/
Tank_MiniTrooper.ino
53 lines (52 loc) · 1.29 KB
/
Tank_MiniTrooper.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <Arduino.h>
/*
Setup RoboBoard to use Drivetrain module.
Allows to configure robot wheel placement and use
functions to control drive direction.
Unplug USB cable and press BOOT button.
*/
// Set flipper position [0:100]%
void setFlipper(int pos) {
Servo.A.spinPos(map(pos, 0, 100, -100, 100));
}
// Initialize program
void setup() {
/**
* Tank drive configuration
*/
// Assign left wheel to DC motor port A
Drivetrain.setWheelLeft(DC.A);
// Assign right wheel to DC motor port B
Drivetrain.setWheelRight(DC.B);
// Select tank drive
Drivetrain.setDriveTank();
// Open flipper
setFlipper(100);
// Wait for USB cable to be pulled out
// Prevents start driving
Board.waitUSB();
// Wait for button press
Button.waitClick();
// Wait a bit after button press
delay(500);
// Semi close flipper
setFlipper(50);
}
// Loop program
void loop() {
// Drive forward and turn right
Drivetrain.driveTurn(50, 60);
delay(1000); // Wait 1 second
// Drive backward at 50% speed
Drivetrain.drive(-50);
delay(1000); // Wait 1 second
// Spin in place left
Drivetrain.turn(-100);
delay(1000); // Wait 1 second
// Brake to full stop
Drivetrain.brake();
setFlipper(100); // Open flipper
delay(300);
setFlipper(50); // Semi close flipper
delay(500);
}