forked from trcbots/linda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleop_controller.h
74 lines (59 loc) · 1.99 KB
/
teleop_controller.h
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
/******************* CONFIG **********************/
#define TELEOP_MAX_LIN_VEL 0.5 // metres/s
#define TELEOP_MAX_ANG_VEL 1.0 // rad/s
#define ROBOT_MAX_DECEL_RATE 1.0 // m/s^2
/*************************************************/
#define REGULAR_TELEOP_MODE 0
#define SEPF_ASSISTED_TELEOP_MODE 1
struct Velocity
{
double linear;
double angular;
};
class TeleopController
{
public:
TeleopController();
void change_state(uint8_t state_id);
void set_input_sensitivity(double lin_sensitivity, double ang_sensitivity);
Velocity process_command(double lin_vel, double ang_vel);
private:
uint8_t _state_id;
double _lin_vel_scaling_factor;
double _ang_vel_scaling_factor;
};
TeleopController::TeleopController()
{
}
void TeleopController::set_input_sensitivity(double lin_sensitivity, double ang_sensitivity)
{
/**
* @brief different input devices (e.g. bluetooth joystick) may have different sensitivities
* lets make the sensitivity adaptable for each TeleopController
*
* Note: the sensitivity values MUST convert joystick values to velocites in metres per second!
*/
_lin_vel_scaling_factor = lin_sensitivity;
_ang_vel_scaling_factor = ang_sensitivity;
}
void TeleopController::change_state(uint8_t state_id)
{
Serial.print("Changing serial state to: ");
Serial.println(state_id);
_state_id = state_id;
}
Velocity TeleopController::process_command(double lin_vel, double ang_vel)
{
Velocity outvel;
if (_state_id == REGULAR_TELEOP_MODE)
{
// Apply scaling and constraints
outvel.linear = constrain(_lin_vel_scaling_factor * lin_vel, -TELEOP_MAX_LIN_VEL, TELEOP_MAX_LIN_VEL);
outvel.angular = constrain(_ang_vel_scaling_factor * ang_vel, -TELEOP_MAX_ANG_VEL, TELEOP_MAX_ANG_VEL);
}
else if (_state_id == SEPF_ASSISTED_TELEOP_MODE)
{
Serial.println("SEPF Assisted Teleop Not Yet Implemented! Ignoring Command...");
}
return outvel;
}