-
Notifications
You must be signed in to change notification settings - Fork 0
Writing a Basic Motor Control Run
johnmeshulam edited this page Nov 10, 2019
·
2 revisions
In this first example, we will create a program that spins a meduim motor 420 degrees forward, waits a few seconds, and then spins it back.
We will be using the armMotor on port A, that we defined in the Defining Hardware tutorial.
The first step is creating a new class in our user.runs package. Let's call this class Run1.
public class Run1 {
}In order for this class to be a valid run, it needs to extend the RobotRun class, and implement 2 methods:
- A constructor. This is a simple constructor that sets the run's display name, which will show up on the brick.
- a
public voidmethod namedrunInstructions. This is where our run code will go. Your code should now look something like this:
public class Run1 extends RobotRun {
public Run1(String name) {
super(name);
}
@Override
public void runInstructions() {
//Your code here
}
}Now that we've set up our basic run template, lets write the actual code. Our program flow is very simple:
-
Rotate the motor 420 degrees
-
Wait 2 seconds
-
Rotate the motor back 420 degrees
In FLL-leJOS code, this can be written using 3 simple lines:
RobotMap.getMotor("armMotor").rotateDegrees(0.5, 420, true); //rotate the motor forwards at 50% speed
Wait.waitForSeconds(2.0); //wait 3 seconds
RobotMap.getMotor("armMotor").rotateDegrees(-0.5, 420, true); //rotate the motor backwards at 50% speedOur final run should look like this:
public class Run1 extends RobotRun{
public Run1(String name) {
super(name);
}
@Override
public void runInstructions() {
RobotMap.getMotor("armMotor").rotateDegrees(0.5, 420, true);
Wait.waitForSeconds(3.0);
RobotMap.getMotor("armMotor").rotateDegrees(-0.5, 420, true);
}
}- Overview
- Code Documentation
- Writing our first run
- Setting Up
- Defining hardware
- Writing a basic Motor Control run
- [Adding sensors and waits]
- [Defining Runs]
- Writing our second run
- [Using the chassis]
- [Finishing up]
- [Line follower code example]