View unanswered posts | View active topics It is currently Mon Jul 06, 2020 5:48 pm

Reply to topic  [ 2 posts ] 
How to conditionally include #pragma motor/sensor setup? 
Author Message

Joined: Mon Dec 01, 2014 4:27 am
Posts: 5
Post 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?


Tue Dec 02, 2014 7:13 pm

Joined: Tue Nov 03, 2015 10:44 pm
Posts: 1
Post 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.
USE #define
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]

void MoveAndTurn()
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.

Tue Nov 03, 2015 11:01 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.