Hello. I am on a Rookie team and I am a Rookie programmer. I have no idea how to program the buttons on the joystick. I just need help programming the buttons for our robot’s shooter motor and intake motor. Any help would be appreciated.
Thank you!
/**
* 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
{
Victor (victora);
Victor (victorb);
Victor (victorc);
Victor (victord);
RobotDrive myRobot; // robot drive system
Joystick rightstick;
public:
RobotDemo(void):
victora (1),
victorb (2),
victorc (3),
victord (4),
myRobot(victora,victorb,victorc,victord), // these must be initialized in the same order
rightstick(2) // as they are declared above.
{
myRobot.SetExpiration(0.1);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
myRobot.Drive(0.0, 0.5); // drive forwards half speed
Wait(10.0); // for 2 seconds
myRobot.Drive(0.0, 0.0); // stop robot
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
while (IsOperatorControl())
{
myRobot.ArcadeDrive(rightstick); // drive with arcade style (use right stick)
Wait(0.005); // wait for a motor update time
}
}
};
START_ROBOT_CLASS(RobotDemo);
Can you be a little more detailed about what you want? What exactly do you want the motors to do when you press a button, and when you release the button? Which buttons do you want to use? Be as specific as you can.
I want the motors to run when I press it, and stop when I release it. I also wanted to use number 6 and 7 buttons.
In your operator control loop, you can write something like this:
if ((rightstick->GetRawButton(6) == 1) && (rightstick->GetRawButton(7) == 0)) //if button 6 is pressed and button 7 is released
{
//In this check you will either "set" your victors
victora->Set(.7f);
//Or use a myrobot function
myrobot.drive(//set parameters);
}
else if((rightstick->GetRawButton(7) == 1) && (rightstick->GetRawButton(6) == 0)) //if button 7 is pressed and button 6 is released
{
// "set" your victors
victora->Set(-.7f);
//Or use a myrobot function
myrobot.drive(//set parameters);
}
else // if nothing is pressed set all victors to zero or use a myrobot.drive with 0.0f
{
// turn off everything
victora->Set(0.0f);
//Or use a myrobot function
myrobot.drive(//set parameters to 0.0f);
}
This will make sure your victors are being set to zero if both buttons are pressed or released. Test your robot on blocks before trying to drive!
Thank you!
Would this make it so that button 6 controls one motor, and button 7 controls the other one?
Actually, that would reverse your victors per button (for an intake?) - pressing button 6 would set your victor to +.7, whilie pressing button 7 would set your victor to -.7.
If you want each button to turn on a different victor, write this:
//pressing 6 will turn on intake, releasing 6 will stop intake
if(rightstick->GetRawButton(6) == 1)
{
Intakevictor->Set(.7f);
}
else if(rightstick->GetRawButton(6) == 0)
{
Intakevictor->Set(0.0f);
}
//you can use this code again for your shooter wheel if you change the button to seven and the victor to your shooter wheel victor.
Brandon posted example code that uses victora as a placeholder. You’ll need to define the other two motors you want to control, initialize them appropriately, and set whichever one you want to run in the proper place in the code.
Are you actually using Victor speed controllers? As a rookie team, I’d expect you to have Jaguars. They have different responses to PWM signals, and you won’t get the best results unless the programming matches the hardware.
Yes, we are using victors.
Also, I’m not sure where to paste the code. I understand it should be in the operator control loop, but I’m unsure where exactly.
Paste the code in the “while(IsOperator)” loop. Any code pasted in that while loop will run for the duration of the match.
Like this?
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
while (IsOperatorControl())
{
myRobot.ArcadeDrive(rightstick); // drive with arcade style (use right stick)
Wait(0.005); // wait for a motor update time
//pressing 6 will turn on intake, releasing 6 will stop intake
if(rightstick->GetRawButton(6) == 1)
{
Intakevictor->Set(.7f);
}
else if(rightstick->GetRawButton(6) == 0)
{
Intakevictor->Set(0.0f);
}
}
}
};
START_ROBOT_CLASS(RobotDemo);
Or Like this
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
while (IsOperatorControl())
{
myRobot.ArcadeDrive(rightstick); // drive with arcade style (use right stick)
Wait(0.005); // wait for a motor update time
}
//pressing 6 will turn on intake, releasing 6 will stop intake
if(rightstick->GetRawButton(6) == 1)
{
Intakevictor->Set(.7f);
}
else if(rightstick->GetRawButton(6) == 0)
{
Intakevictor->Set(0.0f);
}
}
};
START_ROBOT_CLASS(RobotDemo);
Your first example is correct. Just check that you are using the correct victors.
- You should move the Wait(0.005); directly below
else if(rightstick->GetRawButton(6) == 0)
{
Intakevictor->Set(0.0f);
}