Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Toggle Speed adjustment Help (http://www.chiefdelphi.com/forums/showthread.php?t=112736)

MI6 04-02-2013 16:40

Toggle Speed adjustment Help
 
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 :
Quote:

#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

Re: Toggle Speed adjustment Help
 
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

Re: Toggle Speed adjustment Help
 
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.


All times are GMT -5. The time now is 12:55.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi