Skip to content

Commit 0beafc1

Browse files
Initial public commit of RC BoE Robot code.
0 parents  commit 0beafc1

File tree

14 files changed

+1109
-0
lines changed

14 files changed

+1109
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
*.bak
2+
*~
3+
.*.sw?
4+
.DS_Store
5+
._*
6+
\#*.lyx\#
7+
\~$*.xlsx
8+
__MACOSX/
9+
10+
11+
# Compiled Object files
12+
*.slo
13+
*.lo
14+
*.o
15+
*.obj
16+
17+
# Precompiled Headers
18+
*.gch
19+
*.pch
20+
21+
# Compiled Dynamic libraries
22+
*.so
23+
*.dylib
24+
*.dll
25+
26+
# Fortran module files
27+
*.mod
28+
29+
# Compiled Static libraries
30+
*.lai
31+
*.la
32+
*.a
33+
*.lib
34+
35+
# Executables
36+
*.exe
37+
*.out
38+
*.app
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Robotics with the BOE Shield - RoamingWithWhiskers
2+
// Go forward. Back up and turn if whiskers indicate BOE Shield bot bumped
3+
// into something.
4+
5+
#include <Servo.h> // Include servo library
6+
7+
#define NOTE_C4 262
8+
9+
Servo servoLeft; // Declare left and right servos
10+
Servo servoRight;
11+
12+
13+
static const int step_dur = 50; // In milliseconds
14+
static const int honk_dur = 1000 + 1000 + 250; // In milliseconds
15+
16+
17+
// static const uint8_t rght_whskr_pin = 7;
18+
// static const uint8_t left_whskr_pin = 5;
19+
20+
21+
static const uint8_t rght_servo_pin = 12;
22+
static const uint8_t left_servo_pin = 13;
23+
static const uint8_t speaker_pin = 9;
24+
25+
26+
static const uint8_t pin_shift_f_l = 8;
27+
static const uint8_t left_btn_pin = pin_shift_f_l - 1;
28+
static const uint8_t bkwd_btn_pin = pin_shift_f_l - 2;
29+
static const uint8_t frwd_btn_pin = pin_shift_f_l - 3;
30+
static const uint8_t rght_btn_pin = pin_shift_f_l - 4;
31+
static const uint8_t honk_btn_pin = pin_shift_f_l - 5;
32+
33+
34+
void honk(unsigned int n = 2);
35+
36+
37+
void setup() // Built-in initialization block
38+
{
39+
Serial.begin(9600);
40+
41+
// Set up input from receiver:
42+
pinMode(left_btn_pin, INPUT_PULLUP);
43+
pinMode(bkwd_btn_pin, INPUT_PULLUP);
44+
pinMode(frwd_btn_pin, INPUT_PULLUP);
45+
pinMode(rght_btn_pin, INPUT_PULLUP);
46+
pinMode(honk_btn_pin, INPUT_PULLUP);
47+
48+
servoLeft.attach(left_servo_pin); // Attach left signal to pin 13
49+
servoRight.attach(rght_servo_pin); // Attach right signal to pin 12
50+
51+
// Set up speaker
52+
pinMode(speaker_pin, OUTPUT);
53+
noTone(speaker_pin);
54+
honk(1);
55+
}
56+
57+
void loop() // Main loop auto-repeats
58+
{
59+
// byte wLeft = digitalRead(5); // Copy left result to wLeft
60+
// byte wRight = digitalRead(7); // Copy right result to wRight
61+
62+
if (digitalRead(honk_btn_pin) == LOW) {
63+
halt();
64+
honk(2);
65+
// delay(step_dur);
66+
} else if (digitalRead(frwd_btn_pin) == LOW) {
67+
while (digitalRead(frwd_btn_pin) == LOW) forward(step_dur);
68+
halt();
69+
} else if (digitalRead(bkwd_btn_pin) == LOW) {
70+
while (digitalRead(bkwd_btn_pin) == LOW) backward(step_dur);
71+
halt();
72+
} else if (digitalRead(left_btn_pin) == LOW) {
73+
while (digitalRead(left_btn_pin) == LOW) turnLeft(step_dur);
74+
halt();
75+
} else if (digitalRead(rght_btn_pin) == LOW) {
76+
while (digitalRead(rght_btn_pin) == LOW) turnRight(step_dur);
77+
halt();
78+
}
79+
80+
// if((wLeft == 0) && (wRight == 0)) // If both whiskers contact
81+
// {
82+
// backward(1000); // Back up 1 second
83+
// turnLeft(800); // Turn left about 120 degrees
84+
// }
85+
// else if(wLeft == 0) // If only left whisker contact
86+
// {
87+
// backward(1000); // Back up 1 second
88+
// turnRight(400); // Turn right about 60 degrees
89+
// }
90+
// else if(wRight == 0) // If only right whisker contact
91+
// {
92+
// backward(1000); // Back up 1 second
93+
// turnLeft(400); // Turn left about 60 degrees
94+
// }
95+
// else // Otherwise, no whisker contact
96+
// {
97+
// forward(20); // Forward 1/50 of a second
98+
// }
99+
}
100+
101+
void halt() // Halt function
102+
{
103+
servoLeft.writeMicroseconds(1500); // Left wheel counterclockwise
104+
servoRight.writeMicroseconds(1500); // Right wheel clockwise
105+
}
106+
107+
void forward(int time) // Forward function
108+
{
109+
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
110+
servoRight.writeMicroseconds(1300); // Right wheel clockwise
111+
delay(time); // Maneuver for time ms
112+
}
113+
114+
void turnLeft(int time) // Left turn function
115+
{
116+
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
117+
servoRight.writeMicroseconds(1300); // Right wheel clockwise
118+
delay(time); // Maneuver for time ms
119+
}
120+
121+
void turnRight(int time) // Right turn function
122+
{
123+
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
124+
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
125+
delay(time); // Maneuver for time ms
126+
}
127+
128+
void backward(int time) // Backward function
129+
{
130+
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
131+
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
132+
delay(time); // Maneuver for time ms
133+
}
134+
135+
void honk(unsigned int n) {
136+
for (int i = 0; i < n; i++) {
137+
tone(speaker_pin, NOTE_C4, 1000); // Play tone for 1 second
138+
delay(1000); // Delay to finish tone
139+
noTone(speaker_pin);
140+
if (i+1 < n) delay(250); // Only delay between honks
141+
}
142+
}

