Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Exclamation Need urgent help coding a robot to follow a line in eclipse please help :(

    Hi guys, i have a serious issue with getting this robot to follow a line, please someone help?

  2. #2
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Need urgent help coding a robot to follow a line in eclipse please help :(

    Hi guys, im having serious issues trying to get this robot to follow a line. Please please help me?

  3. #3
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Need urgent help coding a robot to follow a line in eclipse please help :(

    Pleaseeeeeee help me

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Showing us a bit of detail would be nice; a cry of despair is not for this forum, nor is 'pleaseeeeee' (kudos for not writing it with a 'z') or that childish smiley.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Three requests in 9 minutes. That's ridiculous. If you don't get an answer within a couple of days, then ask again.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Hi how can I show you the code, I am new here, it is a whole file containing different images and stuff

  7. #7
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Sometimes I wonder if people like this lack theory of mind... or if they possess a theory of mind in which other people are omniscient.
    Get in the habit of using standard Java naming conventions!

  8. #8
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    okay I have a file containing one package with various classes and images
    Attached Files Attached Files

  9. #9
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    No zip files or personal URL's please. Write up a small Short, Self Contained, Correct Example that demonstrates the problem. No more than 100 lines should probably do it. And make certain it is self contained (i.e. does not require reading in special files or images).

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  10. #10
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    how do I post the code

  11. #11
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Paste it in the message. And do it between code tags [code][/code] so it will format it for you. If you look at other threads in the forum you will see what I am talking about.

    Regards,
    Jim
    Last edited by jim829; 03-11-2014 at 08:25 PM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  12. #12
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    The instructions are prominently linked from the front page of this site: Java Programming Forum - Learn Java Programming - New Syntax Highlighter
    Get in the habit of using standard Java naming conventions!

  13. #13
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Java Code:
    package uk.ac.wlv.cs4011.robot;
    
    /**
     * This class represents the robot. It is an abstract class, so you should
     * override it and implement the {@link move} and {@link findTrack} methods. In
     * your own code you can use the methods {@link forward}, {@link back},
     * {@link left} and {@link right} can be used to move and rotate the robot
     * around its world.
     * 
     * @author Sarah Mount, James Shuttleworth
     * @version $Revision: 1.9 $
     * 
     * @see GUI
     * @see RobotWorld
     * @see Sensor
     */
    public abstract class LineFollowRobot {
    
    	/** The number of steps the robot has moved. */
    	private int stepsTaken = 0;
    
    	/** The number of steps the robot has moved whilst ON the world. */
    	private int stepsTakenOnLine = 0;
    
    	/** Determines how wide the starting circle is. */
    	public static final int ACCURACY = 60;
    
    	/** The position inside the world that the robot starts from. */
    	private FacingVector start;
    
    	/** The robot's current position. */
    	private FacingVector current;
    
    	/** Sensor */
    	protected Sensor top, left, right;
    
    	/** The world that the robot moves around. */
    	private RobotWorld world;
    
    	/** Has the robot found the track? */
    	private boolean foundTrack = false;
    
    	/** Has the robot left the starting circle? */
    	private boolean leftStart = false;
    
    	/** Number of milliseconds between each step the robot takes. */
    	public static final int DELAY = 15;
    
    	public LineFollowRobot() {
    		this(new FacingVector(0.0, 0.0));
    		return;
    	}
    
    	/** Constructs and initialises a robot at a given point on the world. */
    	public LineFollowRobot(FacingVector start) {
    		super();
    		this.top = new Sensor();
    		this.left = new Sensor();
    		this.right = new Sensor();
    		this.setStartPosition(start);
    		return;
    	}
    
    	/**
    	 * Move backward a given number of steps.
    	 * 
    	 * Note that we don't fire the timer here because it will be fired by the
    	 * {@link forward} method.
    	 * 
    	 * @param steps
    	 *            How far to move (in pixels (roughly))
    	 * @return true if we were able to move
    	 */
    	protected boolean back(double steps) {
    		return this.forward(0 - steps);
    	}
    
    	/** Determines whether the robot is still inside the world window. */
    	private boolean checkBounds() {
    		boolean ok = true;
    
    		if (this.current.getX() < 0) {
    			ok = false;
    			this.current.setX(0.0);
    		}
    
    		if (this.current.getX() + RobotWorld.ROBOT_WIDTH > RobotWorld.TRACK_WIDTH) {
    			ok = false;
    			this.current.setX(RobotWorld.TRACK_WIDTH - RobotWorld.ROBOT_WIDTH);
    		}
    
    		if (this.current.getY() < 0) {
    			ok = false;
    			this.current.setY(0.0);
    		}
    
    		if (this.current.getY() + RobotWorld.ROBOT_HEIGHT > RobotWorld.TRACK_HEIGHT) {
    			ok = false;
    			this.current
    					.setY(RobotWorld.TRACK_HEIGHT - RobotWorld.ROBOT_HEIGHT);
    		}
    
    		return ok;
    	}
    
    	/**
    	 * Find the world. Override this to find the world
    	 */
    	protected abstract void findTrack();
    
    	/**
    	 * Move forward a given number of steps.
    	 * 
    	 * @param steps
    	 *            How far to move (in pixels (roughly))
    	 * @return true if we were able to move
    	 */
    	protected boolean forward(double steps) {
    		double d = steps;
    		double nx = Math.sin(Math.toRadians(this.current.getAngle())) * d;
    		double ny = Math.cos(Math.toRadians(this.current.getAngle())) * d;
    
    		if (this.current.getAngle() >= 90 && this.current.getAngle() < 180) {
    			ny = -ny;
    		}
    		if (this.current.getAngle() < 90) {
    			ny = -ny;
    		}
    		if (this.current.getAngle() >= 180 && this.current.getAngle() < 270) {
    			ny = -ny;
    		}
    		if (this.current.getAngle() >= 270) {
    			ny = -ny;
    		}
    
    		this.current.translate(nx, ny);
    		this.step();
    		this.updateRobotState();
    		return this.checkBounds();
    	}
    
    	/** Return the robot's current position on the world. */
    	public FacingVector getPosition() {
    		return (FacingVector) this.current.clone();
    	}
    
    	/** Return a profile of the success and accuracy of the robot . */
    	public String getProfile() {
    		float efficiency = (float) this.stepsTakenOnLine / this.stepsTaken
    				* 100;
    		String profile;
    		if (this.isSuccess()) {
    			profile = "Your robot has completed a successful circuit "
    					+ "of the world.\n";
    		} else {
    			profile = "Your robot has not completed a successful circuit "
    					+ "of the world.\n";
    		}
    		profile = profile + "Your robot has made " + this.stepsTaken
    				+ " steps, of which " + this.stepsTakenOnLine
    				+ " were on the line.\n" + "Your robot is " + efficiency
    				+ " % efficient.";
    		return profile;
    	}
    
    	/** Return the position the robot started from. */
    	public PositionVector getStart() {
    		return (PositionVector) this.start.clone();
    	}
    
    	/** Determines whether the robot has found the world. */
    	public boolean hasFoundTrack() {
    		return this.foundTrack;
    	}
    
    	/** Determines whether or not the robot has left the starting circle. */
    	public boolean hasLeftStart() {
    		return this.leftStart;
    	}
    
    	/**
    	 * Determine whether the robot started and ended in roughly the same place.
    	 */
    	public boolean isSuccess() {
    		if (this.leftStart)
    			return this.current.fuzzyCompare(this.start,
    					LineFollowRobot.ACCURACY);
    		else
    			return false;
    	}
    
    	/** Rotate left, a given number of degrees. */
    	protected void left(double degrees) {
    		this.current.rotate(0 - degrees);
    		this.updateRobotState();
    		return;
    	}
    
    	/**
    	 * Follow the world. This is what you need to override to move around
    	 */
    	protected abstract void move();
    
    	/** Rotate right, a given number of degrees. */
    	protected void right(double degrees) {
    		this.current.rotate(degrees);
    		this.updateRobotState();
    		return;
    	}
    
    	/** Set the starting position of the robot. */
    	public void setStartPosition(FacingVector start) {
    		this.current = start;
    		return;
    	}
    
    	/** Set the world. */
    	public void setTrack(RobotWorld t) {
    		this.world = t;
    		return;
    	}
    
    	/** Updates the world status. */
    	private void statusUpdate() {
    		this.world.update();
    		return;
    	}
    
    	/**
    	 * Increments <code>no_steps</code> and (if needed)
    	 * <code>no_good_steps</code>.
    	 * 
    	 * @see #stepsTaken
    	 * @see #stepsTakenOnLine
    	 */
    	private void step() {
    		if (this.top.isPixelBlack() || this.left.isPixelBlack()
    				|| this.right.isPixelBlack()) {
    			this.stepsTakenOnLine++;
    		}
    		this.stepsTaken++;
    		return;
    	}
    
    	/**
    	 * Update the state of the robot after a short delay. This method is called
    	 * every time the robot takes a step. It is used to insert a delay between
    	 * moves and checks to see if we've found the start yet. The delay here
    	 * gives the user interface time to update and makes the animation smoother.
    	 */
    	private void updateRobotState() {
    		LineFollowRobot.this.statusUpdate();
    		if (LineFollowRobot.this.foundTrack && !this.leftStart) {
    			if (!this.current
    					.fuzzyCompare(this.start, LineFollowRobot.ACCURACY)) {
    				this.leftStart = true;
    			}
    		} else if (!this.foundTrack)
    			if (this.top.isPixelBlack() || this.left.isPixelBlack()
    					|| this.right.isPixelBlack()) {
    				this.foundTrack = true;
    				this.start = (FacingVector) this.current.clone();
    			}
    		try {
    			Thread.sleep(LineFollowRobot.DELAY);
    		} catch (InterruptedException e) {
    			// If we can't sleep just carry on.
    		}
    		return;
    	}
    }

  14. #14
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    My robot extends LINE FOLLOW ROBOT

  15. #15
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Java Code:
    package uk.ac.wlv.cs4011.robot;
    
    public class MyRobot extends LineFollowRobot {
    
    	public MyRobot() {
    		super();
    	}
    
    	public MyRobot(FacingVector start) {
    		super(start);
    		return;
    	}
    
    	
    	protected void findTrack() {
    		if (true){
    			
    		}
    
    	}
    
    	
    	protected void move() {
    		while (true) {
    			this.forward(1);
    			this.left(1);
    			this.right(1);
    			this.left(1);
    			
    	
    
    	}
    
    }
    }

  16. #16
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    So... what is your question?
    Get in the habit of using standard Java naming conventions!

  17. #17
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    This appears to be more of a how to use the abstract class than how to do something in Java. Did the abstract class come with any documentation giving examples of how to override and use findTrack()?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  18. #18
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    "Fill in the findTrack() method

    Inside your MyRobot class, you have already created a method with the following signature:

    public void findTrack()

    findTrack() should move the robot around the track until it finds the track -- then it should stop. There are many different of ways of doing this and some are more efficient than others. You might want to start off with the simplest method you can think of (that works!) and worry about efficiency when you come to the optimisation part of the coursework.

    Notice that there is a blank track for testing the findTrack() method. The idea is that you load the blank track and see how the robot covers the area. The best robots will cover the whole of the robot world in a systematic manner.

    Remember to write Javadoc comments explaining what your findTrack() method does and how it does it. If you've created helper methods, comment them too. "

  19. #19
    itsjava is offline Member
    Join Date
    Mar 2014
    Posts
    11
    Rep Power
    0

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Does this help?

  20. #20
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,379
    Rep Power
    5

    Default Re: Need urgent help coding a robot to follow a line in eclipse please help :(

    Quote Originally Posted by itsjava View Post
    Does this help?
    Unfortunately, not much. Clearly LineFollowRobot is one of many classes that support writing methods to navigate a Robot (similar to Karel). This means there are probably canned methods you are to use to help you stay on and move around the track. So this is more related to knowing the application than knowing Java. I would think there would be examples in the documentation of what methods are available to do this. Assuming this is for a class I would suggest that you either discuss this with your classmates or talk to your instructor. They would be able to help you better than I. Of course, there may be others on this forum who are familiar with this and could help.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 13
    Last Post: 01-14-2013, 08:15 AM
  2. Replies: 1
    Last Post: 12-07-2011, 07:39 PM
  3. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  4. Replies: 3
    Last Post: 07-19-2011, 08:41 PM
  5. Replies: 2
    Last Post: 03-17-2009, 04:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •