To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.javaOpen lugnet.robotics.rcx.java in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / Java / 21
20  |  22
Subject: 
Keeping track of coordinates with Lejos
Newsgroups: 
lugnet.robotics.rcx.java
Date: 
Sun, 22 Oct 2000 15:07:15 GMT
Viewed: 
2568 times
  
Here's my experiences with keeping track of X, Y coordinates using Lejos.
Hopefully this will help some people, and other people might be able to help me
improve these techniques or give me advanced navigation ideas.

First, if you haven't got Lejos, I'd strongly recommend going to
http://lejos.sourceforge.net.  It is one of the best development tools out
there for the RCX and if you're a Java programmer already you will fall in
love.

In order to keep track of coordinates it is necessary to use trigonometry.
Remember soh, cah, toa from high-school?  sin(angle) = opposite/hypotenuse,
etc...

Your program will have to keep track of three things about your robot: The
angle the robot is pointing, and the distance it has travelled for a particular
line.  It will also have to keep a running tally of the X and Y values.

Let's say the robot starts off pointing at 90 degrees, which is north on a
coordinate system.  Remember from high-school, the X axis is always
"east-west", and the Y axis is "north-south".  Starting from "east" and moving
counter clockwise we have east is always 0 degrees, north is 90 degrees, west
is 180 degrees, south is 270 degrees.

The robots starting coordinates are:  x=0, y=0.  Now it rotates 30 degrees to
the east, so we must subtract.  90 - 30 = 60 degree orientation.  Now it drives
forwards 100 (centimeters, inches, or whatever units you want to use).  It
stops.  How do we calculate the new x, y coordinates with Java?

// update x, y coordinates
x = x + (Math.cos(Math.toRadians(angle)) * distance);
y = y + (Math.sin(Math.toRadians(angle)) * distance);

So at the start of this equation, x=0, y=0, angle = 60, distance=100.
After we are done, x = 50 and y = 86.6.

It is that simple!  Now you can reapply this equation after every straight line
your robot travels.

If your angle dips below 0 (eg. -36 degrees) or goes above 360 (eg. 456
degrees) the trig functions will still process it properly, so you won't really
have to worry about making sure the angle stays between 0 and 359.999..)

Hope this helps some people out.



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR