Help Needed with C Code for Robotics Project

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Help Needed with C Code for Robotics Project

3,179 次查看
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.
标签 (1)
0 项奖励
回复
2 回复数

812 次查看
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 项奖励
回复

812 次查看
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 项奖励
回复