|How to conditionally include #pragma motor/sensor setup?
|Page 1 of 1|
|Author:||johnslai [ Tue Dec 02, 2014 7:13 pm ]|
|Post subject:||How to conditionally include #pragma motor/sensor setup?|
I am writing a few small programs for a few different robots.
The few programs can work on the multiple robots, except the motor and sensor setup port mapping, forward/reverse motor etc.
I am trying to #include a different config.h which contains the motor/sensor setup for different targets.
However, the compiler complains about #pragma not on the first line of the file.
Is there a way to get around this issue?
|Author:||arthasthrone [ Tue Nov 03, 2015 11:01 pm ]|
|Post subject:||Re: How to conditionally include #pragma motor/sensor setup?|
There are ways to solve this.
First, do make sure that the #include for you config.h is at the top of the file. Because where the #include is, where the compiler will incert all the codes in.
If that doesn't work. another good way to solve this is do it in reverse.
make all your small programs into functions. Then make all those functions into another file, let's call it function.c
For each robot, you set up a file with task main() and the configerations on the top.
then you #include "function.c" right before main(), or anywhere you want to use those functions. All you need to do from then on is to use those functions in the main task to make it running.
If you have a problem with each robot have a much different port map and want to make your life easier on coding.
Look it up if you don't konw what it is. (it's a bit like the naming in the motor set up, but much more useful!)
Basically, you can do
#define turns motor[port2]
#define drives motor[port5]=-motor[port6]
drives = 127;
// some other motions //
turns = 127;
Then, no metter how much motor, or what port did you choose. When you say left, compiler will always understand it as that motor or in a different file, a different motor.
DO make sure the define in before includeing the file of functions, so compiler could know what thing are you talking about.
If you learn more on C, it will be very helpful for coding in general.
|Page 1 of 1||All times are UTC - 5 hours [ DST ]|
|Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group