We are testing code for our motors/servos. Apparently after downloading the code to our cRIO, nothing seems to function. It builds, so we are sure it is not a syntax error.
The code is as follows:
Code:
#include "WPILib.h"
void update_drive;
class RobotDemo : public SimpleRobot
{
RobotDemo(void)
{ // put initialization code here
pwm leftmotor(1);
pwm rightmotor(2);
joystick leftjoy(1);
joystick rightjoy(2);
}
void Autonomous(void)
{ // put autonomous code here
}
void OperatorControl(void)
{ // put operator control code here
update_drive();
}
};
start_robot_class(RobotDemo);
void update_drive()
{
int k = /*your value here*/; //speed increase/decrease value
if (leftjoy:gety() >= (255 - k)) //if left joystick is near max
{ //overshot security
leftmotor:rawset(leftjoy:gety());
}
if (leftjoy:gety() <= k) //if left joystick is near min
{ //undershot security
leftmotor:rawset(leftjoy:gety());
}
if ((leftjoy:gety() < (255 - k)) && (leftjoy:gety() > k)) //otherwise...
{ //standard control
if (leftjoy:gety() > leftmotor:rawget())
{ //speed up
int leftmotortemp1 = leftmotor:rawget();
leftmotor:rawset(leftmotortemp1 + k);
if (leftjoy:gety() < leftmotor:rawget())
{ //overshot security
leftmotor:rawset(leftjoy:gety());
}
}
if (leftjoy:gety() < leftmotor:rawget())
{ //slow down
int leftmotortemp1 = leftmotor:rawget();
leftmotor:rawset(leftmotortemp1 - k);
if (leftjoy:gety() > leftmotor:rawget())
{ //undershot security
leftmotor:rawset(leftjoy:gety());
}
}
}
if (rightjoy:gety() >= (255 - k)) //if right joystick is near max
{ //overshot security
rightmotor:rawset(rightjoy:gety());
}
if (rightjoy:gety() <= k) //if right joystick is near min
{ //undershot security
rightmotor:rawset(rightjoy:gety());
}
if ((rightjoy:gety() < (255 - k)) && (rightjoy:gety() > k)) //otherwise...
{ //standard control
if (rightjoy:gety() > rightmotor:rawget())
{ //speed up
int rightmotortemp1 = rightmotor:rawget();
rightmotor:rawset(rightmotortemp1 + k);
if (rightjoy:gety() < rightmotor:rawget())
{ //overshot security
rightmotor:rawset(rightjoy:gety());
}
}
if (rightjoy:gety() < rightmotor:rawget())
{ //slow down
int rightmotortemp1 = rightmotor:rawget();
rightmotor:rawset(rightmotortemp1 - k);
if (rightjoy:gety() > rightmotor:rawget())
{ //undershot security
rightmotor:rawset(rightjoy:gety());
}
}
}
}
Any suggestions would be greatly appreciated. Our team is really falling behind this year, and nothing seems to be going right.
Thanks,
iPirates 1528