|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
methods for Switchable Autonomous Modes
Hello,
I have looked through much of the forums before Stop Build Date for the best and easiest switchable autonomous mode, but none seemed to work. I use the Simple Robot Template for my code. (my entire cpp file code is posted below) I noticed methods that are solely through the driver station (IO, Position, etc), and using something through that interface is preferred. I was unable to get any to work in the code (and was uncertain about the position selector). My second choice would be a dip switch option on the robot itself. (Just I have never programmed inputs like those on the robot, and I still prefer the DS method). Thanks, Davis Robot Code: Code:
#include "WPILib.h"
#include "Math.h"
#include "stdlib.h"
#include "DriverStation.h"
class RobotDemo : public SimpleRobot
{
RobotDrive R_myRobot;
Joystick J_stick1;
Joystick J_stick2;
Joystick J_stick3;
Joystick J_stick4;
Relay M_standLeft;
Relay M_standCenter;
Relay M_standRight;
Victor M_arm;
Relay M_frisbeePusher;
Relay M_frisbeeReleaser;
public:
RobotDemo(void):
R_myRobot(1, 2),
J_stick1(1),
J_stick2(2),
J_stick3(3),
J_stick4(4),
M_standLeft(1),
M_standCenter(3),
M_standRight(2),
M_arm(3),
M_frisbeePusher(4),
M_frisbeeReleaser(5)
{
R_myRobot.SetExpiration(0.1);
}
void Autonomous(void)
{
R_myRobot.SetSafetyEnabled(false);
}
void OperatorControl(void)
{
R_myRobot.SetSafetyEnabled(true);
// inverts the left motor
R_myRobot.SetInvertedMotor(R_myRobot.kRearLeftMotor, true);
// inverts the right motor
R_myRobot.SetInvertedMotor(R_myRobot.kRearRightMotor, true);
R_myRobot.Drive(0.0, 0.0);
while (IsOperatorControl())
{
// Drive
R_myRobot.TankDrive(J_stick1, J_stick2);
// Arm
if(J_stick4.GetRawButton(1))
M_arm.Set(J_stick4.GetY());
else
if(J_stick4.GetRawButton(2))
M_arm.Set(J_stick4.GetY()*3/4);
else
M_arm.Set(0.0);
// frisbee pusher
if(J_stick1.GetRawButton(1))
M_frisbeePusher.Set(Relay::kForward);
else
if(J_stick1.GetRawButton(2))
M_frisbeePusher.Set(Relay::kReverse);
else
M_frisbeePusher.Set(Relay::kOff);
// frisbee Releaser
if(J_stick2.GetRawButton(1))
M_frisbeePusher.Set(Relay::kForward);
else
if(J_stick2.GetRawButton(2))
M_frisbeePusher.Set(Relay::kReverse);
else
M_frisbeePusher.Set(Relay::kOff);
// stand center
if(J_stick4.GetRawButton(4))
M_standCenter.Set(Relay::kForward);
else
if(J_stick4.GetRawButton(5))
M_standCenter.Set(Relay::kReverse);
else
if(J_stick4.GetRawButton(3))
M_standCenter.Set(Relay::kOff);
// stand left + right
if(J_stick3.GetRawButton(4))
{
M_standLeft.Set(Relay::kForward);
M_standRight.Set(Relay::kForward);
}
else
{
if(J_stick3.GetRawButton(5))
{
M_standLeft.Set(Relay::kReverse);
M_standRight.Set(Relay::kReverse);
}
else
{
if(J_stick3.GetRawButton(3))
{
M_standLeft.Set(Relay::kOff);
M_standRight.Set(Relay::kOff);
}
else
{
// stand left
if(J_stick3.GetRawButton(6))
M_standLeft.Set(Relay::kForward);
else
{
if(J_stick3.GetRawButton(7))
M_standLeft.Set(Relay::kReverse);
else
{
if(J_stick3.GetRawButton(8))
M_standLeft.Set(Relay::kOff);
}
}
// stand right
if(J_stick3.GetRawButton(11))
M_standRight.Set(Relay::kForward);
else
{
if(J_stick3.GetRawButton(10))
M_standRight.Set(Relay::kReverse);
else
{
if(J_stick3.GetRawButton(9))
M_standRight.Set(Relay::kOff);
}
}
}
}
}
Wait(0.005);
}
}
};
START_ROBOT_CLASS(RobotDemo);
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|