-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v 1.0: WheelBot has a separate module to control motors, but still do…
…esn't have sonar sensor so it can't know where to go. You can control him programmatically hardcoding directions, turns and other actions based on timing.
- Loading branch information
Demven
committed
Dec 18, 2016
0 parents
commit f01b2e5
Showing
8 changed files
with
810 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# WheelBot-01 | ||
Arduino-based robot which can measure the distance ahead of it using ultra-sonic sensor | ||
and decide where to go next, thus avoiding crashes with walls and obstacles. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
void rotate() { | ||
brakeOff(); | ||
leftForward(SPEED_LOW, 0); | ||
rightBackward(SPEED_LOW, 0); | ||
delay(790); | ||
} | ||
|
||
void turnRight() { | ||
brakeOff(); | ||
leftForward(SPEED_LOW, 0); | ||
rightBackward(SPEED_LOW, 0); | ||
delay(500); | ||
} | ||
|
||
void turnLeft() { | ||
brakeOff(); | ||
leftBackward(SPEED_LOW, 0); | ||
rightForward(SPEED_LOW, 0); | ||
delay(500); | ||
} | ||
|
||
void goForward(unsigned int speed, unsigned int time) { | ||
leftForward(speed - LEFT_DECREASE, 0); | ||
rightForward(speed - RIGHT_DECREASE, 0); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
void leftForward(unsigned int speed, unsigned int time) { | ||
brakeOff(); | ||
digitalWrite(LEFT_DIRECTION, HIGH); | ||
leftSpeed(speed); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
void rightForward(unsigned int speed, unsigned int time) { | ||
brakeOff(); | ||
digitalWrite(RIGHT_DIRECTION, LOW); | ||
rightSpeed(speed); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
|
||
void goBackward(unsigned int speed, unsigned int time) { | ||
leftBackward(speed, 0); | ||
rightBackward(speed, 0); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
void leftBackward(unsigned int speed, unsigned int time) { | ||
digitalWrite(LEFT_DIRECTION, LOW); | ||
leftSpeed(speed); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
void rightBackward(unsigned int speed, unsigned int time) { | ||
digitalWrite(RIGHT_DIRECTION, HIGH); | ||
rightSpeed(speed); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
|
||
void changeSpeed(unsigned int speed) { | ||
leftSpeed(speed); | ||
rightSpeed(speed); | ||
} | ||
void leftSpeed(unsigned int speed) { | ||
analogWrite(LEFT_SPEED, speed); | ||
} | ||
void rightSpeed(unsigned int speed) { | ||
analogWrite(RIGHT_SPEED, speed); | ||
} | ||
|
||
void brakeOn(unsigned int time) { | ||
leftBrakeOn(0); | ||
rightBrakeOn(0); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
void leftBrakeOn(unsigned int time) { | ||
digitalWrite(LEFT_BRAKE, HIGH); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
void rightBrakeOn(unsigned int time) { | ||
digitalWrite(RIGHT_BRAKE, HIGH); | ||
if (time > 0) { | ||
delay(time); | ||
} | ||
} | ||
|
||
void brakeOff() { | ||
leftBrakeOff(); | ||
rightBrakeOff(); | ||
} | ||
void leftBrakeOff() { | ||
digitalWrite(LEFT_BRAKE, LOW); | ||
} | ||
void rightBrakeOff() { | ||
digitalWrite(RIGHT_BRAKE, LOW); | ||
} | ||
|
||
int getLeftConsumption() { | ||
return analogRead(LEFT_SNS); | ||
} | ||
int getRightConsumption() { | ||
return analogRead(RIGHT_SNS); | ||
} | ||
|
||
void logCurrentConsumption(String msg) { | ||
Serial.print("Left motor current consumption ");Serial.print(msg);Serial.println(getLeftConsumption()); | ||
Serial.print("Right motor current consumption ");Serial.print(msg);Serial.println(getRightConsumption()); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
void initLogger() { | ||
#if DEBUG_MODE | ||
Serial.begin(DEBUG_RATE); | ||
#endif | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#define DEBUG_MODE true | ||
#define DEBUG_RATE 9600 | ||
|
||
#define LEFT_DECREASE 0 | ||
#define RIGHT_DECREASE 2 | ||
|
||
#define LEFT_SPEED 3 | ||
#define LEFT_DIRECTION 12 | ||
#define LEFT_BRAKE 9 | ||
#define LEFT_SNS A0 | ||
|
||
#define RIGHT_SPEED 11 | ||
#define RIGHT_DIRECTION 13 | ||
#define RIGHT_BRAKE 8 | ||
#define RIGHT_SNS A1 | ||
|
||
#define SPEED_MAX 255 | ||
#define SPEED_MEDIUM 150 | ||
#define SPEED_LOW 70 | ||
#define SPEED_ZERO 0 | ||
|
||
void setup() { | ||
initLogger(); | ||
|
||
pinMode(LEFT_BRAKE, OUTPUT); | ||
pinMode(LEFT_DIRECTION, OUTPUT); | ||
|
||
pinMode(RIGHT_BRAKE, OUTPUT); | ||
pinMode(RIGHT_DIRECTION, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
goForward(SPEED_LOW, 3500); | ||
brakeOn(500); | ||
|
||
rotate(); | ||
brakeOn(1000); | ||
|
||
goForward(SPEED_LOW, 3500); | ||
brakeOn(500); | ||
|
||
while(1); | ||
} |
Oops, something went wrong.