Skip to content

Commit c3e8171

Browse files
committed
Update to avoid bug where the robot suddenly accelerated.
1 parent 195fa22 commit c3e8171

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

out/leJOS-RobotPilot.jar

8 Bytes
Binary file not shown.

src/robotpilot/RobotPilot.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public void travel(float distance, boolean immediateReturn) {
9090

9191
}
9292

93-
public void travelDegrees(int degrees) {motor1.setSpeed(0);
94-
setSpeed(speed);
93+
public void travelDegrees(int degrees) {
94+
stop();
95+
setSpeed(speed);
9596
synchronizeMotors();
9697
motor1.rotate(degrees, true);
9798
motor2.rotate(degrees, true);
@@ -136,8 +137,6 @@ public void backward() {
136137
// Starts backward movement of the robot
137138
setSpeed(speed);
138139
synchronizeMotors();
139-
motor1.setSpeed(0);
140-
motor2.setSpeed(0);
141140
if (inverted) {
142141
motor1.forward();
143142
motor2.forward();
@@ -322,7 +321,6 @@ public void close() {
322321

323322
public void setSpeed(float speed) {
324323
// Sets the speed of the robot
325-
stop();
326324
this.speed = speed;
327325
synchronizeMotors();
328326
motor1.setSpeed(speed);
@@ -350,8 +348,11 @@ public int getRightMotorSpeed() {
350348
public void startRotate(boolean right) {
351349
// Starts a rotating motion
352350
// If right is true, the robot will rotate right, otherwise he will rotate left
351+
stop();
352+
synchronizeMotors();
353353
motor1.setSpeed(rotateSpeed);
354354
motor2.setSpeed(rotateSpeed);
355+
motor1.endSynchronization();
355356
synchronizeMotors();
356357
if (right) {
357358
if (inverted) {
@@ -482,6 +483,8 @@ public void rotate(float angle, float friction, boolean immediateReturn) {
482483
synchronizeMotors();
483484
motor1.setSpeed(rotateSpeed);
484485
motor2.setSpeed(rotateSpeed);
486+
motor1.endSynchronization();
487+
synchronizeMotors();
485488
motor1.rotate((int) (degreesToTravel * friction), true);
486489
motor2.rotate((int) (-degreesToTravel * friction), true);
487490
motor1.endSynchronization();
@@ -675,15 +678,19 @@ public void resetRightTachoCount() {
675678
}
676679

677680
public void quickStop() {
681+
synchronizeMotors();
678682
motor1.setAcceleration(QUICK_ACCELERATION);
679683
motor2.setAcceleration(QUICK_ACCELERATION);
684+
motor1.endSynchronization();
680685
stop();
681686
setAcceleration(acceleration);
682687
}
683688

684689
public void quickStop(boolean immediateReturn) {
690+
synchronizeMotors();
685691
motor1.setAcceleration(QUICK_ACCELERATION);
686692
motor2.setAcceleration(QUICK_ACCELERATION);
693+
motor1.endSynchronization();
687694
stop(immediateReturn);
688695
setAcceleration(acceleration);
689696
}

0 commit comments

Comments
 (0)