View unanswered posts | View active topics It is currently Mon Nov 24, 2014 1:58 pm






Reply to topic  [ 4 posts ] 
header files 
Author Message
Rookie

Joined: Wed Feb 12, 2014 5:51 pm
Posts: 2
Post header files
hey community!

i'm trying to include some header files into my main.c
i know it should work but i'm not sure if its correct code.
Whats wrong with my code?

Thanks in advance - rert

main.c
Code:
#include "functions.h"

task main()
{
motorLeftfwd(100,100);
motorRightfwd(100,100);
}


functions.c
Code:
#pragma config(Motor,  motorA,          motorLeft,     tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorB,          motorRight,    tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "functions.h"


void motorLeftfwd(int ispeed, int itime){

motor[motorA] = ispeed;
wait10Msec(itime);

}

void motorRightfwd(int ispeed, int itime){

motor[motorB] = ispeed;
wait10Msec(itime);

}


functions.h
Code:
void motorLeftfwd(int ispeed, int itime){};
void motorRightfwd(int ispeed, int itime){};


Wed Feb 12, 2014 6:01 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: header files
RobotC doesn't work like any other IDEs. For one, you can't have multiple C files. Secondly, pragmas must be declared first thing in the main C file. All other functions should either be in the main C file or other .h header files. So your code should really look like this.
main.c:
Code:
#pragma config(Motor,  motorA,          motorLeft,     tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorB,          motorRight,    tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "functions.h"

task main()
{
    motorLeftfwd(100,100);
    motorRightfwd(100,100);
}

functions.h:
Code:
void motorLeftfwd(int ispeed, int itime)
{
    motor[motorA] = ispeed;
    wait10Msec(itime);
}

void motorRightfwd(int ispeed, int itime)
{
    motor[motorB] = ispeed;
    wait10Msec(itime);
}


Wed Feb 12, 2014 6:49 pm
Profile
Rookie

Joined: Wed Feb 12, 2014 5:51 pm
Posts: 2
Post Re: header files
Thanks that worked great! :D


Fri Feb 14, 2014 5:42 am
Profile
Novice

Joined: Tue Dec 11, 2012 9:19 pm
Posts: 51
Post Re: header files
I've asked for multi file projects that compile into
a single executable, a la most other software IDE's, but Robomatter
has been cool to the idea, preferring to keep it as simple as possible.

As our FTC team matures our software has been getting increasingly
complex. Projects would be a huge win, but more important at this
point is simply the ability to drop the pragmas into a single header
file for reuse across all of our robot executables (of which we have
30+ this year). Combine that with a constantly changing robot
and it's a huge headache (and the standard model only goes part
way to solving the problem).

They've promised #include'd pragmas in 4.0. I can't wait...

Craig


Fri Feb 14, 2014 2:45 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.