forked from FRC1296/RHSRobot2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RhsRobot.cpp
94 lines (80 loc) · 1.92 KB
/
RhsRobot.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "WPILib.h"
//Robot
#include "ComponentBase.h"
#include "RobotParams.h"
//Robot
#include "Drivetrain.h"
#include "RhsRobot.h"
RhsRobot::RhsRobot()
{
Controller_1 = NULL;
Controller_2 = NULL;
drivetrain = NULL;
autonomous = NULL;
}
RhsRobot::~RhsRobot()
{
/*
* Free all allocated memory
* EXAMPLE: delete drivetrain;
*/
delete Controller_1;
delete Controller_2;
delete autonomous;
delete drivetrain;
}
void RhsRobot::Init() //Initializes the robot
{
/*
* Set all pointers to null and then allocate memory and construct objects
* EXAMPLE: drivetrain = NULL;
* drivetrain = new Drivetrain(this);
*/
Controller_1 = new Joystick(1);
Controller_2 = new Joystick(2);
drivetrain = new Drivetrain();
autonomous = new Autonomous();
}
void RhsRobot::OnStateChange() //Handles state changes
{
/*
* Alert all components of state changes by sending robotMessage.
* EXAMPLE: if(drivetrain)
* {
* drivetrain->SendMessage(&robotMessage);
* }
*/
if(drivetrain)
{
drivetrain->SendMessage(&robotMessage);
}
if(autonomous)
{
autonomous->SendMessage(&robotMessage);
}
}
void RhsRobot::Run() //Robot logic
{
/* Poll for control data and send messages to each subsystem. Surround blocks with if(component) so entire components can be disabled
* by commenting out their construction.
* EXAMPLE: if(drivetrain)
* {
* //Check joysticks and send messages
* }
*/
if(autonomous)
{
if(GetCurrentRobotState() == ROBOT_STATE_AUTONOMOUS)
{
// all messages to components will come from the autonomous task
return;
}
}
if(drivetrain)
{
robotMessage.params.tankDrive.left = TANK_DRIVE_LEFT;
robotMessage.params.tankDrive.right = TANK_DRIVE_RIGHT;
drivetrain->SendMessage(&robotMessage);
}
}
START_ROBOT_CLASS(RhsRobot) //Spawns an instance of the RhsRobot class