File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
examples/RoboHeartBalanceBot Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,12 @@ float RoboHeart::getRotationZ(){
227
227
}
228
228
229
229
230
+ void RoboHeart::resetGyro (){
231
+ this ->_rotationX = 0 ;
232
+ this ->_rotationY = 0 ;
233
+ this ->_rotationZ = 0 ;
234
+ }
235
+
230
236
float RoboHeart::getTemperatureC (){
231
237
return (imu.readRawTemp () / 256 .) + 25 ;
232
238
}
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ class RoboHeart {
50
50
float getRotationX ();
51
51
float getRotationY ();
52
52
float getRotationZ ();
53
+ void resetGyro ();
53
54
54
55
RoboHeartStepperMotor stepper;
55
56
RoboHeartDRV8836 motorA;
Original file line number Diff line number Diff line change 21
21
RoboHeart heart = RoboHeart(Serial);
22
22
23
23
// PID controller parameters
24
- #define Kp 20
25
- #define Kd 0.001
26
- #define Ki 40
24
+ #define Kp 6.5
25
+ #define Kd 0
26
+ #define Ki 0
27
27
28
28
#define CONTROL_TICK_PERIOD_US 100.0
29
29
@@ -53,8 +53,8 @@ unsigned long prevTimeIntervalMS = 0;
53
53
// handle -180 after crossing 180 Degrees
54
54
float processAngle (float angle) {
55
55
// handle -180 after crossing 180
56
- if (angle < - 90 ) {
57
- return angle = 360 + angle ;
56
+ if (angle > 180 ) {
57
+ return angle - 360 ;
58
58
}
59
59
return angle;
60
60
}
@@ -71,8 +71,9 @@ void tick() {
71
71
// and later used to indicate stable vertical position
72
72
// of the Balancing Bot.
73
73
void processPinInterrupt () {
74
- offsetAngleDeg = heart.getRotationX ();
74
+ offsetAngleDeg = processAngle ( heart.getRotationX () );
75
75
targetAngleDeg = offsetAngleDeg;
76
+ errorSum = 0 ;
76
77
}
77
78
78
79
// Periodic timer executes the control ticks
You can’t perform that action at this time.
0 commit comments