rc_boe_bot_server/.ackrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--ignore-directory=build
2+
--ignore-directory=node_modules

rc_boe_bot_server/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.bak
2+
*~
3+
.*.sw?
4+
.DS_Store
5+
._*
6+
\#*.lyx\#
7+
\~$*.xlsx
8+
__MACOSX/
9+
10+
11+
build/
12+
tmp/
13+
.idea/
14+
node_modules/
15+
*npm-debug.log*
16+
*.tgz

rc_boe_bot_server/.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tmp/
2+
.idea/
3+
node_modules/
4+
*npm-debug.log
5+
*.tgz
6+
test/
7+
.git/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "bean-sdk",
3+
"version": "0.5.3",
4+
"description": "Official Light Blue Bean SDK for Node.js by Punch Through",
5+
"keywords": [
6+
"bean",
7+
"punchthrough",
8+
"lightblue",
9+
"ble",
10+
"bluetooth",
11+
"noble"
12+
],
13+
"main": "build/lightblue.js",
14+
"babel": {
15+
"presets": [
16+
"es2015"
17+
]
18+
},
19+
"bin": {
20+
"bean": "build/cli/entry.js"
21+
},
22+
"scripts": {
23+
"test": "./node_modules/.bin/mocha --compilers js:babel-register --recursive",
24+
"babel": "./node_modules/.bin/babel src -d build/",
25+
"build": "python scripts/build"
26+
},
27+
"repository": {
28+
"type": "git",
29+
"url": "git+https://github.com/PunchThrough/bean-sdk-node.git"
30+
},
31+
"author": "Stephen Stack",
32+
"license": "ISC",
33+
"bugs": {
34+
"url": "https://github.com/PunchThrough/bean-sdk-node/issues"
35+
},
36+
"homepage": "https://github.com/PunchThrough/bean-sdk-node#readme",
37+
"dependencies": {
38+
"async": "*",
39+
"commander": "*",
40+
"crc": "^3.4.0",
41+
"fs-extra": "^0.30.0",
42+
"js-yaml": "*",
43+
"noble": "^1.7.0",
44+
"queue": "^4.0.0",
45+
"sleep": "^3.0.1",
46+
"sprintf-js": "^1.0.3",
47+
"winston": "^2.2.0"
48+
},
49+
"devDependencies": {
50+
"babel-cli": "^6.11.4",
51+
"babel-preset-es2015": "^6.13.2",
52+
"babel-register": "^6.14.0",
53+
"mocha": "*",
54+
"sinon": "^1.17.4"
55+
}
56+
}

0 commit comments

Comments
 (0)