-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleop Driving Basic Code
66 lines (50 loc) · 1.66 KB
/
Teleop Driving Basic Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//include libraries
#include "WPILib.h"
class Robot: public SampleRobot
{
// Channels for the wheels
const static int frontLeftChannel = 2;
const static int rearLeftChannel = 3;
const static int frontRightChannel = 1;
const static int rearRightChannel = 0;
const static int joystickChannel = 0;
int joystickX = 0;
int joystickY = 0;
int joystickZ = 0;
RobotDrive robotDrive; // robot drive system
Joystick stick; // only joystick
public:
Robot() :
robotDrive(frontLeftChannel, rearLeftChannel,
frontRightChannel, rearRightChannel), // these must be initialized in the same order
stick(joystickChannel) // as they are declared above.
{
robotDrive.SetExpiration(0.1);
robotDrive.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true); // invert the left side motors
robotDrive.SetInvertedMotor(RobotDrive::kRearLeftMotor, true); // you may need to change or remove this to match your robot
}
void OperatorControl()
{
robotDrive.SetSafetyEnabled(false);
while (IsOperatorControl() && IsEnabled())
{
// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
// Setting variables/thresholds
jostickX = stick.GetX();
jostickY = stick.GetY();
jostickZ = stick.GetZ();
if joystickX <= 10 || joystickX >= -10{
joystickX=0
}
if joystickY <= 10 || joystickY >= -10{
joystickY=0
}
if joystickZ <= 10 || joystickZ >= -10{
joystickZ=0
}
robotDrive.MecanumDrive_Cartesian(joystickX, joystickY, joystickZ);
Wait(0.005); // wait 5ms to avoid hogging CPU cycles
}
}
};
START_ROBOT_CLASS(Robot);