Because the previous HummBot video was very dark, I've made another video in day light. Also the HummBot can change direction now since the Arduino controls the steering servo of the HummBot!
As you can see in the video, the HummBot clearly needs some sensors to prevent it from hitting obstacles :-)
Don't hesitate to give me some feedback. I'm very interested in hearing your opinion and improvement ideas!
This is the microcontroller code that I used for this video:
1: int ledPin = 13;
2:
3: int servoPin = 4;
4: int rightPulse = 1900;
5: int neutralPulse = 1500;
6: int leftPulse = 1100;
7: int servoPulse = neutralPulse;
8:
9: int escPin = 2; // Control pin for the ESC
10: int forwardPulse = 1565;
11: int previousDirection = neutralPulse;
12: int backwardPulse = 1420;
13: int escPulse = neutralPulse;
14:
15: long lastPulse = 0; // the time in milliseconds of the last pulse
16: int refreshTime = 20; // the time needed in between pulses
17:
18: int waitTime = 2000;
19: long lastChange = 0;
20:
21: void setup() {
22: pinMode(escPin, OUTPUT);
23: pinMode(servoPin, OUTPUT);
24: servoPulse = neutralPulse;
25: escPulse = neutralPulse;
26: pinMode(ledPin, OUTPUT);
27: Serial.begin(9600);
28: }
29:
30: void loop() {
31:
32: if (millis() - lastChange >= waitTime) {
33: // Important: to callibrate the ESC, start with a neutralPulse of 2 sec.
34: // Drive backwards, forwards, backwards, forwards, ...
35: if (escPulse == neutralPulse) {
36: if (previousDirection == forwardPulse) {
37: escPulse = backwardPulse;
38: } else {
39: escPulse = forwardPulse;
40: }
41: if (servoPulse == neutralPulse || servoPulse == rightPulse) {
42: servoPulse = leftPulse;
43: } else {
44: servoPulse = rightPulse;
45: }
46: waitTime = 2000;
47: } else if (escPulse == backwardPulse) {
48: escPulse = neutralPulse;
49: previousDirection = backwardPulse;
50: waitTime = 1000;
51: } else if (escPulse == forwardPulse) {
52: escPulse = neutralPulse;
53: previousDirection = forwardPulse;
54: waitTime = 1000;
55: }
56: // Debugging:
57: if (Serial.available() > 0) {
58: Serial.print(escPulse, DEC);
59: Serial.print(" ");
60: }
61: lastChange = millis();
62: }
63:
64: // send pulses at 50Hz:
65: if (millis() - lastPulse >= refreshTime) {
66: digitalWrite(escPin, HIGH);
67: delayMicroseconds(escPulse);
68: digitalWrite(escPin, LOW);
69: digitalWrite(servoPin, HIGH);
70: delayMicroseconds(servoPulse);
71: digitalWrite(servoPin, LOW);
72: lastPulse = millis(); // save the time of the last pulse
73: }
74: }
No comments:
Post a Comment