Last active
January 1, 2017 22:30
-
-
Save attilavago/409df8810652890dc55f85fca699c638 to your computer and use it in GitHub Desktop.
Running motors with robotary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test the motors all all 4 ports | |
import RobotKit | |
// Create a new EV3Robot instance to talk to the robot | |
let robot = try EV3Robot() | |
// Access motors at ports A, B, C and D. | |
let motors = robot.motors(atPorts: [.A, .B, .C, .D]) // note de dot notation of the ports | |
// Adding variables to access motors individually | |
let motorA = robot.motors(atPorts: [.A]) | |
let motorB = robot.motors(atPorts: [.B]) | |
let motorC = robot.motors(atPorts: [.C]) | |
let motorD = robot.motors(atPorts: [.D]) | |
print("waiting for 5 seconds") | |
wait(seconds: 5) // setting an initial timeout of 5 seconds | |
// All motors drive forward in the current direction at 40% speed for 2 seconds | |
motors.setSpeed(40) | |
wait(seconds: 2) | |
// Stop for 1 second | |
motors.stop(applyBrakes: true) | |
wait(seconds: 1) | |
motorA.setSpeed(100) | |
wait(milliseconds: 100) | |
motorB.setSpeed(75) | |
wait(milliseconds: 70) | |
motorC.setSpeed(50) | |
wait(milliseconds: 50) | |
motorD.setSpeed(20) | |
wait(milliseconds: 80) | |
// All motors drive backwards in the reverse direction at 40% speed for 2 seconds | |
motors.setSpeed(-40) | |
wait(seconds: 3) | |
// Stop indefinitely | |
motors.stop(applyBrakes: false) | |
print("motors test done, yay") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment