Mercurial > ~darius > hgwebdir.cgi > splitbrain
annotate sea/sea.ino @ 0:fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sat, 11 Jul 2015 15:20:05 +0930 |
parents | |
children | 6f1cd84f8e23 |
rev | line source |
---|---|
0
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #include <Wire.h> |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 #include <Adafruit_MotorShield.h> |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 #include "utility/Adafruit_PWMServoDriver.h" |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 // Orange - Vertical M2+ |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 // White/orange - Vertical M2- |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 // Green - Left M3+ |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 // White/green - Left M3- |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 // Blue - Right M1+ |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 // White/blue - Right M1- |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 // Brown - RS485 B |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 // Brown/white - RS485 A |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 // Motor shield object at default address |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 Adafruit_MotorShield AFMS = Adafruit_MotorShield(); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 // Motor objects |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 Adafruit_DCMotor *leftMotor = AFMS.getMotor(3); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 Adafruit_DCMotor *rightMotor = AFMS.getMotor(1); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 Adafruit_DCMotor *vertMotor = AFMS.getMotor(2); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 void setup() { |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 Serial.begin(115200); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 AFMS.begin(); // Start at default frequency |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 } |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 int |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 parseIn(char dir) { |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 int tmp; |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 while (Serial.read() != dir) |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 ; |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 while (Serial.read() != ':') |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 ; |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 tmp = Serial.parseInt(); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 return tmp; |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 } |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 void loop() { |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 int tmp; |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
43 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 Serial.println("Parsing L..."); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 tmp = parseIn('L'); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 if (tmp > 0) |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 leftMotor->run(FORWARD); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 else |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 leftMotor->run(BACKWARD); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 leftMotor->setSpeed(abs(tmp)); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 Serial.println("Parsing R..."); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 tmp = parseIn('R'); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 if (tmp > 0) |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 rightMotor->run(FORWARD); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 else |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 rightMotor->run(BACKWARD); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 rightMotor->setSpeed(abs(tmp)); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 Serial.println("Parsing V..."); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 tmp = parseIn('V'); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 if (tmp > 0) |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 vertMotor->run(FORWARD); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 else |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 vertMotor->run(BACKWARD); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 vertMotor->setSpeed(abs(tmp)); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 Serial.println("Done"); |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 } |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
71 /* |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 * Local variables: |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
73 * mode: c++ |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 * End: |
fe0a2f223e10
Initial commit of split brain code for the Sea Dragon.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
75 */ |