Help Needed with C Code for Robotics Project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help Needed with C Code for Robotics Project

2,595 Views
thisisbrians
Contributor I
I am working on the code for a robotics project I am doing for a scholarship competition in ANSI C using CodeWarrior version 5.7.0. Here's the address to my project's website if you are interested: http://www.geocities.com/thisisbrians/.

I have started a navigation system, but part of it I need some help with. I will have the robot navigate a series of "waypoints," which are simply (x,y) coordinate points on the robot's plane of travel.

I need a way to store these ordered pairs in memory without using a separate variable for each one, because I may need to store as many as 20 or perhaps even more waypoints at a time. Is there some way to make a group where I can store all these waypoints and recall them sequentially?

Thanks,
Brian S.
Labels (1)
0 Kudos
2 Replies

228 Views
rocco
Senior Contributor II
Hi, Brian:

This is very straightforward in C.

Declare a structure, which contains x, y and whatever other information is pertinent to each way-point. x and y would probably be integers.

Then define an array of those structures. You can then address each way-point with an index.

(be sure to note the difference between 'declare' and 'define').
0 Kudos

228 Views
admin
Specialist II
The array of structures that rocco suggested is probably best, but you could also declare a two-dimentional array like this:
 
char  coord[ 2 ][ 20 ]
 
where you have 20 sets of 2 char, with one being the x coordinate, and the other being the y coordinate.
 
-Tomahawk
0 Kudos