View unanswered posts | View active topics It is currently Sun Apr 20, 2014 1:52 am






Reply to topic  [ 4 posts ] 
problem with the #pragmas for motor controlling 
Author Message
Rookie

Joined: Thu Feb 26, 2009 1:03 am
Posts: 4
Post problem with the #pragmas for motor controlling
We would like to place our motor definitions in a separate include file that is then included by all three programs (reset,teleop,and autonomous) so that we don't have to continually change all of them. However, if the #pragma definitions are not in the main file or right at the top of that main file, the code will not compile, crashing where we try to use the motors/servos. This only seems to apply to the servo controllers and motor controllers; the regular sensors are fine. Is there a quick fix to this?

one that does not work (#pragmas under a random function...same when they are in a different file)
Code:
int AFunctionThatDoesNothing(int a)
//simply to move the #pragmas not first...
{
  return a+5;
}

#pragma config(Hubs,  S1, HTMotor,  HTServo,  HTMotor,  none)
#pragma config(Sensor, S2,     touchSensor,         sensorTouch)
#pragma config(Motor,  motorA,          left,          tmotorNormal, PIDControl)
#pragma config(Motor,  motorB,          right,         tmotorNormal, PIDControl)
#pragma config(Motor,  motorC,          arm,           tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C3_1,     motorF,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C3_2,     motorG,        tmotorNormal, PIDControl)

task main()
{
  motor[left] = 100;
  motor[right] = 100;
  motor[arm] = 100;
  motor[motorD] = 100;
  motor[motorE] = 100;
  motor[motorF] = 100;
  motor[motorG] = 100;
  int sensor = SensorValue(sensorTouch);
  servoTarget[servo1] = 0;
  int b = AFunctionThatDoesNothing(sensor);
  b = b+4;
}


the same thing that works:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  HTMotor,  none)
#pragma config(Sensor, S2,     touchSensor,         sensorTouch)
#pragma config(Motor,  motorA,          left,          tmotorNormal, PIDControl)
#pragma config(Motor,  motorB,          right,         tmotorNormal, PIDControl)
#pragma config(Motor,  motorC,          arm,           tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C3_1,     motorF,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C3_2,     motorG,        tmotorNormal, PIDControl)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int AFunctionThatDoesNothing(int a)
{
  return a+5;
}

task main()
{
  motor[left] = 100;
  motor[right] = 100;
  motor[arm] = 100;
  motor[motorD] = 100;
  motor[motorE] = 100;
  motor[motorF] = 100;
  motor[motorG] = 100;
  int sensor = SensorValue(sensorTouch);
  servoTarget[servo1] = 0;
  int b = AFunctionThatDoesNothing(sensor);
  b = b+4;
}


Thu Feb 26, 2009 11:07 pm
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: problem with the #pragmas for motor controlling
The simplest fix for this would be to put all of your component definitions (the #pragma statements) into their own file, say "motor defs.h". Then make that the first included file in your program.

Ex.
Code:
//motor defs.h
#pragma config(Hubs,  S1, HTMotor,  HTServo,  HTMotor,  none)
#pragma config(Sensor, S2,     touchSensor,         sensorTouch)
#pragma config(Motor,  motorA,          left,          tmotorNormal, PIDControl)
#pragma config(Motor,  motorB,          right,         tmotorNormal, PIDControl)
#pragma config(Motor,  motorC,          arm,           tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C3_1,     motorF,        tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C3_2,     motorG,        tmotorNormal, PIDControl)

Code:
//functions.c
int AFunctionThatDoesNothing(int a)
{
    return a+5;
}

Code:
//main.c
#include "motor defs.h"
#include "functions.c"

task main()
{
    motor[left] = 100;
    motor[right] = 100;
    motor[arm] = 100;
    motor[motorD] = 100;
    motor[motorE] = 100;
    motor[motorF] = 100;
    motor[motorG] = 100;
    int sensor = SensorValue(sensorTouch);
    servoTarget[servo1] = 0;
    int b = AFunctionThatDoesNothing(sensor);
    b = b+4;
}


Note that to include files you must direct RobotC to your code directory. To do this first make sure you have the menu level set to expert; do this by selecting Window->Menu Level->Expert. Next open the Preferences dialog by going to View->Preferences. Select the Directories tab and in the Directory for Source Files box put the full path of the folder where you are keeping your source code, you can also use the Browse button to do this. For more on the use of includes see my post here, http://robotc.net/forums/viewtopic.php?p=5102#p5102.

In short, you can place your motor, servo, and sensor definitions in another file as long as they end up being the first thing included in the main program file and don't get included more than once, RobotC has issues with having the same file included multiple times, even in other files.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Sat Feb 28, 2009 5:35 pm
Profile
Rookie

Joined: Fri Jan 13, 2012 7:31 pm
Posts: 1
Post Re: problem with the #pragmas for motor controlling
Can anyone confirm this solution actually works? I spent about an hour trying and found the #pragmas had to be in the same file (can't be included) [code][/code]


Fri Jan 13, 2012 7:34 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: problem with the #pragmas for motor controlling
Sorry to dig up this old post, but...
I can confirm that including a header .h file which only has the #pragma config(...) statements in them does not work: errors are returned whenever a function is used regarding motors/servos. If no motors/servos are involved, the code will compile just fine.
Anyone else?

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sat May 18, 2013 1:28 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:  
cron



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