Skip to content

Commit 2f4bfce

Browse files
committed
add a button to reset the target reset orentation
1 parent f76468f commit 2f4bfce

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ArduinoClassRobot.ino

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public:
3838
double currentRotationZ=0;
3939
double rotZIncrement=1.2;
4040
double kp=0.01;
41+
double fwdConstant=25;
42+
double resetTarget=0;
4143
int lval ;
4244
int rval ;
4345
Chassis(){}
@@ -59,8 +61,8 @@ public:
5961
}
6062
void write(){
6163
double rotZErr = -kp*(rotZTarget-currentRotationZ);
62-
lval = 90 * fwdTarget - 90 * rotZErr + lCenter;
63-
rval = -90 * fwdTarget - 90 * rotZErr + rCenter;
64+
lval = fwdConstant * fwdTarget - 90 * rotZErr + lCenter;
65+
rval = -fwdConstant * fwdTarget - 90 * rotZErr + rCenter;
6466
if (lval < 0)
6567
lval = 0;
6668
if (rval < 0)
@@ -114,9 +116,12 @@ void loop() {
114116
float y = -fmap(nunchuck.values[0], 0, 255, -1.0, 1.0);
115117
puppy.setTargets(x, y,bno.orientationZ);
116118
if(nunchuck.values[11]>0){
117-
puppy.rotZTarget = 0;
119+
puppy.rotZTarget = puppy.resetTarget;
120+
}
121+
if(nunchuck.values[10]>0){
122+
puppy.resetTarget=puppy.currentRotationZ;
123+
puppy.rotZTarget=puppy.currentRotationZ;
118124
}
119-
120125
delay(10);
121126

122127
Serial.print("\n\tx= ");

0 commit comments

Comments
 (0)