Help with Angles and distance

I am programming a GPS bot. I am getting to sets of (x,y) one being my current location and the other being the destination. I need to do trig in easy c to get the robot to know at what angle to travel and for what distance. I know how to do this trig on paper but have NO IDEA on how to program this. My advisor has given me the task, and I have little if any knowledge of advanced easyC. I know that i will need to do an inverse tangent([X2-X1]/[Y2-Y1]) to get my angle of heading, and to get my distance i need sq rt([X2-X1]^2 + [Y2-Y1]^2). So as you can see, I know what I need to do, but have no idea on how to put this in terms of EasyC. I also know that I will need trig lookup tables and have NO IDEA on how to use them.

I would start with pseudo code, literally you can framework out your code either using flow charts or writing IF … THEN. Most white papers that define software requirements do one or the other and coding from there is as easy as knowing any language’s syntax.

For starters in syntax, I don’t believe EasyC will like the “^” character, so multiply those variables out.

***Now for some issues you’ll encounter along the way (note, these are NOT answers to these issues; I’m only making you aware of them)***What will boggle your mind is that unless your GPS unit is precisly on the center of rotation of your robot, when it moves to the spot you tell it to it will be off by a distance. That distance, minus all negligible mathematical components, is roughly the distance between the GPS unit and the center of rotation.

Also, you’ll need to account for the possible sign errors on your arctan (inverse tangent) output. There are several ways to do this, the most intuitive (but most complex) of which is converting the bearing to the first quadrant, doing the calculation, then reversing the quandrant conversion. Do this on paper using the IF…THEN blocks as well. Doing this will also reduce the amount of arctan tables you need to store, fyi :).

Finally, what should happen when Y2 == Y1 ? Do you see the problem that happens in your arctan calculation? When, in the real world for your application, does Y2 == Y1 and how will your code deal with that condition?

Actually, it is the location of the GPS receive antenna that is the critical item. The location of the GPS engine is irrelevant, but the point remains valid.

Instead of trig, how about just using a ratio, for example for every n units in X you need to also move *i *units in Y. If your units are meters, and to get to New(X,Y) you need to move 4,11 meters, break that up into little bites and for every 4 bites in the X direction you should move 11 bites in Y.

Doesn’t satisfy your assignment, but computationally it is much easier.

Another alternative is a look-up table, just calculate the angles & distance for every possibility (say, up to 50 meters) and store them in a table, so when X,Y = n,i, just look up the answer.


XY and y arent in meters feet or inches, but in lattitude and longitude. I have a lookup table, but need to know how to create a code that say okay you have (x,Y) and (m,n) subtract those and then drag a value from the trig lookup table. Its the only way this can be done. I have no idea what blocks to use b.c as i said, i have never ever programmed before.

Conceptually, using GPS on one of these robots isn’t a good idea because GPS is inaccurate to 10 feet which is pretety huge considering the field is only 20 feet wide. So there really is no benefit to even using GPS on a robot unless you have $60k to spend on one that is accurate to a millimeter…let alone going through the major headache going from point a to point b in easyc is.

Yes, I know GPS outputs in Lat/Lon, but somwehere you need to start thinking in units of distance, even if they are hundred-thousandths of a degree.

How to program it? I can’t* give you a direct & complete answer, but here are some things to try.

  1. How do you determine the direction the robot will move? Somehow, you need to have a way of determining which direction the robot is “facing” right now, and which way it needs to face before it starts moving.

  2. How do you determine distance moved? Needs to be fairly accurate, because GPS isn’t. +/- 10 feet on a good day.

  3. Do you need to deal with obstructions? If so, that’s a problem an order of magnitude or two larger. Beyond the scope here.

OK, once you know 1 and 2, you find where you are, then where you want to be.

Then command the robot to turn until you’re facing the right direction. Then move the robot about half the distance and stop. Last, re-check the direction & distance, and repeat until you reach the goal. If the distance is less than some minimum, say 40 feet, just go to the goal.

Do you need help in figuring out how to turn the robot, or make it go a certain distance?