Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add int cast to code generation of motor blocks for Spike #1545

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@

def run():
# drive
diff_drive.move(10, 'cm', 0, 30)
diff_drive.move(10, 'cm', 0, -(30))
diff_drive.start(0, 30)
diff_drive.move(10, 'cm', 0, int(30))
diff_drive.move(10, 'cm', 0, int(-(30)))
diff_drive.start(0, int(30))
wait_for_seconds(500/1000)
diff_drive.start_at_power(-(30), 0)
diff_drive.start_at_power(int(-(30)), 0)
wait_for_seconds(500/1000)
diff_drive.set_stop_action('brake')
diff_drive.stop()
# turn
diff_drive.move(20 * math.pi / 360 * TRACKWIDTH, 'cm', 100, 30)
diff_drive.move(20 * math.pi / 360 * TRACKWIDTH, 'cm', -100, 30)
diff_drive.start(100, 30)
diff_drive.move(20 * math.pi / 360 * TRACKWIDTH, 'cm', 100, int(30))
diff_drive.move(20 * math.pi / 360 * TRACKWIDTH, 'cm', -100, int(30))
diff_drive.start(100, int(30))
wait_for_seconds(500/1000)
diff_drive.start_at_power(30, -100)
diff_drive.start_at_power(int(30), -100)
wait_for_seconds(500/1000)
diff_drive.set_stop_action('coast')
diff_drive.stop()
# steer
diff_drive.move_tank(20, 'cm', 10, 30)
diff_drive.move_tank(-(20), 'cm', 10, 30)
diff_drive.start_tank(10, 30)
diff_drive.move_tank(20, 'cm', int(10), int(30))
diff_drive.move_tank(-(20), 'cm', int(10), int(30))
diff_drive.start_tank(int(10), int(30))
wait_for_seconds(500/1000)
diff_drive.start_tank_at_power(-(10), -(30))
diff_drive.start_tank_at_power(int(-(10)), int(-(30)))
wait_for_seconds(500/1000)
diff_drive.set_stop_action('coast')
diff_drive.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

def run():
# motor
motorB.run_for_rotations(1, 30)
motorA.run_for_degrees(360, 30)
motorB.start(30)
motorB.run_for_rotations(1, int(30))
motorA.run_for_degrees(360, int(30))
motorB.start(int(30))
wait_for_seconds(500/1000)
motorB.set_stop_action('coast')
motorB.stop()
motorA.start_at_power(-30)
motorA.start_at_power(int(-30))
wait_for_seconds(500/1000)
motorA.set_stop_action('brake')
motorA.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public Void visitMainTask(MainTask mainTask) {
public Void visitMotorDiffOnForAction(MotorDiffOnForAction motorDiffOnForAction) {
src.add("diff_drive.move(");
motorDiffOnForAction.distance.accept(this);
src.add(", 'cm', 0, ");
src.add(", 'cm', 0, int(");
switch ( motorDiffOnForAction.direction ) {
case "BACKWARD":
src.add("-(");
Expand All @@ -118,7 +118,7 @@ public Void visitMotorDiffOnForAction(MotorDiffOnForAction motorDiffOnForAction)
default:
throw new DbcException("Invalid drive direction: " + motorDiffOnForAction.direction);
}
src.add(")");
src.add("))");
return null;
}

Expand All @@ -137,8 +137,9 @@ public Void visitMotorDiffTurnForAction(MotorDiffTurnForAction motorDiffTurnForA
default:
throw new DbcException("Invalid turn direction: " + motorDiffTurnForAction.direction);
}
src.add("int(");
motorDiffTurnForAction.power.accept(this);
src.add(")");
src.add("))");
return null;
}

Expand All @@ -152,6 +153,7 @@ public Void visitMotorDiffOnAction(MotorDiffOnAction motorDiffOnAction) {
src.add("diff_drive.start_at_power(");
end = ", 0)";
}
src.add("int(");
switch ( motorDiffOnAction.direction ) {
case "BACKWARD":
src.add("-(");
Expand All @@ -164,7 +166,7 @@ public Void visitMotorDiffOnAction(MotorDiffOnAction motorDiffOnAction) {
default:
throw new DbcException("Invalid drive direction: " + motorDiffOnAction.direction);
}
src.add(end);
src.add(")", end);
return null;
}

Expand All @@ -189,8 +191,9 @@ public Void visitMotorDiffTurnAction(MotorDiffTurnAction motorDiffTurnAction) {
src.add("diff_drive.start_at_power(");
end = ", " + String.valueOf(turn) + ")";
}
src.add("int(");
motorDiffTurnAction.power.accept(this);
src.add(end);
src.add(")", end);
return null;
}

Expand All @@ -209,11 +212,11 @@ public Void visitMotorDiffCurveForAction(MotorDiffCurveForAction motorDiffCurveF
default:
throw new DbcException("Invalid curve direction: " + motorDiffCurveForAction.direction);
}
src.add(", 'cm', ");
src.add(", 'cm', int(");
motorDiffCurveForAction.powerLeft.accept(this);
src.add(", ");
src.add("), int(");
motorDiffCurveForAction.powerRight.accept(this);
src.add(")");
src.add("))");
return null;
}

Expand Down Expand Up @@ -350,21 +353,22 @@ public Void visitMotorDiffCurveAction(MotorDiffCurveAction motorDiffCurveAction)
}
switch ( motorDiffCurveAction.direction ) {
case "BACKWARD":
src.add("-(");
src.add("int(-(");
motorDiffCurveAction.powerLeft.accept(this);
src.add("), -(");
src.add(")), int(-(");
motorDiffCurveAction.powerRight.accept(this);
src.add(")");
break;
case "FORWARD":
src.add("int(");
motorDiffCurveAction.powerLeft.accept(this);
src.add(", ");
src.add("), int(");
motorDiffCurveAction.powerRight.accept(this);
break;
default:
throw new DbcException("Invalid curve direction: " + motorDiffCurveAction.direction);
}
src.add(")");
src.add("))");
return null;
}

Expand Down Expand Up @@ -403,9 +407,9 @@ public Void visitMotorOnForAction(MotorOnForAction motorOnForAction) {

}
motorOnForAction.value.accept(this);
this.src.add(", ");
this.src.add(", int(");
motorOnForAction.power.accept(this);
this.src.add(")");
this.src.add("))");
return null;
}

Expand All @@ -417,8 +421,9 @@ public Void visitMotorOnAction(MotorOnAction motorOnAction) {
} else {
src.add(".start_at_power(");
}
src.add("int(");
motorOnAction.power.accept(this);
src.add(")");
src.add("))");
return null;
}

Expand Down