Log in

View Full Version : Toggle Speed adjustment Help


MI6
04-02-2013, 16:40
I'm just tank drive with a Xbox controller, i want to make it so when i press one of the two triggers it will make a limit the speed of the robot.

My code :
#include "WPILib.h"

class DemoRobot : public SimpleRobot
{
RobotDrive drivetrain;
Joystick xbox;
public:
DemoRobot() :
drivetrain(1, 2), xbox(1)
{
GetWatchdog().SetEnabled(false);
}

void Autonomous() {}

void OperatorControl()
{
while (IsOperatorControl()) {
drivetrain.TankDrive(xbox.GetY(), xbox.GetRawAxis(5));
Wait(0.005);
}
}
};

START_ROBOT_CLASS(DemoRobot);

z_beeblebrox
04-02-2013, 17:32
I'm not familiar with C++, but in general, one can simply multiply the joystick values by a constant, if the button is pressed, before feeding it to the drive.

Alan Anderson
04-02-2013, 20:21
Read the raw joystick values into temporary variables. If the button is pressed, multiply the values by something less than one. Feed those variables into the TankDrive function.