@@ -34,6 +34,7 @@ void HDrive::setTurnPID(PID pid){
34
34
35
35
void HDrive::setStrafePID (PID pid){
36
36
pidStrafe = pid;
37
+ center->setPID (pidStrafe);
37
38
}
38
39
39
40
void HDrive::spin (int left_velocity, int right_velocity, int center_velocity){
@@ -53,9 +54,14 @@ void HDrive::straight(float distance, int max_speed){
53
54
54
55
void HDrive::straightAsync (float distance, int max_speed){
55
56
distance = Conversion::standardize (distance, this ->measure_units );
56
- float target = ((distance + straight_offset) / wheel_circumference) * 360.0 ;
57
- left->setPID (pidStraight);
58
- right->setPID (pidStraight);
57
+ if (distance > 0 ){
58
+ distance += straight_offset;
59
+ } else {
60
+ distance -= straight_offset;
61
+ }
62
+ float target = ((distance) / wheel_circumference) * 360.0 ;
63
+ left->setPID (pidStraight.copy ());
64
+ right->setPID (pidStraight.copy ());
59
65
this ->spinToTarget (target, target, 0 , max_speed, max_speed, 0 );
60
66
}
61
67
@@ -65,9 +71,14 @@ void HDrive::turn(int target_angle, int max_speed){
65
71
}
66
72
67
73
void HDrive::turnAsync (float target_angle, int max_speed){
68
- float target = ((track_width/2 )*((float )(target_angle+turn_offset)*M_PI/180 )/wheel_circumference)*360 ;
69
- left->setPID (pidTurn);
70
- right->setPID (pidTurn);
74
+ if (target_angle > 0 ){
75
+ target_angle += turn_offset;
76
+ } else {
77
+ target_angle -= turn_offset;
78
+ }
79
+ float target = ((track_width/2 )*((float )(target_angle)*M_PI/180 )/wheel_circumference)*360 ;
80
+ left->setPID (pidTurn.copy ());
81
+ right->setPID (pidTurn.copy ());
71
82
this ->spinToTarget (target, -target, 0 , max_speed, max_speed, 0 );
72
83
}
73
84
@@ -78,7 +89,12 @@ void HDrive::strafe(float distance, int max_speed){
78
89
79
90
void HDrive::strafeAsync (float distance, int max_speed){
80
91
distance = Conversion::standardize (distance, this ->measure_units );
81
- float target = ((distance + strafe_offset) / center_wheel_circumference) * 360.0 ;
92
+ if (distance > 0 ){
93
+ distance += strafe_offset;
94
+ } else {
95
+ distance -= strafe_offset;
96
+ }
97
+ float target = ((distance) / center_wheel_circumference) * 360.0 ;
82
98
this ->spinToTarget (0 , 0 , target, 0 , 0 , max_speed);
83
99
}
84
100
@@ -99,9 +115,9 @@ void HDrive::diagonalAsync(float straight_distance, float strafe_distance, int s
99
115
}
100
116
101
117
void HDrive::spinToTarget (float left_target, float right_target, float center_target, int l_max_spd, int r_max_spd, int c_max_spd){
102
- left->moveRelative (left_target, l_max_spd);
103
- right->moveRelative (right_target, r_max_spd);
104
- center->moveRelative (center_target, c_max_spd);
118
+ left->moveRelativeAsync (left_target, l_max_spd);
119
+ right->moveRelativeAsync (right_target, r_max_spd);
120
+ center->moveRelativeAsync (center_target, c_max_spd);
105
121
}
106
122
107
123
void HDrive::stop (){
@@ -146,8 +162,12 @@ void HDrive::setOffset(float straight, float turn, float center){
146
162
strafe_offset = center;
147
163
}
148
164
149
- void HDrive::setMaxAcceleration (float max_accel){
150
- this ->max_acceleration = max_accel;
165
+ void HDrive::setMaxAcceleration (float straight_max_accel, float c_max_accel){
166
+ if (straight_max_accel < 0 || c_max_accel < 0 )
167
+ LOG (WARN) << " Negative accelerations not allowed" ;
168
+ this ->left ->setMaxAcceleration (straight_max_accel);
169
+ this ->right ->setMaxAcceleration (straight_max_accel);
170
+ this ->center ->setMaxAcceleration (c_max_accel);
151
171
}
152
172
153
173
void HDrive::setTimeout (int timeout){
0 commit comments