-
Notifications
You must be signed in to change notification settings - Fork 8
/
DrivingChassis.h
122 lines (117 loc) · 3.97 KB
/
DrivingChassis.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* DrivingChassis.h
*
* Created on: Jan 12, 2019
* Author: hephaestus
*/
#ifndef DRIVINGCHASSIS_H_
#define DRIVINGCHASSIS_H_
#include "src/pid/PIDMotor.h"
#include "src/commands/GetIMU.h"
#include "config.h"
/**
* DrivingChassis encapsulates a 2 wheel differential steered chassis that drives around
*
* The 0,0,0 center of the robot is on the ground, half way between the left and right wheel contact points.
*
* The +X axis is the positive direction of travel
*
* The +Y axis goes from the center of the robot to the left wheel
*
* The +Z axis goes from the center up through the robot towards the ceiling.
*
* This object should manage the setting of motor setpoints to enable driving
*/
class DrivingChassis {
private:
PIDMotor * myleft;
PIDMotor * myright;
GetIMU * IMU;
float mywheelTrackMM;
float mywheelRadiusMM;
/**
* Compute a delta in wheel angle to traverse a specific distance
*
* arc length = 2* Pi* R* (C/360)
*
* C is the central angle of the arc in degrees
* R is the radius of the arc
* Pi is Pi
*
* @param distance a distance for this wheel to travel in MM
* @return the wheel angle delta in degrees
*/
float distanceToWheelAngle(float distance);
/**
* Compute the arch length distance the wheel needs to travel through to rotate the base
* through a given number of degrees.
*
* arc length = 2* Pi* R* (C/360)
*
* C is the central angle of the arc in degrees
* R is the radius of the arc
* Pi is Pi
*
* @param angle is the angle the base should be rotated by
* @return is the linear distance the wheel needs to travel given the this CHassis's wheel track
*/
float chassisRotationToWheelDistance(float angle);
public:
virtual ~DrivingChassis();
/**
* DrivingChassis encapsulates a 2 wheel differential steered chassis that drives around
*
* @param left the left motor
* @param right the right motor
* @param wheelTrackMM is the measurment in milimeters of the distance from the left wheel contact point to the right wheels contact point
* @param wheelRadiusMM is the measurment in milimeters of the radius of the wheels
* @param imu The object that is used to access the IMU data
*/
DrivingChassis(PIDMotor * left, PIDMotor * right, float wheelTrackMM,
float wheelRadiusMM,GetIMU * imu);
/**
* Start a drive forward action
*
* @param mmDistanceFromCurrent is the distance the mobile base should drive forward
* @param msDuration is the time in miliseconds that the drive action should take
*
* @note this function is fast-return and should not block
* @note pidmotorInstance->overrideCurrentPosition(0); can be used to "zero out" the motor to
* allow for relative moves. Otherwise the motor is always in ABSOLUTE mode
*/
void driveForward(float mmDistanceFromCurrent, int msDuration);
/**
* Start a turn action
*
* This action rotates the robot around the center line made up by the contact points of the left and right wheels.
* Positive angles should rotate to the left
*
* This rotation is a positive rotation about the Z axis of the robot.
*
* @param degreesToRotateBase the number of degrees to rotate
* @param msDuration is the time in miliseconds that the drive action should take
*
* @note this function is fast-return and should not block
* @note pidmotorInstance->overrideCurrentPosition(0); can be used to "zero out" the motor to
* allow for relative moves. Otherwise the motor is always in ABSOLUTE mode
*/
void turnDegrees(float degreesToRotateBase, int msDuration);
/**
* Check to see if the chassis is performing an action
*
* @return false is the chassis is driving, true is the chassis msDuration has elapsed
*
* @note this function is fast-return and should not block
*/
bool isChassisDoneDriving();
/**
* loop()
*
* a fast loop function that will update states of the motors based on the information from the
* imu.
*
* @note this function is fast-return and should not block
*/
bool loop();
};
#endif /* DRIVINGCHASSIS_H_ */