View Single Post
  #3   Spotlight this post!  
Unread 20-01-2009, 15:08
HUmar104 HUmar104 is offline
Registered User
FRC #2425
 
Join Date: Jan 2009
Location: Tampa, Florida
Posts: 6
HUmar104 is an unknown quantity at this point
Re: Windriver downloading code problems.

We have just been using the template code, but i'll go ahead and post a copy here:
Quote:
#include "WPILib.h"

/**
* This is a demo program showing the use of the RobotBase class.
* The SimpleRobot class is the base of a robot application that will automatically call your
* Autonomous and OperatorControl methods at the right time as controlled by the switches on
* the driver station or the field controls.
*/
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick; // only joystick

public:
RobotDemo(void):
myRobot(1, 2), // these must be initialized in the same order
stick(1) // as they are declared above.
{
GetWatchdog().SetExpiration(100);
}

/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
GetWatchdog().SetEnabled(false);
myRobot.Drive(0.5, 0.0); // drive forwards half speed
Wait(2.0); // for 2 seconds
myRobot.Drive(0.0, 0.0); // stop robot
}

/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
while (IsOperatorControl())
{
GetWatchdog().Feed();
myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
}
}
};

START_ROBOT_CLASS(RobotDemo);
However, we have also tried and in-progress version of our modified code:

Quote:
#include "WPILib.h"
#include "AxisCamera.h"

#define JAGUAR_PORT_LEFT 9
#define JAGUAR_PORT_RIGHT 10
#define JOYSTICK_PORT_LEFT 1
#define JOYSTICK_PORT_RIGHT 2
#define ACCEL_PORT_LEFT 3
#define ACCEL_PORT_RIGHT 4
#define COMPRESSOR_PORT 5
#define RELAY_PORT 6
#define SOLENOID_PORT_UP 7
#define SOLENOID_PORT_DOWN 8
#define TRACTION_CONTROL .5
#define VICTOR_PORT_LEFT 9
#define VICTOR_PORT_RIGHT 10


class RobotDemo : public SimpleRobot
{
RobotDrive *myRobot; // robot drive system pointer
Joystick *stickLeft; // Joystick 1 (Left Stick) pointer
Joystick *stickRight; // Joystick 2 (Right Stick) pointer
DriverStation *ds; // create a driver station pointer;
Accelerometer *accLeft; //create the left accelerometer pointer
Accelerometer *accRight; //create the right accelerometer pointer
Compressor *comp; // Create the compressor pointer
Relay *compSpike; //create the pointer for the compressor spike
Solenoid *noidUp; //create the first solenoid
Solenoid *noidDown; //create the second solenoid
Jaguar *motorControllerLeft; //create the motor controllers
Jaguar *motorControllerRight;
Victor *intakeRollerLeft; //intake motors
Victor *intakeRollerRight;

float CurrentAccLeft; //thar be some temp vars
float CurrentAccRight;
int tractionControl;
int holdButton;

void TankDriveFunction(float accL,float accr);
void UpdateAccel(float &accL,float &accR);
void BasketInput(Joystick *Lstick, Joystick *Rstick);
void TractionControl(Joystick *Lstick);
void IntakeControl();

public:
RobotDemo(void) //Constructor Function
{
//**!!**Important**!!** All of the numbers being used in the functions are completely arbitrary
// Change them eventually!

ds = DriverStation::GetInstance(); // attach the pointer to the driverstation
myRobot = new RobotDrive(1, 2); // create robot drive base
stickLeft = new Joystick(JOYSTICK_PORT_LEFT); // create the joysticks
stickRight = new Joystick(JOYSTICK_PORT_RIGHT);
GetWatchdog().SetExpiration(100); //Need to feed the watchdog ever 100 milliseconds
accLeft = new Accelerometer(ACCEL_PORT_LEFT); //attach the left and right accelerometers
accRight = new Accelerometer(ACCEL_PORT_RIGHT);
comp = new Compressor(COMPRESSOR_PORT, RELAY_PORT); //attach the compressor pointer to the compressor
compSpike = new Relay (RELAY_PORT); //attach the compressor spike pointer
noidUp = new Solenoid(SOLENOID_PORT_UP); //attach the solenoid pointers
noidDown = new Solenoid(SOLENOID_PORT_DOWN);
motorControllerLeft = new Jaguar(JAGUAR_PORT_LEFT); //attach motor controllers
motorControllerRight = new Jaguar(JAGUAR_PORT_RIGHT);
intakeRollerLeft = new Victor(VICTOR_PORT_LEFT);
intakeRollerRight = new Victor(VICTOR_PORT_RIGHT);
holdButton = 0;
}


void Autonomous(void) //Autonomous Function
{
//We'll wait and do autonomous when we have a robot.
}


void OperatorControl(void) //Tele-Op Function
{
while (IsOperatorControl()) //While in Tele-Op mode, run.
{
GetWatchdog().Feed(); //Feed that $@#$@#$@#$@# watchdog.

TractionControl(stickLeft); //toggle traction control
UpdateAccel(CurrentAccLeft, CurrentAccRight); //Update the accelerometers
TankDriveFunction(CurrentAccLeft, CurrentAccRight); //go go Go Go GO GOOOOOO!
BasketInput(stickLeft, stickRight); //move the basket
IntakeControl();

}
}
};
void RobotDemo::TankDriveFunction(float accL,float accR)
{
if (tractionControl)
{
if (accL > .06 || accR > .06) //If the acceleration isn't too great...
{
motorControllerRight->Set(TRACTION_CONTROL);
motorControllerLeft->Set(TRACTION_CONTROL);
return;
}
}
else
{
motorControllerLeft->Set(stickRight->GetThrottle());
motorControllerRight->Set(stickLeft->GetThrottle());
}
}

void RobotDemo::UpdateAccel(float &accL,float &accR)
{
accL = accLeft->GetAcceleration(); //check the current acceleration of the left side
accR = accRight->GetAcceleration(); //check the right side
}

void RobotDemo::BasketInput(Joystick *Lstick, Joystick *Rstick)
{
if (Lstick->GetRawButton(2)) //The basket goes down
{
noidUp->Set(false);
noidDown->Set(true);
}
else if (Rstick->GetRawButton(3)) //The basket goes up
{
noidDown->Set(false);
noidUp->Set(true);
}
}

void RobotDemo::TractionControl(Joystick *Lstick)
{
if (Lstick->GetRawButton(4)) tractionControl = 0;
else if (Lstick->GetRawButton(5)) tractionControl = 1;
}

void RobotDemo::IntakeControl()
{

if (stickLeft->GetRawButton(7))
{
intakeRollerLeft->Set(-1.0);
intakeRollerRight->Set(-1.0);
}
else
{
if(stickLeft->GetRawButton(6))
{
if(holdButton!=1)
{
if (intakeRollerLeft->Get())
{
intakeRollerLeft->Set(0);
intakeRollerRight->Set(0);
holdButton = 1;
}
else
{
intakeRollerLeft->Set(1.0);
intakeRollerRight->Set(1.0);
holdButton = 1;
}
}
}
else
{
intakeRollerLeft->Set(0);
intakeRollerRight->Set(0);
holdButton = 0;
}
}
}

START_ROBOT_CLASS(RobotDemo);
any and all help/comments are appreciated!

Hydra Robotics
Team #2425
Reply With Quote