From 82d60b743ea139c153f9c6a621c0c8f84898480e Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Wed, 22 Jan 2020 00:25:03 -0500 Subject: [PATCH 01/28] Blink Test Making LEDs blink in different pattern depending on state. Note: Have some problems with LEDs on/off status and state, untested function --- Blink Test | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Blink Test diff --git a/Blink Test b/Blink Test new file mode 100644 index 0000000..37e2c71 --- /dev/null +++ b/Blink Test @@ -0,0 +1,91 @@ +#include "Arduino.h" + +static uint8_t state; +static unsigned int button; +static unsigned int mySwitch; +enum States_enum {OFF, ON, RUN}; + +/* New Code Not Tested */ +void blink(int pin, int hertz); + +void setup() { + // put your setup code here, to run once: + pinMode(LED_BUILTIN, OUTPUT); + pinMode(2, INPUT); // RUN/STOP button + pinMode(3, INPUT); // ON/OFF switch + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); + pinMode(6, OUTPUT); + + Serial.begin(9600); + + state = OFF; +} + +void loop() { + // put your main code here, to run repeatedly: + button = digitalRead(2); + mySwitch = digitalRead(3); + + switch (state) + { + case OFF: + if(mySwitch == HIGH){ + state = ON; + digitalWrite(4, LOW); // turn off RED LED + } + else { + digitalWrite(4 , HIGH); // turn on RED LED + Serial.println("I'm Off"); // send a message if in OFF state + } + break; + + + case ON: + if(mySwitch == LOW){ + state = OFF; + digitalWrite(5, LOW); // turn GREEN LED off when switch is LOW + break; + } + + if(button == LOW){ // assuming PULL-UP + state = RUN; + digitalWrite(5, LOW); // turn GREEN LED off as we switch state to RUN + } + else{ // Blink at 10 Hz + blink(5, 10); + Serial.println("I'm On"); // send a message if in ON state + } + break; + + + case RUN: + if(mySwitch == LOW){ + state = OFF; + digitalWrite(6, LOW); // turn BLUE LED off + break; + } + + if (button == LOW){ + state = ON; + digitalWrite(6, LOW); // turn BLUE LED off as we switch state to ON + } + else{ // long blink 4 Hz, short blink 8 Hz + blink(6, 4); + blink(6, 8); + Serial.println("I'm Running"); // send a message if in RUN state + } + break; + } + +} + +void blink (int pin, int hertz) { + int time; + time = 1/hertz; + + digitalWrite(pin, HIGH); // turn the LED on (HIGH is the voltage level) + delay(time); // wait for some second + digitalWrite(pin, LOW); // turn the LED off by making the voltage LOW + delay(time); +} -- GitLab From f9c3f55a9773db26098bb89430970c27a17d5bf1 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Wed, 22 Jan 2020 00:29:46 -0500 Subject: [PATCH 02/28] Interrupt Test Should blink when button is pressed. Note: untested --- Interrupt Test | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Interrupt Test diff --git a/Interrupt Test b/Interrupt Test new file mode 100644 index 0000000..545dc91 --- /dev/null +++ b/Interrupt Test @@ -0,0 +1,32 @@ +static unsigned int state; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + pinMode(2, INPUT); + attachInterrupt(digitalPinToInterrupt(2), myISR(), FALLING); + state = 0; +} + +void loop() { + // put your main code here, to run repeatedly: + if(state == 0){ + digitalWrite(4, LOW); + } else { + for(int i= 0; i < 3; i++){ + digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(4, LOW); // turn the LED off by making the voltage LOW + delay(1000); + } + } + +} + +void myISR() { + if(state == 0){ + state = 1; + } else { + state = 0; + } +} -- GitLab From ffd87047cbd1998d6ded0cbefb353b1061b867a9 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Wed, 29 Jan 2020 17:17:46 -0500 Subject: [PATCH 03/28] Drive a motor simple --- DriveMotorMiniTest | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 DriveMotorMiniTest diff --git a/DriveMotorMiniTest b/DriveMotorMiniTest new file mode 100644 index 0000000..1461dca --- /dev/null +++ b/DriveMotorMiniTest @@ -0,0 +1,29 @@ +#include "Arduino.h" + +String readString; +const byte ledPinBLUE = 6; + +void setup() { + Serial.begin(9600); + Serial.println("Driving led using Serial Test"); // so I can keep track of what is loaded + pinMode(ledPinBLUE, OUTPUT); +} + +void loop() { + int n; + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + Serial.println("Input is: "); + Serial.println(readString); //so you can see the captured string + n = readString.toInt(); //convert readString into a number + + readString=""; //empty for next input + } + + analogWrite(ledPinBLUE, n); +} -- GitLab From 286e793446357e366994d9f736ff0495002aedac Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Wed, 29 Jan 2020 17:38:35 -0500 Subject: [PATCH 04/28] Blink test Not needed Not satisfied with code. Not Necessary --- Blink Test | 91 ------------------------------------------------------ 1 file changed, 91 deletions(-) delete mode 100644 Blink Test diff --git a/Blink Test b/Blink Test deleted file mode 100644 index 37e2c71..0000000 --- a/Blink Test +++ /dev/null @@ -1,91 +0,0 @@ -#include "Arduino.h" - -static uint8_t state; -static unsigned int button; -static unsigned int mySwitch; -enum States_enum {OFF, ON, RUN}; - -/* New Code Not Tested */ -void blink(int pin, int hertz); - -void setup() { - // put your setup code here, to run once: - pinMode(LED_BUILTIN, OUTPUT); - pinMode(2, INPUT); // RUN/STOP button - pinMode(3, INPUT); // ON/OFF switch - pinMode(4, OUTPUT); - pinMode(5, OUTPUT); - pinMode(6, OUTPUT); - - Serial.begin(9600); - - state = OFF; -} - -void loop() { - // put your main code here, to run repeatedly: - button = digitalRead(2); - mySwitch = digitalRead(3); - - switch (state) - { - case OFF: - if(mySwitch == HIGH){ - state = ON; - digitalWrite(4, LOW); // turn off RED LED - } - else { - digitalWrite(4 , HIGH); // turn on RED LED - Serial.println("I'm Off"); // send a message if in OFF state - } - break; - - - case ON: - if(mySwitch == LOW){ - state = OFF; - digitalWrite(5, LOW); // turn GREEN LED off when switch is LOW - break; - } - - if(button == LOW){ // assuming PULL-UP - state = RUN; - digitalWrite(5, LOW); // turn GREEN LED off as we switch state to RUN - } - else{ // Blink at 10 Hz - blink(5, 10); - Serial.println("I'm On"); // send a message if in ON state - } - break; - - - case RUN: - if(mySwitch == LOW){ - state = OFF; - digitalWrite(6, LOW); // turn BLUE LED off - break; - } - - if (button == LOW){ - state = ON; - digitalWrite(6, LOW); // turn BLUE LED off as we switch state to ON - } - else{ // long blink 4 Hz, short blink 8 Hz - blink(6, 4); - blink(6, 8); - Serial.println("I'm Running"); // send a message if in RUN state - } - break; - } - -} - -void blink (int pin, int hertz) { - int time; - time = 1/hertz; - - digitalWrite(pin, HIGH); // turn the LED on (HIGH is the voltage level) - delay(time); // wait for some second - digitalWrite(pin, LOW); // turn the LED off by making the voltage LOW - delay(time); -} -- GitLab From 9d1d2253b37d74433a9cfa9e67fc0a1735a4f22a Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Wed, 29 Jan 2020 23:35:29 -0500 Subject: [PATCH 05/28] Add files via upload --- DriveMotorTest/DriveMotorTest.ino | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 DriveMotorTest/DriveMotorTest.ino diff --git a/DriveMotorTest/DriveMotorTest.ino b/DriveMotorTest/DriveMotorTest.ino new file mode 100644 index 0000000..ec78f51 --- /dev/null +++ b/DriveMotorTest/DriveMotorTest.ino @@ -0,0 +1,92 @@ +#include "Arduino.h" + +const byte interruptPinButton = 2; + +const byte ledPinRED = 4; +const byte ledPinGREEN = 5; +const byte ledPinBLUE = 6; +volatile int curr_speed; + +String readString; + +volatile uint8_t state; +enum States_enum {FORWARD, BACKWARD}; + +void myISR(); +void ledOff(int pin); +void ledOn(int pin); +void speedControl(); + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + pinMode(interruptPinButton, INPUT_PULLUP); // RUN/STOP button + pinMode(ledPinRED, OUTPUT); + pinMode(ledPinGREEN, OUTPUT); + pinMode(ledPinBLUE, OUTPUT); + Serial.begin(9600); + + Serial.println("Driving motor using Serial Test"); // so I can keep track of what is loaded + attachInterrupt(digitalPinToInterrupt(interruptPinButton), myISR, FALLING); + state = FORWARD; +} + +void loop() { + + switch (state) + { + case FORWARD: + ledOff(ledPinBLUE); + speedControl(); + analogWrite(ledPinGREEN, curr_speed); + break; + + case BACKWARD: + ledOff(ledPinGREEN); + speedControl(); + analogWrite(ledPinBLUE, curr_speed); + break; + } + +} + +void myISR() { + if(state == FORWARD){ + curr_speed = 0; + state = BACKWARD; + Serial.println("Moving BACKWARD"); + } else if(state == BACKWARD) { + curr_speed = 0; + state = FORWARD; + Serial.println("Moving FORWARD"); + } + delay(2); + +} + +void speedControl() +{ + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + Serial.println("Input is: "); + Serial.println(readString); //so you can see the captured string + curr_speed = readString.toInt(); //convert readString into a number + + readString=""; //empty for next input + } +} + +void ledOff(int pin) +{ + digitalWrite(pin, LOW); +} + +void ledOn(int pin) +{ + digitalWrite(pin, HIGH); +} + -- GitLab From 52703e56e25acd7c88fada9e588f93113285bb88 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Sun, 2 Feb 2020 17:54:42 -0500 Subject: [PATCH 06/28] Drive motor using H-bridge IC --- LockedAntiphase/LockedAntiphase.ino | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 LockedAntiphase/LockedAntiphase.ino diff --git a/LockedAntiphase/LockedAntiphase.ino b/LockedAntiphase/LockedAntiphase.ino new file mode 100644 index 0000000..be457e8 --- /dev/null +++ b/LockedAntiphase/LockedAntiphase.ino @@ -0,0 +1,90 @@ +#include "Arduino.h" + +const byte WheelOneF = 2; +const byte WheelOneB = 3; +const byte WheelTwoF = 4; +const byte WheelTwoB = 5; +volatile int curr_speed; + +String readString; + +volatile uint8_t state; +enum States_enum {FORWARD, BACKWARD}; + +void pinClose(int pin); +void pinOpen(int pin); +void speedControl(); + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + pinMode(WheelOneF, OUTPUT); + pinMode(WheelOneB, OUTPUT); + pinMode(WheelTwoF, OUTPUT); + pinMode(WheelTwoB, OUTPUT); + Serial.begin(9600); + Serial.println("Driving motor back and forth Test"); // so I can keep track of what is loaded + Serial.println("Moving Forward"); + state = FORWARD; + curr_speed = 0; +} + +void loop() { + + switch (state) + { + case FORWARD: + speedControl(); + pinOpen(WheelOneB); + pinOpen(WheelTwoB); + analogWrite(WheelOneF, curr_speed); + analogWrite(WheelTwoF, curr_speed); + break; + + case BACKWARD: + speedControl(); + pinOpen(WheelOneF); + pinOpen(WheelTwoF); + analogWrite(WheelOneB, curr_speed); + analogWrite(WheelTwoB, curr_speed); + break; + } + +} + +void speedControl() +{ + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + + if (c == 'f'){ + Serial.println("Going Forward"); + state = FORWARD; + } else if (c == 'b'){ + Serial.println("Moving Backward"); + state = BACKWARD; + } + + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + curr_speed = readString.toInt(); + Serial.println("Speed:"); + Serial.println(curr_speed); + + readString=""; //empty for next input + } +} + +void pinOpen(int pin) +{ + digitalWrite(pin, LOW); +} + +void pinClose(int pin) +{ + digitalWrite(pin, HIGH); +} + + -- GitLab From 0219485297232ba81f43b95a7630ad221a9a7a6a Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Tue, 4 Feb 2020 14:42:27 -0500 Subject: [PATCH 07/28] Controlling the motion of the proto bot --- MotionControl/MotionControl.ino | 163 ++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 MotionControl/MotionControl.ino diff --git a/MotionControl/MotionControl.ino b/MotionControl/MotionControl.ino new file mode 100644 index 0000000..fb2df2f --- /dev/null +++ b/MotionControl/MotionControl.ino @@ -0,0 +1,163 @@ +#include "Arduino.h" + +const byte WheelLeftF = 2; +const byte WheelLeftB = 3; +const byte WheelRightF = 4; +const byte WheelRightB = 5; +volatile int curr_speed_left; +volatile int curr_speed_right; + +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +String readString; + +volatile uint8_t state; +enum States_enum {STOP, FORWARD, BACKWARD, LEFT, RIGHT, CIRCLE}; + +void pinClose(int pin); +void pinOpen(int pin); +void speedControl(); + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + pinMode(WheelLeftF, OUTPUT); + pinMode(WheelLeftB, OUTPUT); + pinMode(WheelRightF, OUTPUT); + pinMode(WheelRightB, OUTPUT); + Serial.begin(9600); + Serial.println("Driving motor motion Test"); // so I can keep track of what is loaded + Serial.println("Stop"); + state = STOP; +} + +void loop() { + + switch (state) + { + case STOP: + speedControl(); + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + pinOpen(WheelLeftF); + pinOpen(WheelRightF); + break; + + case FORWARD: + speedControl(); + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + analogWrite(WheelLeftF, HALF); + analogWrite(WheelRightF, HALF); + break; + + case BACKWARD: + speedControl(); + pinOpen(WheelLeftF); + pinOpen(WheelRightF); + analogWrite(WheelLeftB, HALF); + analogWrite(WheelRightB, HALF); + break; + + case LEFT: + speedControl(); + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + analogWrite(WheelLeftF, ZERO); + analogWrite(WheelRightF, TQUARTER); + break; + + case RIGHT: + speedControl(); + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + analogWrite(WheelLeftF, TQUARTER); + analogWrite(WheelRightF, ZERO); + break; + + case CIRCLE: + speedControl(); + pinOpen(WheelLeftB); + pinOpen(WheelRightF); + analogWrite(WheelLeftF, QUARTER); + analogWrite(WheelRightB, QUARTER); + break; + } + +} + +void speedControl() +{ + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + + if (c == 'f'){ + Serial.println("Going Forward"); + state = FORWARD; + } else if (c == 'b'){ + Serial.println("Moving Backward"); + state = BACKWARD; + } else if (c == 'l'){ + Serial.println("Moving Left"); + state = LEFT; + } else if (c == 'r'){ + Serial.println("Moving Right"); + state = RIGHT; + } else if (c == 's'){ + Serial.println("Stop"); + state = STOP; + } else if (c == 'c'){ + Serial.println("Turn 360"); + state = CIRCLE; + } + + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + readString=""; //empty for next input + + delay(2); //slow down a bit so motors have time to get inputs + } + + /*if (readString.length() >0) { + curr_speed_left = readStringLeft.toInt(); + Serial.println("Speed Left:"); + Serial.println(curr_speed_left); + + curr_speed_right = readStringRight.toInt(); + Serial.println("Speed Right:"); + Serial.println(curr_speed_right); + + readString=""; //empty for next input + + delay(2); //slow down a bit so motors have time to get inputs + }*/ +} + +void pinOpen(int pin) +{ + digitalWrite(pin, LOW); +} + +void pinClose(int pin) +{ + digitalWrite(pin, HIGH); +} + +void blink (int pin, float hertz, int brightness) { + unsigned int time; + time = 1/hertz * 1000; + + if (state != STOP) { + analogWrite(pin, brightness); // turn the LED on (HIGH is the voltage level) + delay(time); // wait for some second + analogWrite(pin, 0); // turn the LED off by making the voltage LOW + delay(time); + } +} + -- GitLab From 2e6c97aeb2dc0d4cd0f6901a29450f2b6636df8d Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Tue, 4 Feb 2020 20:02:43 -0500 Subject: [PATCH 08/28] A unTested more advance version of motion control --- MotionControl/MotionControl.ino | 38 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/MotionControl/MotionControl.ino b/MotionControl/MotionControl.ino index fb2df2f..a4df7cc 100644 --- a/MotionControl/MotionControl.ino +++ b/MotionControl/MotionControl.ino @@ -4,8 +4,7 @@ const byte WheelLeftF = 2; const byte WheelLeftB = 3; const byte WheelRightF = 4; const byte WheelRightB = 5; -volatile int curr_speed_left; -volatile int curr_speed_right; +volatile int curr_speed; const int MAX = 255; const int TQUARTER = 191; @@ -20,6 +19,7 @@ enum States_enum {STOP, FORWARD, BACKWARD, LEFT, RIGHT, CIRCLE}; void pinClose(int pin); void pinOpen(int pin); +void stateControl(); void speedControl(); void setup() { @@ -90,6 +90,26 @@ void loop() { } void speedControl() +{ + stateControl(); + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + curr_speed = readString.toInt(); + Serial.println("Speed:"); + Serial.println(curr_speed); + readString=""; //empty for next input + + delay(2); //slow down a bit so motors have time to get inputs + } +} + +void stateControl() { while (Serial.available()) { char c = Serial.read(); //gets one byte from serial buffer @@ -123,20 +143,6 @@ void speedControl() delay(2); //slow down a bit so motors have time to get inputs } - - /*if (readString.length() >0) { - curr_speed_left = readStringLeft.toInt(); - Serial.println("Speed Left:"); - Serial.println(curr_speed_left); - - curr_speed_right = readStringRight.toInt(); - Serial.println("Speed Right:"); - Serial.println(curr_speed_right); - - readString=""; //empty for next input - - delay(2); //slow down a bit so motors have time to get inputs - }*/ } void pinOpen(int pin) -- GitLab From 93d6451f8c7ce3f46993f110fb75e9621db1d3fa Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Wed, 12 Feb 2020 18:50:45 -0500 Subject: [PATCH 09/28] Tests for ground sensor AnalogInRead Test helps correlate input analog voltage to Arduino's value. GroundSensor Test should lights up LED corresponding to the color sensed by the sensor. (UNTESTED) --- AnalogInReadTest/AnalogInReadTest.ino | 20 +++++ GroundSensorTest/GroundSensorTest.ino | 125 ++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 AnalogInReadTest/AnalogInReadTest.ino create mode 100644 GroundSensorTest/GroundSensorTest.ino diff --git a/AnalogInReadTest/AnalogInReadTest.ino b/AnalogInReadTest/AnalogInReadTest.ino new file mode 100644 index 0000000..f76175a --- /dev/null +++ b/AnalogInReadTest/AnalogInReadTest.ino @@ -0,0 +1,20 @@ +#include "Arduino.h" + +const byte analogPin = A0; + +// Need actual data for the value of voltage for each color +const int B_RANGE = 50; +const int R_RANGE = 100; +const int Y_RANGE = 150; + +void setup() { + Serial.begin(9600); + Serial.println("AnalogIn Read Test"); // so I can keep track of what is loaded +} + +void loop() { + int voltage = analogRead(analogPin); + Serial.println("Voltage Value: "); + Serial.println(voltage); + delay(1000); +} diff --git a/GroundSensorTest/GroundSensorTest.ino b/GroundSensorTest/GroundSensorTest.ino new file mode 100644 index 0000000..9f1a3ae --- /dev/null +++ b/GroundSensorTest/GroundSensorTest.ino @@ -0,0 +1,125 @@ +#include "Arduino.h" + +const byte ledRED = 2; +const byte ledBLUE = 3; +const byte ledYELLOW = 4; +const byte ledBLACK = 5; + +const byte sensorledRED = 6; +const byte sensorledBLUE = 7; + +const byte analogPin = A0; + +// Range of colors are partitions of 1023 +const int B_LOW = 300; +const int B_HIGH = 500; +const int R_LOW = 500; +const int R_HIGH = 800; + +String readString; + +volatile uint8_t state; +enum States_enum {OFF, ON}; + +void pinOn(int pin); +void allOff(); +void pinsOff(int pin, int pin2, int pin3); +void stateControl(); +void senseTape(); + +void setup() { + pinMode(ledRED, OUTPUT); + pinMode(ledBLUE, OUTPUT); + pinMode(ledYELLOW, OUTPUT); + pinMode(ledBLACK, OUTPUT); + + pinMode(sensorledRED, OUTPUT); + pinMode(sensorledBLUE, OUTPUT); + + Serial.begin(9600); + Serial.println("Ground Sensor Test"); // so I can keep track of what is loaded + Serial.println("Off"); + state = OFF; +} + +void loop() { + + switch (state) + { + case OFF: + stateControl(); + allOff(); + break; + + case ON: + stateControl(); + break; + } + +} + +void senseTape() +{ + int voltage = analogRead(analogPin); + bool is_black = voltage < B_LOW; + bool is_blue = (voltage >= B_LOW) and (voltage <= B_HIGH); + bool is_red = (voltage > R_LOW) and (voltage <= R_HIGH); + bool is_yellow = voltage > R_HIGH; + + if (is_black) { + pinsOff(ledBLUE, ledRED, ledYELLOW); + pinOn(ledBLACK); + } else if (is_blue) { + pinsOff(ledBLACK, ledRED, ledYELLOW); + pinOn(ledBLUE); + } else if (is_red) { + pinsOff(ledBLUE, ledBLACK, ledYELLOW); + pinOn(ledRED); + } else if (is_yellow) { + pinsOff(ledBLUE, ledRED, ledBLACK); + pinOn(ledYELLOW); + } else { + Serial.println("Invalid voltage detected! Check Code!"); + } +} + +void stateControl() +{ + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + + if (c == 'l'){ + Serial.println("Both LEDs on"); + state = ON; + } else if (c == 'o'){ + Serial.println("Off"); + state = OFF; + } + + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + readString=""; //empty for next input + delay(2); //slow down a bit so motors have time to get inputs + } +} + +void pinOn(int pin) +{ + digitalWrite(pin, HIGH); +} + +void allOff() +{ + pinsOff(ledRED,ledBLUE,ledYELLOW); + pinsOff(ledBLACK,sensorledRED,sensorledBLUE); +} + +void pinsOff(int pin1, int pin2, int pin3) +{ + digitalWrite(pin1, LOW); + digitalWrite(pin2, LOW); + digitalWrite(pin3, LOW); +} -- GitLab From 71082eb8c518540e8fc25b7431026f52afef1b37 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Thu, 13 Feb 2020 19:23:41 -0500 Subject: [PATCH 10/28] Make bot move based on color sensed Can control speed of movement (In Development) and task to do when certain color is sense ie blue = forward, red = turn right, etc. --- FollowTheLine/FollowTheLine.ino | 286 ++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 FollowTheLine/FollowTheLine.ino diff --git a/FollowTheLine/FollowTheLine.ino b/FollowTheLine/FollowTheLine.ino new file mode 100644 index 0000000..5105733 --- /dev/null +++ b/FollowTheLine/FollowTheLine.ino @@ -0,0 +1,286 @@ +#include "Arduino.h" + +const byte WheelLeftF = 2; +const byte WheelLeftB = 3; +const byte WheelRightF = 4; +const byte WheelRightB = 5; + +const byte sensorLeds = 6; + +const byte analogPin = A0; + +// Range of colors are partitions of 1023 +const int B_LOW = 300; +const int B_HIGH = 500; +const int R_LOW = 500; +const int R_HIGH = 800; + +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +/* Edit this for bot functionality + * stop = 's' + * forward = 'f' + * backward = 'b' + * right = 'r' + * left = 'l' + **********************************/ + const char RED_DO = 's'; + const char BLUE_DO = 'f'; + const char BLACK_DO = 's'; + const char YELLOW_DO = 'r'; + + const int FWD_SPD = QUARTER; + const int BCK_SPD = QUARTER; + const int LFT_SPD = QUARTER; + const int RGT_SPD = QUARTER; + const int RT_CW_SPD = QUARTER; + const int RT_CCW_SPD = QUARTER; +/* *********************************/ + +String readString; + +volatile uint8_t state; +enum States_enum {OFF, ON, STOP, FORWARD, BACKWARD, LEFT, RIGHT, CLOCKWISE, CCLOCKWISE}; + +void pinClose(byte pin); +void pinOpen(byte pin); +void allPinsOpen(); +void stateControl(char c); +void senseTape(); +void bootSequence(); +void driveMotor(byte pinOpen1, byte pinOpen2, byte pinClose1, byte pinClose2); + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + pinMode(WheelLeftF, OUTPUT); + pinMode(WheelLeftB, OUTPUT); + pinMode(WheelRightF, OUTPUT); + pinMode(WheelRightB, OUTPUT); + pinMode(sensorLeds, OUTPUT); + + Serial.begin(9600); + Serial.println("Follow the Line Color"); // so I can keep track of what is loaded + Serial.println("OFF"); + state = OFF; +} + +void loop() { + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + if (c = 'g') { + state = ON; + } + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + readString=""; //empty for next input + delay(2); //slow down a bit so motors have time to get inputs + } + + switch (state) + { + case OFF: + /* Starting state, nothing should be on */ + allPinsOpen(); + break; + + case ON: + bootSequence(); + senseTape(); + break; + + case STOP: + senseTape(); + allPinsOpen(); + break; + + case FORWARD: + senseTape(); + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + analogWrite(WheelLeftF, QUARTER); + analogWrite(WheelRightF, QUARTER); + break; + + case BACKWARD: + senseTape(); + pinOpen(WheelLeftF); + pinOpen(WheelRightF); + analogWrite(WheelLeftB, QUARTER); + analogWrite(WheelRightB, QUARTER); + break; + + case LEFT: + senseTape(); + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + analogWrite(WheelLeftF, ZERO); + analogWrite(WheelRightF, QUARTER); + break; + + case RIGHT: + senseTape(); + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + analogWrite(WheelLeftF, QUARTER); + analogWrite(WheelRightF, ZERO); + break; + + case CLOCKWISE: + senseTape(); + /* + pinOpen(WheelLeftB); + pinOpen(WheelRightF); + analogWrite(WheelLeftF, QUARTER); + analogWrite(WheelRightB, QUARTER); + */ + driveMotor(WheelLeftB, WheelRightF, WheelLeftF, WheelRightB); + break; + + case CCLOCKWISE: + senseTape(); + /* + pinOpen(WheelLeftF); + pinOpen(WheelRightB); + analogWrite(WheelLeftB, QUARTER); + analogWrite(WheelRightF, QUARTER); + */ + driveMotor(WheelLeftF, WheelRightB, WheelLeftB, WheelRightF); + break; + } +} + +void driveMotor(byte pinOpen1, byte pinOpen2, byte pinClose1, byte pinClose2) +{ + pinOpen(pinOpen1); + pinOpen(pinOpen2); + + switch (state) + { + case FORWARD: + analogWrite(WheelLeftF, FWD_SPD); + analogWrite(WheelRightF, FWD_SPD); + break; + + case BACKWARD: + analogWrite(WheelLeftB, BCK_SPD); + analogWrite(WheelRightB, BCK_SPD); + break; + + case LEFT: + analogWrite(WheelLeftF, ZERO); + analogWrite(WheelRightF, LFT_SPD); + break; + + case RIGHT: + analogWrite(WheelLeftF, RGT_SPD); + analogWrite(WheelRightF, ZERO); + break; + + case CLOCKWISE: + analogWrite(WheelLeftF, RT_CW_SPD); + analogWrite(WheelRightB, RT_CW_SPD); + break; + + case CCLOCKWISE: + analogWrite(WheelLeftB, RT_CCW_SPD); + analogWrite(WheelRightF, RT_CCW_SPD); + break; + } +} + +void bootSequence() +{ + Serial.println("Bot is on"); + Serial.println("Moving in "); + Serial.println("3"); + delay(1000); + Serial.println("2"); + delay(1000); + Serial.println("1"); + delay(1000); + pinClose(sensorLeds); +} + +void allPinsOpen() +{ + pinOpen(WheelLeftB); + pinOpen(WheelRightB); + pinOpen(WheelLeftF); + pinOpen(WheelRightF); + pinOpen(sensorLeds); +} + +void senseTape() +{ + int voltage = analogRead(analogPin); + bool is_black = voltage < B_LOW; + bool is_blue = (voltage >= B_LOW) and (voltage <= B_HIGH); + bool is_red = (voltage > R_LOW) and (voltage <= R_HIGH); + bool is_yellow = voltage > R_HIGH; + + char command; + if (is_black) { + Serial.println("Detected Black"); + command = BLACK_DO; + } else if (is_blue) { + Serial.println("Detected Blue"); + command = BLUE_DO; + } else if (is_red) { + Serial.println("Detected Red"); + command = RED_DO; + } else if (is_yellow) { + Serial.println("Detected Yellow"); + command = YELLOW_DO; + } else { + Serial.println("Invalid voltage detected! Check Code!"); + command = 's'; + } + + stateControl(command); +} + +void stateControl(char c) +{ + if (c == 'f'){ + Serial.println("Going Forward"); + state = FORWARD; + } else if (c == 'b'){ + Serial.println("Moving Backward"); + state = BACKWARD; + } else if (c == 'l'){ + Serial.println("Moving Left"); + state = LEFT; + } else if (c == 'r'){ + Serial.println("Moving Right"); + state = RIGHT; + } else if (c == 's'){ + Serial.println("Stop"); + state = STOP; + } else if (c == 'd'){ + Serial.println("Turn 360 Clockwise"); + state = CLOCKWISE; + } else if (c == 'a'){ + Serial.println("Turn 360 Counter Clockwise"); + state = CCLOCKWISE; + } + + delay(5); //slow loop to allow for change in state +} + +void pinOpen(byte pin) +{ + digitalWrite(pin, LOW); +} + +void pinClose(byte pin) +{ + digitalWrite(pin, HIGH); +} + -- GitLab From 4ab469cc4d8192161d613eb2fb4ced02cde0bb89 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:17:46 -0500 Subject: [PATCH 11/28] Trying to use .h and .cpp to remake FollowLine --- FollowLineUsingLib/FollowLineUsingLib.ino | 189 ++++++++++++++++++++++ FourPinControl/FourPinControl.cpp | 83 ++++++++++ FourPinControl/FourPinControl.h | 26 +++ GroundSensor/GroundSensor.cpp | 38 +++++ GroundSensor/GroundSensor.h | 25 +++ MotorControl/MotorControl.cpp | 97 +++++++++++ MotorControl/MotorControl.h | 40 +++++ 7 files changed, 498 insertions(+) create mode 100644 FollowLineUsingLib/FollowLineUsingLib.ino create mode 100644 FourPinControl/FourPinControl.cpp create mode 100644 FourPinControl/FourPinControl.h create mode 100644 GroundSensor/GroundSensor.cpp create mode 100644 GroundSensor/GroundSensor.h create mode 100644 MotorControl/MotorControl.cpp create mode 100644 MotorControl/MotorControl.h diff --git a/FollowLineUsingLib/FollowLineUsingLib.ino b/FollowLineUsingLib/FollowLineUsingLib.ino new file mode 100644 index 0000000..95592fd --- /dev/null +++ b/FollowLineUsingLib/FollowLineUsingLib.ino @@ -0,0 +1,189 @@ +#include +#include +#include "Arduino.h" + +volatile uint8_t state; +enum States_enum {OFF, ON, STOP, FORWARD, BACKWARD, LEFT, RIGHT, CLOCKWISE, CCLOCKWISE, SEARCH}; + +volatile uint8_t cmd; +enum Movements_enum {halt, forward, backward, left, right, rotate_cw, rotate_ccw, search}; + +/* Pin to turn on/off ground sensor */ +const byte sensorLeds = 6; +/* Pin for analog input from ground sensor */ +const byte analogPin = A0; + +/* Range of colors are partitions of 1023 */ +const int B_LOW = 300; +const int B_HIGH = 500; +const int R_LOW = 500; +const int R_HIGH = 800; + +/* Edit this for bot functionality + * stop = 's' + * forward = 'f' + * backward = 'b' + * right = 'r' + * left = 'l' + */ + const char RED_DO = right; + const char BLUE_DO = forward; + const char BLACK_DO = search; + const char YELLOW_DO = halt; + + /* Set up the ground sensor */ +Bounds bound = {B_LOW, B_HIGH, R_LOW, R_HIGH}; +Instructions instr = {RED_DO, BLUE_DO, BLACK_DO, YELLOW_DO}; +GroundSensor tapeSensor(sensorLeds, analogPin, bound, instr); + + +/* Pins for wheel control */ +const byte WheelLeftF = 2; +const byte WheelLeftB = 3; +const byte WheelRightF = 4; +const byte WheelRightB = 5; + +/* Duty Cycle constants */ +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +/* Control speed of each state*/ +const int FWD_SPD = QUARTER; +const int BCK_SPD = QUARTER; +const int LFT_SPD = QUARTER; +const int RGT_SPD = QUARTER; +const int RT_CW_SPD = QUARTER; +const int RT_CCW_SPD = QUARTER; + +/* Control the motor */ +Wheels w = {WheelLeftF, WheelLeftB, WheelRightF, WheelRightB}; +Speeds s = {FWD_SPD, BCK_SPD, LFT_SPD, RGT_SPD, RT_CW_SPD, RT_CCW_SPD}; +MotorControl motors(w, s); + +void stateControl(uint8_t c); +void bootSequence(); + +void setup() { + attachInterrupt(digitalPinToInterrupt(analogPin), detect, CHANGE); + Serial.begin(9600); + Serial.println("Follow the Line Color"); // so I can keep track of what is loaded + Serial.println("Bot is OFF"); + state = OFF; + Serial.println("Turn it on? Y/N"); +} + +void loop() { + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + if ((c = 'Y') || (c = 'y')) { + state = ON; + } + } + + switch (state) + { + case OFF: + /* Starting state, wait for user to turn on*/ + break; + + case ON: + bootSequence(); + break; + + case STOP: + motors.stop(); // Stop right away + break; + + case FORWARD: + stateControl(cmd); + motors.forward(); + break; + + case BACKWARD: + stateControl(cmd); + motors.backward(); + break; + + case LEFT: + stateControl(cmd); + motors.left(); + break; + + case RIGHT: + stateControl(cmd); + motors.right(); + break; + + case CLOCKWISE: + stateControl(cmd); + motors.cw(); + break; + + case CCLOCKWISE: + stateControl(cmd); + motors.ccw(); + break; + + case SEARCH: + stateControl(cmd); + motors.ccw(); + delay(1000); + motors.cw(); + delay(3000); + break; + } +} + +void bootSequence() +{ + Serial.println("Bot is on"); + Serial.println("Moving in "); + Serial.println("3"); + delay(1000); + Serial.println("2"); + delay(1000); + Serial.println("1"); + delay(1000); + digitalWrite(sensorLeds, HIGH); + tapeSensor.senseColor(&cmd); +} + +void stateControl(uint8_t c) +{ + if (c == forward){ + Serial.println("Going Forward"); + state = FORWARD; + } else if (c == backward){ + Serial.println("Moving Backward"); + state = BACKWARD; + } else if (c == left){ + Serial.println("Moving Left"); + state = LEFT; + } else if (c == right){ + Serial.println("Moving Right"); + state = RIGHT; + } else if (c == halt){ + Serial.println("Stop"); + state = STOP; + } else if (c == rotate_cw){ + Serial.println("Turn 360 Clockwise"); + state = CLOCKWISE; + } else if (c == rotate_ccw){ + Serial.println("Turn 360 Counter Clockwise"); + state = CCLOCKWISE; + } else if (c == search){ + Serial.println("Searching for path"); + state = SEARCH; + } + + delay(5); //slow loop to allow for change in state +} + +void detect() +{ + tapeSensor.senseColor(&cmd); +} + diff --git a/FourPinControl/FourPinControl.cpp b/FourPinControl/FourPinControl.cpp new file mode 100644 index 0000000..322843e --- /dev/null +++ b/FourPinControl/FourPinControl.cpp @@ -0,0 +1,83 @@ +#include "Arduino.h" +#include "FourPinControl.h" + + +FourPinControl::FourPinControl() +{ + _p1 = _p2 = _p3 = _p4 = 0; +} + +void FourPinControl::newOutputs(int p1, int p2, int p3, int p4) +{ + // Set pins to output mode, remember them + pinMode(p1, OUTPUT); + pinMode(p2, OUTPUT); + pinMode(p3, OUTPUT); + pinMode(p4, OUTPUT); + _p1 = p1; + _p2 = p2; + _p3 = p3; + _p4 = p4; +} + +/* Opening Pins Section*/ +// Open a pin +void FourPinControl::pinOpen(int p) +{ + digitalWrite(p, LOW); +} + +// Open two pins +void FourPinControl::twoPinsOpen(int p1, int p2) +{ + digitalWrite(p1, LOW); + digitalWrite(p2, LOW); +} + +// Open three pins +void FourPinControl::threePinsOpen(int p1, int p2, int p3) +{ + digitalWrite(p1, LOW); + digitalWrite(p2, LOW); + digitalWrite(p3, LOW); +} + +// Open all four pins +void FourPinControl::allPinsOpen() +{ + digitalWrite(_p1, LOW); + digitalWrite(_p2, LOW); + digitalWrite(_p3, LOW); + digitalWrite(_p4, LOW); +} + +/* Closing Pins Section*/ +// Close a pin +void FourPinControl::pinClose(int p) +{ + digitalWrite(p, HIGH); +} + +// Close two pins +void FourPinControl::twoPinsClose(int p1, int p2) +{ + digitalWrite(p1, HIGH); + digitalWrite(p2, HIGH); +} + +// Close three pins +void FourPinControl:: threePinsClose(int p1, int p2, int p3) +{ + digitalWrite(p1, HIGH); + digitalWrite(p2, HIGH); + digitalWrite(p3, HIGH); +} + +// Close all four pins +void FourPinControl::allPinsClose() +{ + digitalWrite(_p1, HIGH); + digitalWrite(_p2, HIGH); + digitalWrite(_p3, HIGH); + digitalWrite(_p4, HIGH); +} \ No newline at end of file diff --git a/FourPinControl/FourPinControl.h b/FourPinControl/FourPinControl.h new file mode 100644 index 0000000..db65163 --- /dev/null +++ b/FourPinControl/FourPinControl.h @@ -0,0 +1,26 @@ +#ifndef FourPinControl_h +#define FourPinControl_h + +#include "Arduino.h" + +class FourPinControl +{ + public: + FourPinControl(); + void newOutputs(int p1, int p2, int p3, int p4); + + void pinOpen(int p); + void twoPinsOpen(int p1, int p2); + void threePinsOpen(int p1, int p2, int p3); + void allPinsOpen(); + + void pinClose(int p); + void twoPinsClose(int p1, int p2); + void threePinsClose(int p1, int p2, int p3); + void allPinsClose(); + + private: + int _p1, _p2, _p3, _p4; +}; + +#endif diff --git a/GroundSensor/GroundSensor.cpp b/GroundSensor/GroundSensor.cpp new file mode 100644 index 0000000..278462c --- /dev/null +++ b/GroundSensor/GroundSensor.cpp @@ -0,0 +1,38 @@ +#include "Arduino.h" +#include "GroundSensor.h" + +GroundSensor::GroundSensor(int sensorPin, int analogPin, + Bounds b, Instructions i) +{ + pinMode(sensorPin, OUTPUT); + _sensorPin = sensorPin; + _analogPin = analogPin; + _bound = b; + _inst = i; +} + +void GroundSensor::senseColor(volatile uint8_t *command) +{ + int voltage = analogRead(_analogPin); + bool is_black = voltage < _bound.b_low; + bool is_blue = (voltage >= _bound.b_low) and (voltage <= _bound.b_high); + bool is_red = (voltage > _bound.r_low) and (voltage <= _bound.r_high); + bool is_yellow = voltage > _bound.r_high; + + if (is_black) { + Serial.println("Detected Black"); + *command = _inst.black_do; + } else if (is_blue) { + Serial.println("Detected Blue"); + *command = _inst.blue_do; + } else if (is_red) { + Serial.println("Detected Red"); + *command = _inst.red_do; + } else if (is_yellow) { + Serial.println("Detected Yellow"); + *command = _inst.yellow_do; + } else { + Serial.println("Invalid voltage detected! Check Code!"); + *command = 's'; + } +} diff --git a/GroundSensor/GroundSensor.h b/GroundSensor/GroundSensor.h new file mode 100644 index 0000000..3e5710e --- /dev/null +++ b/GroundSensor/GroundSensor.h @@ -0,0 +1,25 @@ +#ifndef GroundSensor_h +#define GroundSensor_h + +#include "Arduino.h" + +struct Bounds { + int b_low, b_high, r_low, r_high; +}; + +struct Instructions { + uint8_t red_do, blue_do, black_do, yellow_do; +}; + +class GroundSensor +{ + public: + GroundSensor(int sensorPin, int analogPin, Bounds b, Instructions i); + void senseColor(volatile uint8_t *command); + private: + int _sensorPin, _analogPin; + Bounds _bound; + Instructions _inst; +}; + +#endif diff --git a/MotorControl/MotorControl.cpp b/MotorControl/MotorControl.cpp new file mode 100644 index 0000000..26ab536 --- /dev/null +++ b/MotorControl/MotorControl.cpp @@ -0,0 +1,97 @@ +#include "Arduino.h" +#include "MotorControl.h" + +/* Duty Cycle constants */ +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +enum Movements_enum {FORWARD, BACK, LEFT, RIGHT, CW, CCW}; + + +MotorControl::MotorControl(Wheels w, Speeds s) +{ + _pinControl.newOutputs(w.leftF, w.leftB, w.rightF, w.rightB); + _w = w; + _s = s; +} + +void MotorControl::stop() +{ + _pinControl.allPinsOpen(); +} + +void MotorControl::forward() +{ + _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + driveMotor(FORWARD); +} + +void MotorControl::backward() +{ + _m = {_w.leftF, _w.rightF, _w.leftB, _w.rightB}; + driveMotor(BACK); +} + +void MotorControl::left() +{ + _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + driveMotor(LEFT); +} +void MotorControl::right() +{ + _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + driveMotor(RIGHT); +} + +void MotorControl::cw() +{ + _m = {_w.leftB, _w.rightF, _w.leftF, _w.rightB}; + driveMotor(CW); +} + +void MotorControl::ccw() +{ + _m = {_w.leftB, _w.rightF, _w.leftB, _w.rightF}; + driveMotor(CCW); +} + +void MotorControl::driveMotor(int movement) +{ + _pinControl.twoPinsOpen(_m.w1, _m.w2); + + switch (movement) + { + case FORWARD: + analogWrite(_m.w3, _s.forward); + analogWrite(_m.w4, _s.forward); + break; + + case BACK: + analogWrite(_m.w3, _s.backward); + analogWrite(_m.w4, _s.left); + break; + + case LEFT: + analogWrite(_m.w3, ZERO); + analogWrite(_m.w4, _s.left); + break; + + case RIGHT: + analogWrite(_m.w3, _s.right); + analogWrite(_m.w4, ZERO); + break; + + case CW: + analogWrite(_m.w3, _s.cw); + analogWrite(_m.w4, _s.cw); + break; + + case CCW: + analogWrite(_m.w3, _s.ccw); + analogWrite(_m.w4, _s.ccw); + break; + } +} diff --git a/MotorControl/MotorControl.h b/MotorControl/MotorControl.h new file mode 100644 index 0000000..c1d881b --- /dev/null +++ b/MotorControl/MotorControl.h @@ -0,0 +1,40 @@ +#ifndef MotorControl_h +#define MotorControl_h + +#include "Arduino.h" +#include "FourPinControl.h" + +struct Wheels { + int leftF, leftB, rightF, rightB; +}; + +struct Speeds { + int forward, backward, left, right, cw, ccw; +}; + +class MotorControl +{ + public: + MotorControl(Wheels w, Speeds s); + void stop(); + void forward(); + void backward(); + void left(); + void right(); + void cw(); + void ccw(); + + private: + struct Movement { + int w1, w2, w3, w4; + }; + + Wheels _w; + Speeds _s; + Movement _m; + FourPinControl _pinControl; + + void driveMotor(int movement); +}; + +#endif -- GitLab From 26ec42642c59c94dc30d5c4af1ff2aad8a608bdb Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:20:43 -0500 Subject: [PATCH 12/28] Libraries I wrote for FollowTheLineUsingLib --- libraries/FourPinControl/FourPinControl.cpp | 83 ++++++++++++++++++ libraries/FourPinControl/FourPinControl.h | 26 ++++++ libraries/GroundSensor/GroundSensor.cpp | 38 ++++++++ libraries/GroundSensor/GroundSensor.h | 25 ++++++ libraries/MotorControl/MotorControl.cpp | 97 +++++++++++++++++++++ libraries/MotorControl/MotorControl.h | 40 +++++++++ libraries/PinControl/PinControl.cpp | 64 ++++++++++++++ libraries/PinControl/PinControl.h | 24 +++++ libraries/readme.txt | 1 + 9 files changed, 398 insertions(+) create mode 100644 libraries/FourPinControl/FourPinControl.cpp create mode 100644 libraries/FourPinControl/FourPinControl.h create mode 100644 libraries/GroundSensor/GroundSensor.cpp create mode 100644 libraries/GroundSensor/GroundSensor.h create mode 100644 libraries/MotorControl/MotorControl.cpp create mode 100644 libraries/MotorControl/MotorControl.h create mode 100644 libraries/PinControl/PinControl.cpp create mode 100644 libraries/PinControl/PinControl.h create mode 100644 libraries/readme.txt diff --git a/libraries/FourPinControl/FourPinControl.cpp b/libraries/FourPinControl/FourPinControl.cpp new file mode 100644 index 0000000..322843e --- /dev/null +++ b/libraries/FourPinControl/FourPinControl.cpp @@ -0,0 +1,83 @@ +#include "Arduino.h" +#include "FourPinControl.h" + + +FourPinControl::FourPinControl() +{ + _p1 = _p2 = _p3 = _p4 = 0; +} + +void FourPinControl::newOutputs(int p1, int p2, int p3, int p4) +{ + // Set pins to output mode, remember them + pinMode(p1, OUTPUT); + pinMode(p2, OUTPUT); + pinMode(p3, OUTPUT); + pinMode(p4, OUTPUT); + _p1 = p1; + _p2 = p2; + _p3 = p3; + _p4 = p4; +} + +/* Opening Pins Section*/ +// Open a pin +void FourPinControl::pinOpen(int p) +{ + digitalWrite(p, LOW); +} + +// Open two pins +void FourPinControl::twoPinsOpen(int p1, int p2) +{ + digitalWrite(p1, LOW); + digitalWrite(p2, LOW); +} + +// Open three pins +void FourPinControl::threePinsOpen(int p1, int p2, int p3) +{ + digitalWrite(p1, LOW); + digitalWrite(p2, LOW); + digitalWrite(p3, LOW); +} + +// Open all four pins +void FourPinControl::allPinsOpen() +{ + digitalWrite(_p1, LOW); + digitalWrite(_p2, LOW); + digitalWrite(_p3, LOW); + digitalWrite(_p4, LOW); +} + +/* Closing Pins Section*/ +// Close a pin +void FourPinControl::pinClose(int p) +{ + digitalWrite(p, HIGH); +} + +// Close two pins +void FourPinControl::twoPinsClose(int p1, int p2) +{ + digitalWrite(p1, HIGH); + digitalWrite(p2, HIGH); +} + +// Close three pins +void FourPinControl:: threePinsClose(int p1, int p2, int p3) +{ + digitalWrite(p1, HIGH); + digitalWrite(p2, HIGH); + digitalWrite(p3, HIGH); +} + +// Close all four pins +void FourPinControl::allPinsClose() +{ + digitalWrite(_p1, HIGH); + digitalWrite(_p2, HIGH); + digitalWrite(_p3, HIGH); + digitalWrite(_p4, HIGH); +} \ No newline at end of file diff --git a/libraries/FourPinControl/FourPinControl.h b/libraries/FourPinControl/FourPinControl.h new file mode 100644 index 0000000..db65163 --- /dev/null +++ b/libraries/FourPinControl/FourPinControl.h @@ -0,0 +1,26 @@ +#ifndef FourPinControl_h +#define FourPinControl_h + +#include "Arduino.h" + +class FourPinControl +{ + public: + FourPinControl(); + void newOutputs(int p1, int p2, int p3, int p4); + + void pinOpen(int p); + void twoPinsOpen(int p1, int p2); + void threePinsOpen(int p1, int p2, int p3); + void allPinsOpen(); + + void pinClose(int p); + void twoPinsClose(int p1, int p2); + void threePinsClose(int p1, int p2, int p3); + void allPinsClose(); + + private: + int _p1, _p2, _p3, _p4; +}; + +#endif diff --git a/libraries/GroundSensor/GroundSensor.cpp b/libraries/GroundSensor/GroundSensor.cpp new file mode 100644 index 0000000..278462c --- /dev/null +++ b/libraries/GroundSensor/GroundSensor.cpp @@ -0,0 +1,38 @@ +#include "Arduino.h" +#include "GroundSensor.h" + +GroundSensor::GroundSensor(int sensorPin, int analogPin, + Bounds b, Instructions i) +{ + pinMode(sensorPin, OUTPUT); + _sensorPin = sensorPin; + _analogPin = analogPin; + _bound = b; + _inst = i; +} + +void GroundSensor::senseColor(volatile uint8_t *command) +{ + int voltage = analogRead(_analogPin); + bool is_black = voltage < _bound.b_low; + bool is_blue = (voltage >= _bound.b_low) and (voltage <= _bound.b_high); + bool is_red = (voltage > _bound.r_low) and (voltage <= _bound.r_high); + bool is_yellow = voltage > _bound.r_high; + + if (is_black) { + Serial.println("Detected Black"); + *command = _inst.black_do; + } else if (is_blue) { + Serial.println("Detected Blue"); + *command = _inst.blue_do; + } else if (is_red) { + Serial.println("Detected Red"); + *command = _inst.red_do; + } else if (is_yellow) { + Serial.println("Detected Yellow"); + *command = _inst.yellow_do; + } else { + Serial.println("Invalid voltage detected! Check Code!"); + *command = 's'; + } +} diff --git a/libraries/GroundSensor/GroundSensor.h b/libraries/GroundSensor/GroundSensor.h new file mode 100644 index 0000000..3e5710e --- /dev/null +++ b/libraries/GroundSensor/GroundSensor.h @@ -0,0 +1,25 @@ +#ifndef GroundSensor_h +#define GroundSensor_h + +#include "Arduino.h" + +struct Bounds { + int b_low, b_high, r_low, r_high; +}; + +struct Instructions { + uint8_t red_do, blue_do, black_do, yellow_do; +}; + +class GroundSensor +{ + public: + GroundSensor(int sensorPin, int analogPin, Bounds b, Instructions i); + void senseColor(volatile uint8_t *command); + private: + int _sensorPin, _analogPin; + Bounds _bound; + Instructions _inst; +}; + +#endif diff --git a/libraries/MotorControl/MotorControl.cpp b/libraries/MotorControl/MotorControl.cpp new file mode 100644 index 0000000..26ab536 --- /dev/null +++ b/libraries/MotorControl/MotorControl.cpp @@ -0,0 +1,97 @@ +#include "Arduino.h" +#include "MotorControl.h" + +/* Duty Cycle constants */ +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +enum Movements_enum {FORWARD, BACK, LEFT, RIGHT, CW, CCW}; + + +MotorControl::MotorControl(Wheels w, Speeds s) +{ + _pinControl.newOutputs(w.leftF, w.leftB, w.rightF, w.rightB); + _w = w; + _s = s; +} + +void MotorControl::stop() +{ + _pinControl.allPinsOpen(); +} + +void MotorControl::forward() +{ + _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + driveMotor(FORWARD); +} + +void MotorControl::backward() +{ + _m = {_w.leftF, _w.rightF, _w.leftB, _w.rightB}; + driveMotor(BACK); +} + +void MotorControl::left() +{ + _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + driveMotor(LEFT); +} +void MotorControl::right() +{ + _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + driveMotor(RIGHT); +} + +void MotorControl::cw() +{ + _m = {_w.leftB, _w.rightF, _w.leftF, _w.rightB}; + driveMotor(CW); +} + +void MotorControl::ccw() +{ + _m = {_w.leftB, _w.rightF, _w.leftB, _w.rightF}; + driveMotor(CCW); +} + +void MotorControl::driveMotor(int movement) +{ + _pinControl.twoPinsOpen(_m.w1, _m.w2); + + switch (movement) + { + case FORWARD: + analogWrite(_m.w3, _s.forward); + analogWrite(_m.w4, _s.forward); + break; + + case BACK: + analogWrite(_m.w3, _s.backward); + analogWrite(_m.w4, _s.left); + break; + + case LEFT: + analogWrite(_m.w3, ZERO); + analogWrite(_m.w4, _s.left); + break; + + case RIGHT: + analogWrite(_m.w3, _s.right); + analogWrite(_m.w4, ZERO); + break; + + case CW: + analogWrite(_m.w3, _s.cw); + analogWrite(_m.w4, _s.cw); + break; + + case CCW: + analogWrite(_m.w3, _s.ccw); + analogWrite(_m.w4, _s.ccw); + break; + } +} diff --git a/libraries/MotorControl/MotorControl.h b/libraries/MotorControl/MotorControl.h new file mode 100644 index 0000000..c1d881b --- /dev/null +++ b/libraries/MotorControl/MotorControl.h @@ -0,0 +1,40 @@ +#ifndef MotorControl_h +#define MotorControl_h + +#include "Arduino.h" +#include "FourPinControl.h" + +struct Wheels { + int leftF, leftB, rightF, rightB; +}; + +struct Speeds { + int forward, backward, left, right, cw, ccw; +}; + +class MotorControl +{ + public: + MotorControl(Wheels w, Speeds s); + void stop(); + void forward(); + void backward(); + void left(); + void right(); + void cw(); + void ccw(); + + private: + struct Movement { + int w1, w2, w3, w4; + }; + + Wheels _w; + Speeds _s; + Movement _m; + FourPinControl _pinControl; + + void driveMotor(int movement); +}; + +#endif diff --git a/libraries/PinControl/PinControl.cpp b/libraries/PinControl/PinControl.cpp new file mode 100644 index 0000000..76f51cc --- /dev/null +++ b/libraries/PinControl/PinControl.cpp @@ -0,0 +1,64 @@ +#include "Arduino.h" +#include "PinControl.h" + +PinControl::PinControl() +{ + // Don't do anything here +} + +void pinOpen(int p) +{ + digitalWrite(p, LOW); +} + + +void twoPinOpen(int p1, int p2) +{ + digitalWrite(p1, LOW); + digitalWrite(p2, LOW); +} + +void threePinOpen(int p1, int p2, int p3) +{ + digitalWrite(p1, LOW); + digitalWrite(p2, LOW); + digitalWrite(p3, LOW); +} + +void fourPinOpen(int p1, int p2, int p3, int p4) +{ + digitalWrite(p1, LOW); + digitalWrite(p2, LOW); + digitalWrite(p3, LOW); + digitalWrite(p4, LOW); +} + +void fourPinsOpen() +{ + +} + +void pinClose(int p) +{ + digitalWrite(p, HIGH); +} + +void twoPinClose(int p1, int p2) +{ + digitalWrite(p1, HIGH); + digitalWrite(p2, HIGH); +} +void threePinClose(int p1, int p2, int p3) +{ + digitalWrite(p1, HIGH); + digitalWrite(p2, HIGH); + digitalWrite(p3, HIGH); +} + +void fourPinClose(int p1, int p2, int p3, int p4) +{ + digitalWrite(p1, HIGH); + digitalWrite(p2, HIGH); + digitalWrite(p3, HIGH); + digitalWrite(p4, HIGH); +} \ No newline at end of file diff --git a/libraries/PinControl/PinControl.h b/libraries/PinControl/PinControl.h new file mode 100644 index 0000000..d69d4b4 --- /dev/null +++ b/libraries/PinControl/PinControl.h @@ -0,0 +1,24 @@ +#ifndef PinControl_h +#define PinControl_h + +#include "Arduino.h" + +class Morse +{ + public: + PinControl(int p1, int p2, int p3, int p4); + + void pinOpen(int p); + void twoPinOpen(int p1, int p2); + void threePinOpen(int p1, int p2, int p3); + void fourPinOpen(int p1, int p2, int p3, int p4); + + void pinClose(int p); + void twoPinClose(int p1, int p2); + void threePinClose(int p1, int p2, int p3); + void fourPinClose(int p1, int p2, int p3, int p4); + + private: +}; + +#endif diff --git a/libraries/readme.txt b/libraries/readme.txt new file mode 100644 index 0000000..96ce674 --- /dev/null +++ b/libraries/readme.txt @@ -0,0 +1 @@ +For information on installing libraries, see: http://www.arduino.cc/en/Guide/Libraries -- GitLab From 32cc83cab6e2bd2dbc3c9cb7be280b0a93a878a9 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:21:41 -0500 Subject: [PATCH 13/28] In libraries --- GroundSensor/GroundSensor.cpp | 38 ----------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 GroundSensor/GroundSensor.cpp diff --git a/GroundSensor/GroundSensor.cpp b/GroundSensor/GroundSensor.cpp deleted file mode 100644 index 278462c..0000000 --- a/GroundSensor/GroundSensor.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "Arduino.h" -#include "GroundSensor.h" - -GroundSensor::GroundSensor(int sensorPin, int analogPin, - Bounds b, Instructions i) -{ - pinMode(sensorPin, OUTPUT); - _sensorPin = sensorPin; - _analogPin = analogPin; - _bound = b; - _inst = i; -} - -void GroundSensor::senseColor(volatile uint8_t *command) -{ - int voltage = analogRead(_analogPin); - bool is_black = voltage < _bound.b_low; - bool is_blue = (voltage >= _bound.b_low) and (voltage <= _bound.b_high); - bool is_red = (voltage > _bound.r_low) and (voltage <= _bound.r_high); - bool is_yellow = voltage > _bound.r_high; - - if (is_black) { - Serial.println("Detected Black"); - *command = _inst.black_do; - } else if (is_blue) { - Serial.println("Detected Blue"); - *command = _inst.blue_do; - } else if (is_red) { - Serial.println("Detected Red"); - *command = _inst.red_do; - } else if (is_yellow) { - Serial.println("Detected Yellow"); - *command = _inst.yellow_do; - } else { - Serial.println("Invalid voltage detected! Check Code!"); - *command = 's'; - } -} -- GitLab From 81f340d9105b0eeafe19ff895b2df871cf29b356 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:21:51 -0500 Subject: [PATCH 14/28] In libraries --- GroundSensor/GroundSensor.h | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 GroundSensor/GroundSensor.h diff --git a/GroundSensor/GroundSensor.h b/GroundSensor/GroundSensor.h deleted file mode 100644 index 3e5710e..0000000 --- a/GroundSensor/GroundSensor.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef GroundSensor_h -#define GroundSensor_h - -#include "Arduino.h" - -struct Bounds { - int b_low, b_high, r_low, r_high; -}; - -struct Instructions { - uint8_t red_do, blue_do, black_do, yellow_do; -}; - -class GroundSensor -{ - public: - GroundSensor(int sensorPin, int analogPin, Bounds b, Instructions i); - void senseColor(volatile uint8_t *command); - private: - int _sensorPin, _analogPin; - Bounds _bound; - Instructions _inst; -}; - -#endif -- GitLab From 7e0be5166b52df181c2e463c5396ef1e772cd8bc Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:22:35 -0500 Subject: [PATCH 15/28] In libraries --- MotorControl/MotorControl.cpp | 97 ----------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 MotorControl/MotorControl.cpp diff --git a/MotorControl/MotorControl.cpp b/MotorControl/MotorControl.cpp deleted file mode 100644 index 26ab536..0000000 --- a/MotorControl/MotorControl.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "Arduino.h" -#include "MotorControl.h" - -/* Duty Cycle constants */ -const int MAX = 255; -const int TQUARTER = 191; -const int HALF = 127; -const int QUARTER = 64; -const int ZERO = 0; - -enum Movements_enum {FORWARD, BACK, LEFT, RIGHT, CW, CCW}; - - -MotorControl::MotorControl(Wheels w, Speeds s) -{ - _pinControl.newOutputs(w.leftF, w.leftB, w.rightF, w.rightB); - _w = w; - _s = s; -} - -void MotorControl::stop() -{ - _pinControl.allPinsOpen(); -} - -void MotorControl::forward() -{ - _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; - driveMotor(FORWARD); -} - -void MotorControl::backward() -{ - _m = {_w.leftF, _w.rightF, _w.leftB, _w.rightB}; - driveMotor(BACK); -} - -void MotorControl::left() -{ - _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; - driveMotor(LEFT); -} -void MotorControl::right() -{ - _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; - driveMotor(RIGHT); -} - -void MotorControl::cw() -{ - _m = {_w.leftB, _w.rightF, _w.leftF, _w.rightB}; - driveMotor(CW); -} - -void MotorControl::ccw() -{ - _m = {_w.leftB, _w.rightF, _w.leftB, _w.rightF}; - driveMotor(CCW); -} - -void MotorControl::driveMotor(int movement) -{ - _pinControl.twoPinsOpen(_m.w1, _m.w2); - - switch (movement) - { - case FORWARD: - analogWrite(_m.w3, _s.forward); - analogWrite(_m.w4, _s.forward); - break; - - case BACK: - analogWrite(_m.w3, _s.backward); - analogWrite(_m.w4, _s.left); - break; - - case LEFT: - analogWrite(_m.w3, ZERO); - analogWrite(_m.w4, _s.left); - break; - - case RIGHT: - analogWrite(_m.w3, _s.right); - analogWrite(_m.w4, ZERO); - break; - - case CW: - analogWrite(_m.w3, _s.cw); - analogWrite(_m.w4, _s.cw); - break; - - case CCW: - analogWrite(_m.w3, _s.ccw); - analogWrite(_m.w4, _s.ccw); - break; - } -} -- GitLab From f4757ba4da1e2e00682c6c7c687ada1dfbdd9bc6 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:22:45 -0500 Subject: [PATCH 16/28] In libraries --- MotorControl/MotorControl.h | 40 ------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 MotorControl/MotorControl.h diff --git a/MotorControl/MotorControl.h b/MotorControl/MotorControl.h deleted file mode 100644 index c1d881b..0000000 --- a/MotorControl/MotorControl.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MotorControl_h -#define MotorControl_h - -#include "Arduino.h" -#include "FourPinControl.h" - -struct Wheels { - int leftF, leftB, rightF, rightB; -}; - -struct Speeds { - int forward, backward, left, right, cw, ccw; -}; - -class MotorControl -{ - public: - MotorControl(Wheels w, Speeds s); - void stop(); - void forward(); - void backward(); - void left(); - void right(); - void cw(); - void ccw(); - - private: - struct Movement { - int w1, w2, w3, w4; - }; - - Wheels _w; - Speeds _s; - Movement _m; - FourPinControl _pinControl; - - void driveMotor(int movement); -}; - -#endif -- GitLab From 00f6b02ea571d53d1ca7d717581aad975852f6eb Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:22:58 -0500 Subject: [PATCH 17/28] In libraries --- FourPinControl/FourPinControl.cpp | 83 ------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 FourPinControl/FourPinControl.cpp diff --git a/FourPinControl/FourPinControl.cpp b/FourPinControl/FourPinControl.cpp deleted file mode 100644 index 322843e..0000000 --- a/FourPinControl/FourPinControl.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "Arduino.h" -#include "FourPinControl.h" - - -FourPinControl::FourPinControl() -{ - _p1 = _p2 = _p3 = _p4 = 0; -} - -void FourPinControl::newOutputs(int p1, int p2, int p3, int p4) -{ - // Set pins to output mode, remember them - pinMode(p1, OUTPUT); - pinMode(p2, OUTPUT); - pinMode(p3, OUTPUT); - pinMode(p4, OUTPUT); - _p1 = p1; - _p2 = p2; - _p3 = p3; - _p4 = p4; -} - -/* Opening Pins Section*/ -// Open a pin -void FourPinControl::pinOpen(int p) -{ - digitalWrite(p, LOW); -} - -// Open two pins -void FourPinControl::twoPinsOpen(int p1, int p2) -{ - digitalWrite(p1, LOW); - digitalWrite(p2, LOW); -} - -// Open three pins -void FourPinControl::threePinsOpen(int p1, int p2, int p3) -{ - digitalWrite(p1, LOW); - digitalWrite(p2, LOW); - digitalWrite(p3, LOW); -} - -// Open all four pins -void FourPinControl::allPinsOpen() -{ - digitalWrite(_p1, LOW); - digitalWrite(_p2, LOW); - digitalWrite(_p3, LOW); - digitalWrite(_p4, LOW); -} - -/* Closing Pins Section*/ -// Close a pin -void FourPinControl::pinClose(int p) -{ - digitalWrite(p, HIGH); -} - -// Close two pins -void FourPinControl::twoPinsClose(int p1, int p2) -{ - digitalWrite(p1, HIGH); - digitalWrite(p2, HIGH); -} - -// Close three pins -void FourPinControl:: threePinsClose(int p1, int p2, int p3) -{ - digitalWrite(p1, HIGH); - digitalWrite(p2, HIGH); - digitalWrite(p3, HIGH); -} - -// Close all four pins -void FourPinControl::allPinsClose() -{ - digitalWrite(_p1, HIGH); - digitalWrite(_p2, HIGH); - digitalWrite(_p3, HIGH); - digitalWrite(_p4, HIGH); -} \ No newline at end of file -- GitLab From 9c179f1d48aaf36524677d3a7fd26e78917b888b Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:23:06 -0500 Subject: [PATCH 18/28] In libraries --- FourPinControl/FourPinControl.h | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 FourPinControl/FourPinControl.h diff --git a/FourPinControl/FourPinControl.h b/FourPinControl/FourPinControl.h deleted file mode 100644 index db65163..0000000 --- a/FourPinControl/FourPinControl.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef FourPinControl_h -#define FourPinControl_h - -#include "Arduino.h" - -class FourPinControl -{ - public: - FourPinControl(); - void newOutputs(int p1, int p2, int p3, int p4); - - void pinOpen(int p); - void twoPinsOpen(int p1, int p2); - void threePinsOpen(int p1, int p2, int p3); - void allPinsOpen(); - - void pinClose(int p); - void twoPinsClose(int p1, int p2); - void threePinsClose(int p1, int p2, int p3); - void allPinsClose(); - - private: - int _p1, _p2, _p3, _p4; -}; - -#endif -- GitLab From 9f6ba801504c0f9eacd91d38ca203c22957bc725 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:26:57 -0500 Subject: [PATCH 19/28] Bot follows a line (uncalibrate wheels) --- FollowTheLine/FollowTheLine.ino | 60 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/FollowTheLine/FollowTheLine.ino b/FollowTheLine/FollowTheLine.ino index 5105733..8121d44 100644 --- a/FollowTheLine/FollowTheLine.ino +++ b/FollowTheLine/FollowTheLine.ino @@ -50,7 +50,6 @@ void pinClose(byte pin); void pinOpen(byte pin); void allPinsOpen(); void stateControl(char c); -void senseTape(); void bootSequence(); void driveMotor(byte pinOpen1, byte pinOpen2, byte pinClose1, byte pinClose2); @@ -156,6 +155,36 @@ void loop() { } } +void senseTape() +{ + int voltage = analogRead(analogPin); + bool is_black = voltage < B_LOW; + bool is_blue = (voltage >= B_LOW) and (voltage <= B_HIGH); + bool is_red = (voltage > R_LOW) and (voltage <= R_HIGH); + bool is_yellow = voltage > R_HIGH; + + char cmd; + if (is_black) { + Serial.println("Detected Black"); + cmd = BLACK_DO; + } else if (is_blue) { + Serial.println("Detected Blue"); + cmd = BLUE_DO; + } else if (is_red) { + Serial.println("Detected Red"); + cmd = RED_DO; + } else if (is_yellow) { + Serial.println("Detected Yellow"); + cmd = YELLOW_DO; + } else { + Serial.println("Invalid voltage detected! Check Code!"); + cmd = 's'; + } + + stateControl(cmd); +} + + void driveMotor(byte pinOpen1, byte pinOpen2, byte pinClose1, byte pinClose2) { pinOpen(pinOpen1); @@ -217,35 +246,6 @@ void allPinsOpen() pinOpen(sensorLeds); } -void senseTape() -{ - int voltage = analogRead(analogPin); - bool is_black = voltage < B_LOW; - bool is_blue = (voltage >= B_LOW) and (voltage <= B_HIGH); - bool is_red = (voltage > R_LOW) and (voltage <= R_HIGH); - bool is_yellow = voltage > R_HIGH; - - char command; - if (is_black) { - Serial.println("Detected Black"); - command = BLACK_DO; - } else if (is_blue) { - Serial.println("Detected Blue"); - command = BLUE_DO; - } else if (is_red) { - Serial.println("Detected Red"); - command = RED_DO; - } else if (is_yellow) { - Serial.println("Detected Yellow"); - command = YELLOW_DO; - } else { - Serial.println("Invalid voltage detected! Check Code!"); - command = 's'; - } - - stateControl(command); -} - void stateControl(char c) { if (c == 'f'){ -- GitLab From 7e8987fa94940cb8d7c1d9e0bd6e7fccd0d0786e Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:32:10 -0500 Subject: [PATCH 20/28] UnNeeded --- DriveMotorMiniTest | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 DriveMotorMiniTest diff --git a/DriveMotorMiniTest b/DriveMotorMiniTest deleted file mode 100644 index 1461dca..0000000 --- a/DriveMotorMiniTest +++ /dev/null @@ -1,29 +0,0 @@ -#include "Arduino.h" - -String readString; -const byte ledPinBLUE = 6; - -void setup() { - Serial.begin(9600); - Serial.println("Driving led using Serial Test"); // so I can keep track of what is loaded - pinMode(ledPinBLUE, OUTPUT); -} - -void loop() { - int n; - while (Serial.available()) { - char c = Serial.read(); //gets one byte from serial buffer - readString += c; //makes the string readString - delay(2); //slow looping to allow buffer to fill with next character - } - - if (readString.length() >0) { - Serial.println("Input is: "); - Serial.println(readString); //so you can see the captured string - n = readString.toInt(); //convert readString into a number - - readString=""; //empty for next input - } - - analogWrite(ledPinBLUE, n); -} -- GitLab From a2e1528842e4e43354aef6edb3e73e2a2c5ff341 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:32:27 -0500 Subject: [PATCH 21/28] Old Stuff --- Interrupt Test | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 Interrupt Test diff --git a/Interrupt Test b/Interrupt Test deleted file mode 100644 index 545dc91..0000000 --- a/Interrupt Test +++ /dev/null @@ -1,32 +0,0 @@ -static unsigned int state; - -void setup() { - // put your setup code here, to run once: - Serial.begin(9600); - pinMode(2, INPUT); - attachInterrupt(digitalPinToInterrupt(2), myISR(), FALLING); - state = 0; -} - -void loop() { - // put your main code here, to run repeatedly: - if(state == 0){ - digitalWrite(4, LOW); - } else { - for(int i= 0; i < 3; i++){ - digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level) - delay(1000); // wait for a second - digitalWrite(4, LOW); // turn the LED off by making the voltage LOW - delay(1000); - } - } - -} - -void myISR() { - if(state == 0){ - state = 1; - } else { - state = 0; - } -} -- GitLab From 52e4db95f80006abbc0c1fef0d9c97129f1a6057 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 01:32:56 -0500 Subject: [PATCH 22/28] Driving a motor, plain and simple --- DriveMotorMiniTest/DriveMotorMiniTest.ino | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 DriveMotorMiniTest/DriveMotorMiniTest.ino diff --git a/DriveMotorMiniTest/DriveMotorMiniTest.ino b/DriveMotorMiniTest/DriveMotorMiniTest.ino new file mode 100644 index 0000000..7bf7ebc --- /dev/null +++ b/DriveMotorMiniTest/DriveMotorMiniTest.ino @@ -0,0 +1,29 @@ +#include "Arduino.h" + +String readString; +const byte ledPinBLUE = 6; + +void setup() { + Serial.begin(9600); + Serial.println("Driving led using Serial Test"); // so I can keep track of what is loaded + pinMode(ledPinBLUE, OUTPUT); +} + +void loop() { + int n; + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + readString += c; //makes the string readString + delay(2); //slow looping to allow buffer to fill with next character + } + + if (readString.length() >0) { + Serial.println("Input is: "); + Serial.println(readString); //so you can see the captured string + n = readString.toInt(); //convert readString into a number + + readString=""; //empty for next input + } + + analogWrite(ledPinBLUE, n); +} -- GitLab From 7a86c78849d883941ba03c8917bab76bb35e7ca3 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 20:11:08 -0500 Subject: [PATCH 23/28] Both files work with lib. Useful for calibration --- GroundSensorTest/GroundSensorTest.ino | 129 +++++--------------------- MotionControl/MotionControl.ino | 109 ++++++---------------- 2 files changed, 49 insertions(+), 189 deletions(-) diff --git a/GroundSensorTest/GroundSensorTest.ino b/GroundSensorTest/GroundSensorTest.ino index 9f1a3ae..83867b1 100644 --- a/GroundSensorTest/GroundSensorTest.ino +++ b/GroundSensorTest/GroundSensorTest.ino @@ -1,14 +1,11 @@ +#include #include "Arduino.h" -const byte ledRED = 2; -const byte ledBLUE = 3; -const byte ledYELLOW = 4; -const byte ledBLACK = 5; +const byte sensorleds = 6; +const byte analogPin = A3; -const byte sensorledRED = 6; -const byte sensorledBLUE = 7; - -const byte analogPin = A0; +volatile uint8_t cmd; +enum Movements_enum {halt, forward, backward, left, right, rotate_cw, rotate_ccw, search}; // Range of colors are partitions of 1023 const int B_LOW = 300; @@ -16,110 +13,28 @@ const int B_HIGH = 500; const int R_LOW = 500; const int R_HIGH = 800; -String readString; - -volatile uint8_t state; -enum States_enum {OFF, ON}; - -void pinOn(int pin); -void allOff(); -void pinsOff(int pin, int pin2, int pin3); -void stateControl(); -void senseTape(); +/* Edit this for bot functionality + * stop = 's' + * forward = 'f' + * backward = 'b' + * right = 'r' + * left = 'l' + */ + const char RED_DO = right; + const char BLUE_DO = forward; + const char BLACK_DO = search; + const char YELLOW_DO = halt; + +Bounds bound = {B_LOW, B_HIGH, R_LOW, R_HIGH}; +Instructions instr = {RED_DO, BLUE_DO, BLACK_DO, YELLOW_DO}; +GroundSensor tapeSensor(sensorleds, analogPin, bound, instr); void setup() { - pinMode(ledRED, OUTPUT); - pinMode(ledBLUE, OUTPUT); - pinMode(ledYELLOW, OUTPUT); - pinMode(ledBLACK, OUTPUT); - - pinMode(sensorledRED, OUTPUT); - pinMode(sensorledBLUE, OUTPUT); - Serial.begin(9600); Serial.println("Ground Sensor Test"); // so I can keep track of what is loaded - Serial.println("Off"); - state = OFF; + Serial.println("Trying to detect color"); } void loop() { - - switch (state) - { - case OFF: - stateControl(); - allOff(); - break; - - case ON: - stateControl(); - break; - } - -} - -void senseTape() -{ - int voltage = analogRead(analogPin); - bool is_black = voltage < B_LOW; - bool is_blue = (voltage >= B_LOW) and (voltage <= B_HIGH); - bool is_red = (voltage > R_LOW) and (voltage <= R_HIGH); - bool is_yellow = voltage > R_HIGH; - - if (is_black) { - pinsOff(ledBLUE, ledRED, ledYELLOW); - pinOn(ledBLACK); - } else if (is_blue) { - pinsOff(ledBLACK, ledRED, ledYELLOW); - pinOn(ledBLUE); - } else if (is_red) { - pinsOff(ledBLUE, ledBLACK, ledYELLOW); - pinOn(ledRED); - } else if (is_yellow) { - pinsOff(ledBLUE, ledRED, ledBLACK); - pinOn(ledYELLOW); - } else { - Serial.println("Invalid voltage detected! Check Code!"); - } -} - -void stateControl() -{ - while (Serial.available()) { - char c = Serial.read(); //gets one byte from serial buffer - readString += c; //makes the string readString - - if (c == 'l'){ - Serial.println("Both LEDs on"); - state = ON; - } else if (c == 'o'){ - Serial.println("Off"); - state = OFF; - } - - delay(2); //slow looping to allow buffer to fill with next character - } - - if (readString.length() >0) { - readString=""; //empty for next input - delay(2); //slow down a bit so motors have time to get inputs - } -} - -void pinOn(int pin) -{ - digitalWrite(pin, HIGH); -} - -void allOff() -{ - pinsOff(ledRED,ledBLUE,ledYELLOW); - pinsOff(ledBLACK,sensorledRED,sensorledBLUE); -} - -void pinsOff(int pin1, int pin2, int pin3) -{ - digitalWrite(pin1, LOW); - digitalWrite(pin2, LOW); - digitalWrite(pin3, LOW); + tapeSensor.senseColor(&cmd); } diff --git a/MotionControl/MotionControl.ino b/MotionControl/MotionControl.ino index a4df7cc..a8a5db1 100644 --- a/MotionControl/MotionControl.ino +++ b/MotionControl/MotionControl.ino @@ -1,3 +1,4 @@ +#include #include "Arduino.h" const byte WheelLeftF = 2; @@ -11,23 +12,28 @@ const int TQUARTER = 191; const int HALF = 127; const int QUARTER = 64; const int ZERO = 0; - String readString; +/* Control speed of each state*/ +const int FWD_SPD = QUARTER; +const int BCK_SPD = QUARTER; +const int LFT_SPD = QUARTER; +const int RGT_SPD = QUARTER; +const int RT_CW_SPD = QUARTER; +const int RT_CCW_SPD = QUARTER; + +/* Control the motor */ +Wheels w = {WheelLeftF, WheelLeftB, WheelRightF, WheelRightB}; +Speeds s = {FWD_SPD, BCK_SPD, LFT_SPD, RGT_SPD, RT_CW_SPD, RT_CCW_SPD}; +MotorControl motors(w, s); + volatile uint8_t state; enum States_enum {STOP, FORWARD, BACKWARD, LEFT, RIGHT, CIRCLE}; -void pinClose(int pin); -void pinOpen(int pin); void stateControl(); void speedControl(); void setup() { - pinMode(LED_BUILTIN, OUTPUT); - pinMode(WheelLeftF, OUTPUT); - pinMode(WheelLeftB, OUTPUT); - pinMode(WheelRightF, OUTPUT); - pinMode(WheelRightB, OUTPUT); Serial.begin(9600); Serial.println("Driving motor motion Test"); // so I can keep track of what is loaded Serial.println("Stop"); @@ -39,76 +45,38 @@ void loop() { switch (state) { case STOP: - speedControl(); - pinOpen(WheelLeftB); - pinOpen(WheelRightB); - pinOpen(WheelLeftF); - pinOpen(WheelRightF); + stateControl(); + motors.halt(); // Stop right away break; case FORWARD: - speedControl(); - pinOpen(WheelLeftB); - pinOpen(WheelRightB); - analogWrite(WheelLeftF, HALF); - analogWrite(WheelRightF, HALF); + stateControl(); + motors.forward(); break; case BACKWARD: - speedControl(); - pinOpen(WheelLeftF); - pinOpen(WheelRightF); - analogWrite(WheelLeftB, HALF); - analogWrite(WheelRightB, HALF); + stateControl(); + motors.backward(); break; case LEFT: - speedControl(); - pinOpen(WheelLeftB); - pinOpen(WheelRightB); - analogWrite(WheelLeftF, ZERO); - analogWrite(WheelRightF, TQUARTER); + stateControl(); + motors.left(); break; case RIGHT: - speedControl(); - pinOpen(WheelLeftB); - pinOpen(WheelRightB); - analogWrite(WheelLeftF, TQUARTER); - analogWrite(WheelRightF, ZERO); + stateControl(); + motors.right(); break; case CIRCLE: - speedControl(); - pinOpen(WheelLeftB); - pinOpen(WheelRightF); - analogWrite(WheelLeftF, QUARTER); - analogWrite(WheelRightB, QUARTER); - break; + stateControl(); + motors.cw(); + break; } } -void speedControl() -{ - stateControl(); - while (Serial.available()) { - char c = Serial.read(); //gets one byte from serial buffer - readString += c; //makes the string readString - - delay(2); //slow looping to allow buffer to fill with next character - } - - if (readString.length() >0) { - curr_speed = readString.toInt(); - Serial.println("Speed:"); - Serial.println(curr_speed); - readString=""; //empty for next input - - delay(2); //slow down a bit so motors have time to get inputs - } -} - void stateControl() { while (Serial.available()) { @@ -144,26 +112,3 @@ void stateControl() delay(2); //slow down a bit so motors have time to get inputs } } - -void pinOpen(int pin) -{ - digitalWrite(pin, LOW); -} - -void pinClose(int pin) -{ - digitalWrite(pin, HIGH); -} - -void blink (int pin, float hertz, int brightness) { - unsigned int time; - time = 1/hertz * 1000; - - if (state != STOP) { - analogWrite(pin, brightness); // turn the LED on (HIGH is the voltage level) - delay(time); // wait for some second - analogWrite(pin, 0); // turn the LED off by making the voltage LOW - delay(time); - } -} - -- GitLab From b4b1fa22a0679b8fff2ce4d3f14708669f31081b Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Fri, 14 Feb 2020 20:11:59 -0500 Subject: [PATCH 24/28] Add files via upload --- DriveMotorTest/DriveMotorTest.ino | 61 ++--- FollowLineUsingLib/FollowLineUsingLib.ino | 64 +++-- .../GenerateOutOfPhaseTest.ino | 50 ++++ StateMachine/StateMachine.ino | 228 +++++++++--------- libraries/FourPinControl/FourPinControl.cpp | 2 +- libraries/FourPinControl/FourPinControl.h | 2 +- libraries/MotorControl/MotorControl.cpp | 20 +- libraries/MotorControl/MotorControl.h | 7 +- 8 files changed, 245 insertions(+), 189 deletions(-) create mode 100644 GenerateOutOfPhaseTest/GenerateOutOfPhaseTest.ino diff --git a/DriveMotorTest/DriveMotorTest.ino b/DriveMotorTest/DriveMotorTest.ino index ec78f51..e668378 100644 --- a/DriveMotorTest/DriveMotorTest.ino +++ b/DriveMotorTest/DriveMotorTest.ino @@ -1,32 +1,21 @@ +#include #include "Arduino.h" -const byte interruptPinButton = 2; - -const byte ledPinRED = 4; -const byte ledPinGREEN = 5; -const byte ledPinBLUE = 6; -volatile int curr_speed; - -String readString; volatile uint8_t state; enum States_enum {FORWARD, BACKWARD}; -void myISR(); -void ledOff(int pin); -void ledOn(int pin); void speedControl(); void setup() { pinMode(LED_BUILTIN, OUTPUT); - pinMode(interruptPinButton, INPUT_PULLUP); // RUN/STOP button - pinMode(ledPinRED, OUTPUT); pinMode(ledPinGREEN, OUTPUT); pinMode(ledPinBLUE, OUTPUT); Serial.begin(9600); Serial.println("Driving motor using Serial Test"); // so I can keep track of what is loaded - attachInterrupt(digitalPinToInterrupt(interruptPinButton), myISR, FALLING); + Serial.println("Moving Forward"); + curr_speed = 0; state = FORWARD; } @@ -49,44 +38,32 @@ void loop() { } -void myISR() { - if(state == FORWARD){ - curr_speed = 0; - state = BACKWARD; - Serial.println("Moving BACKWARD"); - } else if(state == BACKWARD) { - curr_speed = 0; - state = FORWARD; - Serial.println("Moving FORWARD"); - } - delay(2); - -} - void speedControl() { while (Serial.available()) { char c = Serial.read(); //gets one byte from serial buffer readString += c; //makes the string readString + + if (c == 'f'){ + Serial.println("Going Forward"); + state = FORWARD; + } else if (c == 'b'){ + Serial.println("Moving Backward"); + state = BACKWARD; + } + delay(2); //slow looping to allow buffer to fill with next character } - if (readString.length() >0) { - Serial.println("Input is: "); + if ((readString.length() >0)) { + Serial.println("Input is:"); Serial.println(readString); //so you can see the captured string - curr_speed = readString.toInt(); //convert readString into a number + + curr_speed = readString.toInt(); + Serial.println("Speed:"); + Serial.println(curr_speed); - readString=""; //empty for next input + readString = ""; //empty for next input } } - -void ledOff(int pin) -{ - digitalWrite(pin, LOW); -} - -void ledOn(int pin) -{ - digitalWrite(pin, HIGH); -} diff --git a/FollowLineUsingLib/FollowLineUsingLib.ino b/FollowLineUsingLib/FollowLineUsingLib.ino index 95592fd..c1d0677 100644 --- a/FollowLineUsingLib/FollowLineUsingLib.ino +++ b/FollowLineUsingLib/FollowLineUsingLib.ino @@ -36,7 +36,6 @@ Bounds bound = {B_LOW, B_HIGH, R_LOW, R_HIGH}; Instructions instr = {RED_DO, BLUE_DO, BLACK_DO, YELLOW_DO}; GroundSensor tapeSensor(sensorLeds, analogPin, bound, instr); - /* Pins for wheel control */ const byte WheelLeftF = 2; const byte WheelLeftB = 3; @@ -67,7 +66,7 @@ void stateControl(uint8_t c); void bootSequence(); void setup() { - attachInterrupt(digitalPinToInterrupt(analogPin), detect, CHANGE); + //attachInterrupt(digitalPinToInterrupt(sensorLeds), detect, CHANGE); Serial.begin(9600); Serial.println("Follow the Line Color"); // so I can keep track of what is loaded Serial.println("Bot is OFF"); @@ -91,48 +90,67 @@ void loop() { case ON: bootSequence(); + tapeSensor.senseColor(&cmd); + stateControl(); break; case STOP: - motors.stop(); // Stop right away + tapeSensor.senseColor(&cmd); + stateControl(); + motors.halt(); break; case FORWARD: - stateControl(cmd); + tapeSensor.senseColor(&cmd); + stateControl(); motors.forward(); break; case BACKWARD: - stateControl(cmd); + tapeSensor.senseColor(&cmd); + stateControl(); motors.backward(); break; case LEFT: - stateControl(cmd); + tapeSensor.senseColor(&cmd); + stateControl(); motors.left(); break; case RIGHT: - stateControl(cmd); + tapeSensor.senseColor(&cmd); + stateControl(); motors.right(); break; case CLOCKWISE: - stateControl(cmd); + tapeSensor.senseColor(&cmd); + stateControl(); motors.cw(); break; case CCLOCKWISE: - stateControl(cmd); + tapeSensor.senseColor(&cmd); + stateControl(); motors.ccw(); break; case SEARCH: - stateControl(cmd); + tapeSensor.senseColor(&cmd); + stateControl(); motors.ccw(); delay(1000); + motors.halt(); + tapeSensor.senseColor(&cmd); + stateControl(); + delay(500); motors.cw(); delay(3000); + tapeSensor.senseColor(&cmd); + stateControl(); + motors.halt(); + delay(500); break; } } @@ -148,33 +166,32 @@ void bootSequence() Serial.println("1"); delay(1000); digitalWrite(sensorLeds, HIGH); - tapeSensor.senseColor(&cmd); } -void stateControl(uint8_t c) +void stateControl() { - if (c == forward){ + if (cmd == forward){ Serial.println("Going Forward"); state = FORWARD; - } else if (c == backward){ + } else if (cmd == backward){ Serial.println("Moving Backward"); state = BACKWARD; - } else if (c == left){ + } else if (cmd == left){ Serial.println("Moving Left"); state = LEFT; - } else if (c == right){ + } else if (cmd == right){ Serial.println("Moving Right"); state = RIGHT; - } else if (c == halt){ + } else if (cmd == halt){ Serial.println("Stop"); state = STOP; - } else if (c == rotate_cw){ + } else if (cmd == rotate_cw){ Serial.println("Turn 360 Clockwise"); state = CLOCKWISE; - } else if (c == rotate_ccw){ + } else if (cmd == rotate_ccw){ Serial.println("Turn 360 Counter Clockwise"); state = CCLOCKWISE; - } else if (c == search){ + } else if (cmd == search){ Serial.println("Searching for path"); state = SEARCH; } @@ -182,8 +199,9 @@ void stateControl(uint8_t c) delay(5); //slow loop to allow for change in state } -void detect() +/*void detect() { - tapeSensor.senseColor(&cmd); -} + tapeSensor.senseColor(&cmd); + stateControl(); +}*/ diff --git a/GenerateOutOfPhaseTest/GenerateOutOfPhaseTest.ino b/GenerateOutOfPhaseTest/GenerateOutOfPhaseTest.ino new file mode 100644 index 0000000..63fa978 --- /dev/null +++ b/GenerateOutOfPhaseTest/GenerateOutOfPhaseTest.ino @@ -0,0 +1,50 @@ +byte duty_cycle = 0; + +String readString; + +void setup(){ + pinMode(10, OUTPUT); + pinMode(9, OUTPUT); + Serial.begin(9600); + + /* Phase Correct PWM */ + TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20); + TCCR2B = _BV(CS22); + + //TCCR1A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20); + //TCCR1B = _BV(CS22); + + /* + TCCR3A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM20); + TCCR1B = _BV(WGM22) | _BV(CS22); + */ + + /* + TCCR3A = (0<0) { + duty_cycle = readString.toInt(); + + Serial.println("Duty_Cycle A:"); + Serial.println(duty_cycle); + Serial.println("Duty_Cycle B:"); + Serial.println(duty_cycle); + + OCR2A = duty_cycle; + OCR2B = duty_cycle; + readString=""; //empty for next input + } + analogWrite(10, OCR2A); + analogWrite(9, OCR2B); + delay(2); +} diff --git a/StateMachine/StateMachine.ino b/StateMachine/StateMachine.ino index 46eecce..73e6817 100644 --- a/StateMachine/StateMachine.ino +++ b/StateMachine/StateMachine.ino @@ -1,114 +1,114 @@ -#include "Arduino.h" - -const byte interruptPinButton = 2; -const byte interruptPinOnOff = 3; - -const byte ledPinRED = 4; -const byte ledPinGREEN = 5; -const byte ledPinBLUE = 6; -const byte analogPinPot1 = A0; -const byte analogPinPot2 = A1; - - -volatile uint8_t state; -enum States_enum {OFF, ON, RUN}; - -void blink(int pin, float hertz, int brightness); -void myISR1(); -void myISR2(); -void fade(int pin, int timeToOff); -int calcFadeTime(); -int calcBrightness(); - -void setup() { - // put your setup code here, to run once: - pinMode(LED_BUILTIN, OUTPUT); - pinMode(interruptPinButton, INPUT_PULLUP); // RUN/STOP button - pinMode(interruptPinOnOff, INPUT_PULLUP); // ON/OFF switch - pinMode(ledPinRED, OUTPUT); - pinMode(ledPinGREEN, OUTPUT); - pinMode(ledPinBLUE, OUTPUT); - - Serial.begin(9600); - attachInterrupt(digitalPinToInterrupt(interruptPinButton), myISR1, FALLING); - attachInterrupt(digitalPinToInterrupt(interruptPinOnOff), myISR2, FALLING); - - state = OFF; -} - -void loop() { - - switch (state) - { - case OFF: - digitalWrite(4 , HIGH); // turn on RED LED - //Serial.println("I'm Off"); // send a message if in OFF state - break; - - case ON: - digitalWrite(ledPinRED, LOW); - blink(5, 10, calcBrightness()); // Blink at 10 Hz - //Serial.println("I'm On"); // send a message if in ON state - break; - - - case RUN: - fade(ledPinBLUE, calcFadeTime()); // fade over pot set time - //Serial.println("I'm Running"); // send a message if in RUN state - break; - } - -} - -void blink (int pin, float hertz, int brightness) { - unsigned int time; - time = 1/hertz * 1000; - - if (state != OFF) { - analogWrite(pin, brightness); // turn the LED on (HIGH is the voltage level) - delay(time); // wait for some second - analogWrite(pin, 0); // turn the LED off by making the voltage LOW - delay(time); - } -} - -void myISR1() { - Serial.println("I'm Interrupting Button"); - if(state == ON){ - state = RUN; - } else if(state == RUN) { - state = ON; - } -} - -void myISR2() { - Serial.println("I'm Interrupting On/Off"); - if(state == OFF) { - state = ON; - } else { - state = OFF; - } -} - -void fade(int pin, int timeToOff) { - analogWrite(pin,255); - for (int i = 0; i < 51; i++){ - analogWrite(pin, 255-i*5); - delay(timeToOff/51); - } - analogWrite(pin, LOW); -} - -int calcFadeTime(){ - int voltage = analogRead(analogPinPot1); - - float timeMs = voltage / 350.00 * 3000 + 500; - - return timeMs; - } - - int calcBrightness(){ - int voltage = analogRead(analogPinPot2); - float brightness = voltage / 615.00 * 255; - return round(brightness); - } +#include "Arduino.h" + +const byte interruptPinButton = 2; +const byte interruptPinOnOff = 3; + +const byte ledPinRED = 4; +const byte ledPinGREEN = 5; +const byte ledPinBLUE = 6; +const byte analogPinPot1 = A0; +const byte analogPinPot2 = A1; + + +volatile uint8_t state; +enum States_enum {OFF, ON, RUN}; + +void blink(int pin, float hertz, int brightness); +void myISR1(); +void myISR2(); +void fade(int pin, int timeToOff); +int calcFadeTime(); +int calcBrightness(); + +void setup() { + // put your setup code here, to run once: + pinMode(LED_BUILTIN, OUTPUT); + pinMode(interruptPinButton, INPUT_PULLUP); // RUN/STOP button + pinMode(interruptPinOnOff, INPUT_PULLUP); // ON/OFF switch + pinMode(ledPinRED, OUTPUT); + pinMode(ledPinGREEN, OUTPUT); + pinMode(ledPinBLUE, OUTPUT); + + Serial.begin(9600); + attachInterrupt(digitalPinToInterrupt(interruptPinButton), myISR1, FALLING); + attachInterrupt(digitalPinToInterrupt(interruptPinOnOff), myISR2, FALLING); + + state = OFF; +} + +void loop() { + + switch (state) + { + case OFF: + digitalWrite(4 , HIGH); // turn on RED LED + //Serial.println("I'm Off"); // send a message if in OFF state + break; + + case ON: + digitalWrite(ledPinRED, LOW); + blink(5, 10, calcBrightness()); // Blink at 10 Hz + //Serial.println("I'm On"); // send a message if in ON state + break; + + + case RUN: + fade(ledPinBLUE, calcFadeTime()); // fade over pot set time + //Serial.println("I'm Running"); // send a message if in RUN state + break; + } + +} + +void blink (int pin, float hertz, int brightness) { + unsigned int time; + time = 1/hertz * 1000; + + if (state != OFF) { + analogWrite(pin, brightness); // turn the LED on (HIGH is the voltage level) + delay(time); // wait for some second + analogWrite(pin, 0); // turn the LED off by making the voltage LOW + delay(time); + } +} + +void myISR1() { + Serial.println("I'm Interrupting Button"); + if(state == ON){ + state = RUN; + } else if(state == RUN) { + state = ON; + } +} + +void myISR2() { + Serial.println("I'm Interrupting On/Off"); + if(state == OFF) { + state = ON; + } else { + state = OFF; + } +} + +void fade(int pin, int timeToOff) { + analogWrite(pin,255); + for (int i = 0; i < 51; i++){ + analogWrite(pin, 255-i*5); + delay(timeToOff/51); + } + analogWrite(pin, LOW); +} + +int calcFadeTime(){ + int voltage = analogRead(analogPinPot1); + + float timeMs = voltage / 350.00 * 3000 + 500; + + return timeMs; + } + + int calcBrightness(){ + int voltage = analogRead(analogPinPot2); + float brightness = voltage / 615.00 * 255; + return round(brightness); + } diff --git a/libraries/FourPinControl/FourPinControl.cpp b/libraries/FourPinControl/FourPinControl.cpp index 322843e..b20e8d8 100644 --- a/libraries/FourPinControl/FourPinControl.cpp +++ b/libraries/FourPinControl/FourPinControl.cpp @@ -7,7 +7,7 @@ FourPinControl::FourPinControl() _p1 = _p2 = _p3 = _p4 = 0; } -void FourPinControl::newOutputs(int p1, int p2, int p3, int p4) +FourPinControl::FourPinControl(int p1, int p2, int p3, int p4) { // Set pins to output mode, remember them pinMode(p1, OUTPUT); diff --git a/libraries/FourPinControl/FourPinControl.h b/libraries/FourPinControl/FourPinControl.h index db65163..4d2860d 100644 --- a/libraries/FourPinControl/FourPinControl.h +++ b/libraries/FourPinControl/FourPinControl.h @@ -7,7 +7,7 @@ class FourPinControl { public: FourPinControl(); - void newOutputs(int p1, int p2, int p3, int p4); + FourPinControl(int p1, int p2, int p3, int p4); void pinOpen(int p); void twoPinsOpen(int p1, int p2); diff --git a/libraries/MotorControl/MotorControl.cpp b/libraries/MotorControl/MotorControl.cpp index 26ab536..6b04857 100644 --- a/libraries/MotorControl/MotorControl.cpp +++ b/libraries/MotorControl/MotorControl.cpp @@ -13,14 +13,25 @@ enum Movements_enum {FORWARD, BACK, LEFT, RIGHT, CW, CCW}; MotorControl::MotorControl(Wheels w, Speeds s) { - _pinControl.newOutputs(w.leftF, w.leftB, w.rightF, w.rightB); + pinMode(w.leftF, OUTPUT); + pinMode(w.leftB, OUTPUT); + pinMode(w.rightF, OUTPUT); + pinMode(w.rightB, OUTPUT); _w = w; _s = s; } -void MotorControl::stop() +void MotorControl::allPinsOpen() { - _pinControl.allPinsOpen(); + digitalWrite(_w.leftF, LOW); + digitalWrite(_w.leftB, LOW); + digitalWrite(_w.rightF, LOW); + digitalWrite(_w.rightB, LOW); +} + +void MotorControl::halt() +{ + allPinsOpen(); } void MotorControl::forward() @@ -60,7 +71,8 @@ void MotorControl::ccw() void MotorControl::driveMotor(int movement) { - _pinControl.twoPinsOpen(_m.w1, _m.w2); + digitalWrite(_m.w1, LOW); + digitalWrite(_m.w2, LOW); switch (movement) { diff --git a/libraries/MotorControl/MotorControl.h b/libraries/MotorControl/MotorControl.h index c1d881b..3988f55 100644 --- a/libraries/MotorControl/MotorControl.h +++ b/libraries/MotorControl/MotorControl.h @@ -2,7 +2,6 @@ #define MotorControl_h #include "Arduino.h" -#include "FourPinControl.h" struct Wheels { int leftF, leftB, rightF, rightB; @@ -16,7 +15,7 @@ class MotorControl { public: MotorControl(Wheels w, Speeds s); - void stop(); + void halt(); void forward(); void backward(); void left(); @@ -26,15 +25,15 @@ class MotorControl private: struct Movement { - int w1, w2, w3, w4; + int w1, w2, w3, w4; }; Wheels _w; Speeds _s; Movement _m; - FourPinControl _pinControl; void driveMotor(int movement); + void allPinsOpen(); }; #endif -- GitLab From 6215fb1e04af34a236e924cbbe43f93a91dd5592 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Sun, 23 Feb 2020 01:16:26 -0500 Subject: [PATCH 25/28] New updated libraries and tests --- DistanceTest/DistanceTest.ino | 94 ++++++++ FollowLineUsingLib/FollowLineUsingLib.ino | 237 ++++++++++---------- GroundSensorTest/GroundSensorTest.ino | 43 ++-- HallSensorTest/HallSensorTest.ino | 90 ++++++++ HallSensorTestBasic/HallSensorTestBasic.ino | 25 +++ MotionControl/MotionControl.ino | 9 +- SearchingTest/SearchingTest.ino | 204 +++++++++++++++++ libraries/GroundSensor/GroundSensor.cpp | 154 ++++++++++--- libraries/GroundSensor/GroundSensor.h | 36 +++ libraries/MotorControl/MotorControl.cpp | 55 ++++- libraries/MotorControl/MotorControl.h | 63 ++++-- 11 files changed, 818 insertions(+), 192 deletions(-) create mode 100644 DistanceTest/DistanceTest.ino create mode 100644 HallSensorTest/HallSensorTest.ino create mode 100644 HallSensorTestBasic/HallSensorTestBasic.ino create mode 100644 SearchingTest/SearchingTest.ino diff --git a/DistanceTest/DistanceTest.ino b/DistanceTest/DistanceTest.ino new file mode 100644 index 0000000..8528d46 --- /dev/null +++ b/DistanceTest/DistanceTest.ino @@ -0,0 +1,94 @@ +#include +#include "Arduino.h" + +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +/* Time of travel and constant speed value*/ +const float distance = 5; // inches +const int BEST= 45; + +/* Acceleration time and speed*/ +const int ACC_TIME = 100; +const int ACC_SPD = QUARTER; + +const byte WheelLeftF = 2; +const byte WheelLeftB = 3; +const byte WheelRightF = 4; +const byte WheelRightB = 5; + +/* Control speed of each state*/ +const int FWD_SPD = BEST; +const int BCK_SPD = BEST+10; +const int LFT_SPD = BEST; +const int RGT_SPD = BEST; +const int RT_CW_SPD = BEST; +const int RT_CCW_SPD = BEST; + +/* Control the motor */ +Wheels w = {WheelLeftF, WheelLeftB, WheelRightF, WheelRightB}; +Speeds s = {FWD_SPD, BCK_SPD, LFT_SPD, RGT_SPD, RT_CW_SPD, RT_CCW_SPD}; +Accel a = {ACC_TIME, ACC_SPD}; +MotorControl motors(w, s, a); + +volatile uint8_t state; +enum States_enum {STOP, FORWARD, BACKWARD}; + +void stateControl(); + +void setup() { + Serial.begin(9600); + Serial.println("Distace Test"); // so I can keep track of what is loaded + Serial.println("Stop"); + state = STOP; +} + +void loop() { + + int time_delay = distance * 1000; + switch (state) + { + case STOP: + stateControl(); + motors.halt(); // Stop right away + break; + + case FORWARD: + stateControl(); + motors.forward(); + delay(time_delay); + state = STOP; + break; + + case BACKWARD: + stateControl(); + motors.backward(); + delay(time_delay); + state = STOP; + break; + } + +} + +void stateControl() +{ + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + + if (c == 'f'){ + Serial.println("Going Forward"); + state = FORWARD; + } else if (c == 'b'){ + Serial.println("Moving Backward"); + state = BACKWARD; + } else if (c == 's'){ + Serial.println("Stop"); + state = STOP; + } + + delay(2); //slow looping to allow buffer to fill with next character + } +} diff --git a/FollowLineUsingLib/FollowLineUsingLib.ino b/FollowLineUsingLib/FollowLineUsingLib.ino index c1d0677..f70fba7 100644 --- a/FollowLineUsingLib/FollowLineUsingLib.ino +++ b/FollowLineUsingLib/FollowLineUsingLib.ino @@ -2,39 +2,47 @@ #include #include "Arduino.h" +/* Duty Cycle constants */ +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; +const int BEST = 45; // Will need to change when weight of bot change + volatile uint8_t state; -enum States_enum {OFF, ON, STOP, FORWARD, BACKWARD, LEFT, RIGHT, CLOCKWISE, CCLOCKWISE, SEARCH}; +enum States_enum {OFF, ON, STOP, FORWARD, BACKWARD, LEFT, RIGHT, CLOCKWISE, CCLOCKWISE}; volatile uint8_t cmd; -enum Movements_enum {halt, forward, backward, left, right, rotate_cw, rotate_ccw, search}; +volatile uint8_t on; +enum Movements_enum {halt, forward, backward, left, right, rotate_cw, rotate_ccw, search}; + + +/******************************* Configuration Section **********************************/ /* Pin to turn on/off ground sensor */ -const byte sensorLeds = 6; +const byte sensorLeds = 13; /* Pin for analog input from ground sensor */ const byte analogPin = A0; /* Range of colors are partitions of 1023 */ +/* R = 3.7 kOhms const int B_LOW = 300; const int B_HIGH = 500; const int R_LOW = 500; -const int R_HIGH = 800; - -/* Edit this for bot functionality - * stop = 's' - * forward = 'f' - * backward = 'b' - * right = 'r' - * left = 'l' - */ - const char RED_DO = right; - const char BLUE_DO = forward; - const char BLACK_DO = search; - const char YELLOW_DO = halt; - - /* Set up the ground sensor */ -Bounds bound = {B_LOW, B_HIGH, R_LOW, R_HIGH}; -Instructions instr = {RED_DO, BLUE_DO, BLACK_DO, YELLOW_DO}; -GroundSensor tapeSensor(sensorLeds, analogPin, bound, instr); +const int R_HIGH = 835; +*/ +/* R = 5.6 kOhms */ +const int B_LOW = 400; +const int B_HIGH = 700; +const int R_LOW = 700; +const int R_HIGH = 1020; + +/* What bot should do when it sense a color*/ +const char RED_DO = forward; +const char BLUE_DO = forward; +const char BLACK_DO = rotate_ccw; +const char YELLOW_DO = forward; /* Pins for wheel control */ const byte WheelLeftF = 2; @@ -42,166 +50,169 @@ const byte WheelLeftB = 3; const byte WheelRightF = 4; const byte WheelRightB = 5; -/* Duty Cycle constants */ -const int MAX = 255; -const int TQUARTER = 191; -const int HALF = 127; -const int QUARTER = 64; -const int ZERO = 0; - /* Control speed of each state*/ -const int FWD_SPD = QUARTER; -const int BCK_SPD = QUARTER; +const int FWD_SPD = BEST; +const int BCK_SPD = BEST; const int LFT_SPD = QUARTER; const int RGT_SPD = QUARTER; const int RT_CW_SPD = QUARTER; const int RT_CCW_SPD = QUARTER; +/* Set transition delay*/ +int transition_delay = 100; + +/* Acceleration time and speed*/ +const int ACC_TIME = 200; +const int ACC_SPD = QUARTER; + +/*****************************************************************************************/ + + +/* Set up the ground sensor */ +Bounds bound = {B_LOW, B_HIGH, R_LOW, R_HIGH}; +Instructions instr = {RED_DO, BLUE_DO, BLACK_DO, YELLOW_DO}; +GroundSensor tapeSensor(sensorLeds, analogPin, bound, instr, transition_delay); + /* Control the motor */ Wheels w = {WheelLeftF, WheelLeftB, WheelRightF, WheelRightB}; Speeds s = {FWD_SPD, BCK_SPD, LFT_SPD, RGT_SPD, RT_CW_SPD, RT_CCW_SPD}; -MotorControl motors(w, s); +Accel a = {ACC_TIME, ACC_SPD}; +MotorControl motors(w, s, a); -void stateControl(uint8_t c); +void stateControl(); void bootSequence(); void setup() { - //attachInterrupt(digitalPinToInterrupt(sensorLeds), detect, CHANGE); - Serial.begin(9600); - Serial.println("Follow the Line Color"); // so I can keep track of what is loaded + Serial.begin(9600); + Serial.println("Follow the Line Color"); // so I can keep track of what is loaded Serial.println("Bot is OFF"); state = OFF; + on = 'n'; + cmd = BLACK_DO; Serial.println("Turn it on? Y/N"); } void loop() { - while (Serial.available()) { - char c = Serial.read(); //gets one byte from serial buffer - if ((c = 'Y') || (c = 'y')) { - state = ON; - } - } - + switch (state) { case OFF: /* Starting state, wait for user to turn on*/ + while (Serial.available()) { + on = Serial.read(); //gets one byte from serial buffer + if ((on == 'y')) { + state = ON; + on = 'n'; + delay(2); + break; + } + } + motors.halt(); + digitalWrite(sensorLeds, LOW); break; case ON: bootSequence(); + delay(500); tapeSensor.senseColor(&cmd); stateControl(); - break; - + break; + case STOP: + motors.halt(); tapeSensor.senseColor(&cmd); stateControl(); - motors.halt(); break; - + case FORWARD: + if (cmd == backward) { + motors.halt(); + delay(10000); + } + motors.forward(); tapeSensor.senseColor(&cmd); stateControl(); - motors.forward(); break; case BACKWARD: + if (cmd == forward) { + motors.halt(); + delay(10000); + } + motors.backward(); tapeSensor.senseColor(&cmd); stateControl(); - motors.backward(); break; - case LEFT: + case LEFT: + motors.left(); tapeSensor.senseColor(&cmd); stateControl(); - motors.left(); break; case RIGHT: - tapeSensor.senseColor(&cmd); - stateControl(); motors.right(); - break; - - case CLOCKWISE: tapeSensor.senseColor(&cmd); stateControl(); - motors.cw(); break; - case CCLOCKWISE: + case CLOCKWISE: + motors.cw(); tapeSensor.senseColor(&cmd); stateControl(); - motors.ccw(); break; - case SEARCH: - tapeSensor.senseColor(&cmd); - stateControl(); + case CCLOCKWISE: motors.ccw(); - delay(1000); - motors.halt(); - tapeSensor.senseColor(&cmd); - stateControl(); - delay(500); - motors.cw(); - delay(3000); tapeSensor.senseColor(&cmd); stateControl(); - motors.halt(); - delay(500); break; } } void bootSequence() { - Serial.println("Bot is on"); - Serial.println("Moving in "); - Serial.println("3"); - delay(1000); - Serial.println("2"); - delay(1000); - Serial.println("1"); - delay(1000); - digitalWrite(sensorLeds, HIGH); + Serial.println("Bot is on"); + digitalWrite(sensorLeds, HIGH); + Serial.println("Ready!"); + delay(1000); + Serial.println("Go!"); } void stateControl() { - if (cmd == forward){ - Serial.println("Going Forward"); - state = FORWARD; - } else if (cmd == backward){ - Serial.println("Moving Backward"); - state = BACKWARD; - } else if (cmd == left){ - Serial.println("Moving Left"); - state = LEFT; - } else if (cmd == right){ - Serial.println("Moving Right"); - state = RIGHT; - } else if (cmd == halt){ - Serial.println("Stop"); - state = STOP; - } else if (cmd == rotate_cw){ - Serial.println("Turn 360 Clockwise"); - state = CLOCKWISE; - } else if (cmd == rotate_ccw){ - Serial.println("Turn 360 Counter Clockwise"); - state = CCLOCKWISE; - } else if (cmd == search){ - Serial.println("Searching for path"); - state = SEARCH; - } - - delay(5); //slow loop to allow for change in state -} + /* Change the state based on cmd*/ + if (cmd == forward) { + //Serial.println("Going Forward"); + state = FORWARD; + } else if (cmd == backward) { + Serial.println("Moving Backward"); + state = BACKWARD; + } else if (cmd == left) { + //Serial.println("Moving Left"); + state = LEFT; + } else if (cmd == right) { + //Serial.println("Moving Right"); + state = RIGHT; + } else if (cmd == halt) { + //Serial.println("Stop"); + state = STOP; + } else if (cmd == rotate_cw) { + //Serial.println("Turn 360 Clockwise"); + state = CLOCKWISE; + } else if (cmd == rotate_ccw) { + //Serial.println("Turn 360 Counter Clockwise"); + state = CCLOCKWISE; + } + delay(2); //slow loop to allow for change in state -/*void detect() -{ - tapeSensor.senseColor(&cmd); - stateControl(); -}*/ - + while (Serial.available()) { + on = Serial.read(); //gets one byte from serial buffer + if ((on == 'y')) { + state = OFF; + on = 'n'; + delay(2); + break; + } + } +} diff --git a/GroundSensorTest/GroundSensorTest.ino b/GroundSensorTest/GroundSensorTest.ino index 83867b1..7c2fbe1 100644 --- a/GroundSensorTest/GroundSensorTest.ino +++ b/GroundSensorTest/GroundSensorTest.ino @@ -1,29 +1,24 @@ #include #include "Arduino.h" -const byte sensorleds = 6; -const byte analogPin = A3; +const byte sensorleds = 13; +const byte analogPin = A0; volatile uint8_t cmd; -enum Movements_enum {halt, forward, backward, left, right, rotate_cw, rotate_ccw, search}; +volatile uint8_t light; +enum Movements_enum {halt, forward, backward, left, right, rotate_cw, rotate_ccw, search}; // Range of colors are partitions of 1023 -const int B_LOW = 300; -const int B_HIGH = 500; -const int R_LOW = 500; -const int R_HIGH = 800; +// R = 5.6 kOhms +const int B_LOW = 400; +const int B_HIGH = 700; +const int R_LOW = 700; +const int R_HIGH = 1020; -/* Edit this for bot functionality - * stop = 's' - * forward = 'f' - * backward = 'b' - * right = 'r' - * left = 'l' - */ - const char RED_DO = right; - const char BLUE_DO = forward; - const char BLACK_DO = search; - const char YELLOW_DO = halt; +const char RED_DO = right; +const char BLUE_DO = forward; +const char BLACK_DO = search; +const char YELLOW_DO = halt; Bounds bound = {B_LOW, B_HIGH, R_LOW, R_HIGH}; Instructions instr = {RED_DO, BLUE_DO, BLACK_DO, YELLOW_DO}; @@ -33,8 +28,18 @@ void setup() { Serial.begin(9600); Serial.println("Ground Sensor Test"); // so I can keep track of what is loaded Serial.println("Trying to detect color"); + light = 'f'; + cmd = BLACK_DO; } void loop() { - tapeSensor.senseColor(&cmd); + while (Serial.available()) { + light = Serial.read(); //gets one byte from serial buffer + if ((light == 'o')) { + digitalWrite(sensorleds, HIGH); + } else if ((light == 'f')) { + digitalWrite(sensorleds, LOW); + } + } + tapeSensor.senseColor(&cmd); } diff --git a/HallSensorTest/HallSensorTest.ino b/HallSensorTest/HallSensorTest.ino new file mode 100644 index 0000000..0045255 --- /dev/null +++ b/HallSensorTest/HallSensorTest.ino @@ -0,0 +1,90 @@ +#include +#include "Arduino.h" + +const byte WheelLeftF = 2; +const byte WheelLeftB = 3; +const byte WheelRightF = 4; +const byte WheelRightB = 5; + +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +/* Control speed of each state*/ +const int FWD_SPD = QUARTER; +const int BCK_SPD = QUARTER; +const int LFT_SPD = QUARTER; +const int RGT_SPD = QUARTER; +const int RT_CW_SPD = QUARTER; +const int RT_CCW_SPD = QUARTER; + +/* Control the motor */ +Wheels w = {WheelLeftF, WheelLeftB, WheelRightF, WheelRightB}; +Speeds s = {FWD_SPD, BCK_SPD, LFT_SPD, RGT_SPD, RT_CW_SPD, RT_CCW_SPD}; +MotorControl motors(w, s); + +volatile uint8_t state; +enum States_enum {STOP, FORWARD, BACKWARD}; + +const int hallSensor = 7; + +void stateControl(); +void brakeISR(); + +void setup() { + attachInterrupt(digitalPinToInterrupt(hallSensor), brakeISR, HIGH); + Serial.begin(9600); + Serial.println("Hall Sensor Test"); // so I can keep track of what is loaded + Serial.println("Stop"); + state = STOP; +} + +void loop() { + + switch (state) + { + case STOP: + stateControl(); + motors.halt(); // Stop right away + break; + + case FORWARD: + stateControl(); + motors.forward(); + break; + + case BACKWARD: + stateControl(); + motors.backward(); + break; + } + +} + +void stateControl() +{ + while (Serial.available()) { + char c = Serial.read(); //gets one byte from serial buffer + + if (c == 'f'){ + Serial.println("Going Forward"); + state = FORWARD; + } else if (c == 'b'){ + Serial.println("Moving Backward"); + state = BACKWARD; + } else if (c == 's'){ + Serial.println("Stop"); + state = STOP; + } + + delay(2); //slow looping to allow buffer to fill with next character + } +} + +void brakeISR() +{ + Serial.println("Pedestrian Detected"); + state = STOP; +} diff --git a/HallSensorTestBasic/HallSensorTestBasic.ino b/HallSensorTestBasic/HallSensorTestBasic.ino new file mode 100644 index 0000000..3ed0b45 --- /dev/null +++ b/HallSensorTestBasic/HallSensorTestBasic.ino @@ -0,0 +1,25 @@ +#include +#include "Arduino.h" + +const int hallSensor = 7; +const int sensorLed = 12; + +void brakeISR(); + +void setup() { + pinMode(sensorLed, OUTPUT); + attachInterrupt(digitalPinToInterrupt(hallSensor), brakeISR, HIGH); + Serial.begin(9600); + Serial.println("Hall Sensor Test"); // so I can keep track of what is loaded +} + +void loop() { + digitalWrite(sensorLed, LOW); +} + +void brakeISR() +{ + Serial.println("Pedestrian Detected"); + digitalWrite(sensorLed, HIGH); + state = STOP; +} diff --git a/MotionControl/MotionControl.ino b/MotionControl/MotionControl.ino index a8a5db1..587712e 100644 --- a/MotionControl/MotionControl.ino +++ b/MotionControl/MotionControl.ino @@ -5,7 +5,6 @@ const byte WheelLeftF = 2; const byte WheelLeftB = 3; const byte WheelRightF = 4; const byte WheelRightB = 5; -volatile int curr_speed; const int MAX = 255; const int TQUARTER = 191; @@ -22,16 +21,20 @@ const int RGT_SPD = QUARTER; const int RT_CW_SPD = QUARTER; const int RT_CCW_SPD = QUARTER; +/* Acceleration time and speed*/ +const int ACC_TIME = 100; +const int ACC_SPD = QUARTER; + /* Control the motor */ Wheels w = {WheelLeftF, WheelLeftB, WheelRightF, WheelRightB}; Speeds s = {FWD_SPD, BCK_SPD, LFT_SPD, RGT_SPD, RT_CW_SPD, RT_CCW_SPD}; -MotorControl motors(w, s); +Accel a = {ACC_TIME, ACC_SPD}; +MotorControl motors(w, s, a); volatile uint8_t state; enum States_enum {STOP, FORWARD, BACKWARD, LEFT, RIGHT, CIRCLE}; void stateControl(); -void speedControl(); void setup() { Serial.begin(9600); diff --git a/SearchingTest/SearchingTest.ino b/SearchingTest/SearchingTest.ino new file mode 100644 index 0000000..a7d89b1 --- /dev/null +++ b/SearchingTest/SearchingTest.ino @@ -0,0 +1,204 @@ +#include +#include +#include "Arduino.h" + +volatile uint8_t state; +enum States_enum {OFF, ON, STOP, FORWARD, SEARCH}; + +volatile uint8_t cmd; +volatile uint8_t off; +enum Movements_enum {halt, forward, backward, left, right, rotate_cw, rotate_ccw, search}; + +/* Pin to turn on/off ground sensor */ +const byte sensorLeds = 13; +/* Pin for analog input from ground sensor */ +const byte analogPin = A0; + +/* Range of colors are partitions of 1023 +const int B_LOW = 300; +const int B_HIGH = 500; +const int R_LOW = 500; +const int R_HIGH = 835; +*/ +// Range of colors are partitions of 1023 +// R = 5.6 kOhms +const int B_LOW = 400; +const int B_HIGH = 700; +const int R_LOW = 700; +const int R_HIGH = 1020; + +const char RED_DO = halt; +const char BLUE_DO = forward; +const char BLACK_DO = search; +const char YELLOW_DO = search; + +/* Set up the ground sensor */ +Bounds bound = {B_LOW, B_HIGH, R_LOW, R_HIGH}; +Instructions instr = {RED_DO, BLUE_DO, BLACK_DO, YELLOW_DO}; +GroundSensor tapeSensor(sensorLeds, analogPin, bound, instr); + +/* Pins for wheel control */ +const byte WheelLeftF = 2; +const byte WheelLeftB = 3; +const byte WheelRightF = 4; +const byte WheelRightB = 5; + +/* Duty Cycle constants */ +const int MAX = 255; +const int TQUARTER = 191; +const int HALF = 127; +const int QUARTER = 64; +const int ZERO = 0; + +/* Constant speed value*/ +const int BEST= 45; + +/* Acceleration time and speed*/ +const int ACC_TIME = 100; +const int ACC_SPD = QUARTER; + +/* Control speed of each state*/ +const int FWD_SPD = QUARTER; +const int BCK_SPD = QUARTER; +const int LFT_SPD = QUARTER; +const int RGT_SPD = QUARTER; +const int RT_CW_SPD = QUARTER; +const int RT_CCW_SPD = QUARTER; + +/* Control the motor */ +Wheels w = {WheelLeftF, WheelLeftB, WheelRightF, WheelRightB}; +Speeds s = {FWD_SPD, BCK_SPD, LFT_SPD, RGT_SPD, RT_CW_SPD, RT_CCW_SPD}; +Accel a = {ACC_TIME, ACC_SPD}; +MotorControl motors(w, s, a); + +/* Time of searching*/ +const int search_time = 5; + +void stateControl(); +void bootSequence(); +void detect(); +void search_side2side(); +void search_back(); +void wait_and_check(); + +void setup() { + Serial.begin(9600); + Serial.println("Searching Test"); // so I can keep track of what is loaded + Serial.println("Bot is OFF"); + state = OFF; + cmd = BLACK_DO; + off = 'n'; + Serial.println("Turn it on? Y/N"); +} + +void loop() { + + switch (state) + { + case OFF: + /* Starting state, wait for user to turn on*/ + while (Serial.available()) { + off = Serial.read(); //gets one byte from serial buffer + if ((off == 'y')) { + state = STOP; + off = 'n'; + delay(2); + } + } + motors.halt(); + digitalWrite(sensorLeds, HIGH); + break; + + case STOP: + motors.halt(); + tapeSensor.senseColor(&cmd); + stateControl(); + break; + + case FORWARD: + motors.forward(); + tapeSensor.senseColor(&cmd); + stateControl(); + break; + + case SEARCH: + tapeSensor.senseColor(&cmd); + stateControl(); + detect(); + break; + } +} + +void stateControl() +{ + if (cmd == forward) { + Serial.println("Going Forward"); + state = FORWARD; + } else if (cmd == search) { + Serial.println("Searching for path"); + state = SEARCH; + } else if (cmd == halt) { + state = STOP; + } + delay(2); //slow loop to allow for change in state + + while (Serial.available()) { + off = Serial.read(); //gets one byte from serial buffer + if (off = 'y') { + state = OFF; + off = 'n'; + delay(2); + } + delay(2); + } +} + +void detect() +{ + motors.halt(); + delay(1000); + search_side2side(); +} + +void wait_and_check() +{ + motors.halt(); + tapeSensor.senseColor(&cmd); + stateControl(); + delay(1000); +} + +void search_back() +{ + while (1) { + motors.backward(); + delay(search_time * 100); + wait_and_check(); + if (state != SEARCH) { + return; + } + } +} + +void search_side2side() +{ + motors.ccw(); + delay(search_time * 100); + wait_and_check(); + if (state != SEARCH) { + return; + } + motors.cw(); + delay((search_time) * 200); + wait_and_check(); + if (state != SEARCH) { + return; + } + motors.ccw(); + delay(search_time * 100); + wait_and_check(); + if (state != SEARCH) { + return; + } + search_back(); +} diff --git a/libraries/GroundSensor/GroundSensor.cpp b/libraries/GroundSensor/GroundSensor.cpp index 278462c..7bd75aa 100644 --- a/libraries/GroundSensor/GroundSensor.cpp +++ b/libraries/GroundSensor/GroundSensor.cpp @@ -1,38 +1,134 @@ #include "Arduino.h" #include "GroundSensor.h" -GroundSensor::GroundSensor(int sensorPin, int analogPin, - Bounds b, Instructions i) +GroundSensor::GroundSensor(int sensorPin, int analogPin, + Bounds b, Instructions i) { - pinMode(sensorPin, OUTPUT); - _sensorPin = sensorPin; - _analogPin = analogPin; - _bound = b; - _inst = i; + pinMode(sensorPin, OUTPUT); + _sensorPin = sensorPin; + _analogPin = analogPin; + _bound = b; + _inst = i; + _voltage = 0; + _current_color = black; + /* Default transtion delay is 500 ms*/ + _transition_delay = 500; +} + +GroundSensor::GroundSensor(int sensorPin, int analogPin, + Bounds b, Instructions i, int transition_delay) +{ + pinMode(sensorPin, OUTPUT); + _sensorPin = sensorPin; + _analogPin = analogPin; + _bound = b; + _inst = i; + _voltage = 0; + _current_color = black; + _transition_delay = transition_delay; +} + +void GroundSensor::transition() +{ + /* We know that the command doesn't matches its color*/ + /* Wait for some time before getting another reading*/ + delay(_transition_delay); + _voltage = analogRead(_analogPin); + get_color(); +} + +bool GroundSensor::is_black() +{ + return (_voltage < _bound.b_low); +} + +bool GroundSensor::is_blue() +{ + return (_voltage >= _bound.b_low) && (_voltage <= _bound.b_high); +} + +bool GroundSensor::is_red() +{ + return (_voltage > _bound.r_low) && (_voltage <= _bound.r_high); +} + +bool GroundSensor::is_yellow() +{ + return (_voltage > _bound.r_high); +} + +bool GroundSensor::is_different_color(volatile uint8_t *command) +{ + /* Check if current command matches the color the sensor just received*/ + bool still_blue = (*command == _inst.blue_do) && (is_blue()); + bool still_red = (*command == _inst.red_do) && (is_red()); + bool still_yellow = (*command == _inst.yellow_do) && (is_yellow()); + bool still_black = (*command == _inst.black_do) && (is_black()); + + bool is_different = !(still_blue || still_red || still_yellow + || still_black); + + return is_different; +} + +void GroundSensor::get_color() +{ + if (is_red()) + { + _current_color = red; + } + else if (is_blue()) + { + _current_color = blue; + } + else if (is_black()) + { + _current_color = black; + } + else if (is_yellow()) + { + _current_color = yellow; + } } void GroundSensor::senseColor(volatile uint8_t *command) { - int voltage = analogRead(_analogPin); - bool is_black = voltage < _bound.b_low; - bool is_blue = (voltage >= _bound.b_low) and (voltage <= _bound.b_high); - bool is_red = (voltage > _bound.r_low) and (voltage <= _bound.r_high); - bool is_yellow = voltage > _bound.r_high; - - if (is_black) { - Serial.println("Detected Black"); - *command = _inst.black_do; - } else if (is_blue) { - Serial.println("Detected Blue"); - *command = _inst.blue_do; - } else if (is_red) { - Serial.println("Detected Red"); - *command = _inst.red_do; - } else if (is_yellow) { - Serial.println("Detected Yellow"); - *command = _inst.yellow_do; - } else { - Serial.println("Invalid voltage detected! Check Code!"); - *command = 's'; - } + _voltage = analogRead(_analogPin); + if (is_different_color(command)) + { + Serial.println("Different Color!"); + transition(); + } + else + { + get_color(); + } + + if (_current_color == black) + { + Serial.println("Detected Black"); + *command = _inst.black_do; + } + else if (_current_color == blue) + { + Serial.println("Detected Blue"); + *command = _inst.blue_do; + } + else if (_current_color == red) + { + Serial.println("Detected Red"); + *command = _inst.red_do; + } + else if (_current_color == yellow) + { + Serial.println("Detected Yellow"); + *command = _inst.yellow_do; + } + else + { + /* Voltage spikes, don't want these*/ + Serial.println("Invalid _voltage detected! Check Code!"); + *command = 0; + } + //Serial.println(_voltage); } diff --git a/libraries/GroundSensor/GroundSensor.h b/libraries/GroundSensor/GroundSensor.h index 3e5710e..25cc8ba 100644 --- a/libraries/GroundSensor/GroundSensor.h +++ b/libraries/GroundSensor/GroundSensor.h @@ -3,6 +3,8 @@ #include "Arduino.h" +enum Color_enum{red, blue, black, yellow}; + struct Bounds { int b_low, b_high, r_low, r_high; }; @@ -14,12 +16,46 @@ struct Instructions { class GroundSensor { public: + /* Set up the Ground Sensor with default transtion delay*/ GroundSensor(int sensorPin, int analogPin, Bounds b, Instructions i); + + /* Set up the Ground Sensor with custom transition delay*/ + GroundSensor(int sensorPin, int analogPin, Bounds b, Instructions i, + int transition_delay); + + /* Change the command based on color sensed*/ void senseColor(volatile uint8_t *command); private: + /* Pins for sensor and leds*/ int _sensorPin, _analogPin; + + /* Bounds for colors' voltages*/ Bounds _bound; + + /* Set of command based on color*/ Instructions _inst; + + /* Detected voltage*/ + int _voltage; + + /* Current color*/ + int _current_color; + + /* How long to wait until we get a second reading in case of a + * transtion of color + */ + int _transition_delay; + + /* Helper functions*/ + bool is_red(); + bool is_blue(); + bool is_black(); + bool is_yellow(); + + bool is_different_color(volatile uint8_t *command); + void get_color(); + + void transition(); }; #endif diff --git a/libraries/MotorControl/MotorControl.cpp b/libraries/MotorControl/MotorControl.cpp index 6b04857..7be1b65 100644 --- a/libraries/MotorControl/MotorControl.cpp +++ b/libraries/MotorControl/MotorControl.cpp @@ -10,8 +10,20 @@ const int ZERO = 0; enum Movements_enum {FORWARD, BACK, LEFT, RIGHT, CW, CCW}; +MotorControl::MotorControl(Wheels w, Speeds s, Accel a) +{ + pinMode(w.leftF, OUTPUT); + pinMode(w.leftB, OUTPUT); + pinMode(w.rightF, OUTPUT); + pinMode(w.rightB, OUTPUT); + _w = w; + _s = s; + _a = a; + _adjust = {0, 0}; + from_stop = true; +} -MotorControl::MotorControl(Wheels w, Speeds s) +MotorControl::MotorControl(Wheels w, Speeds s, Accel a, Adjust adjust) { pinMode(w.leftF, OUTPUT); pinMode(w.leftB, OUTPUT); @@ -19,6 +31,9 @@ MotorControl::MotorControl(Wheels w, Speeds s) pinMode(w.rightB, OUTPUT); _w = w; _s = s; + _a = a; + _adjust = adjust; + from_stop = true; } void MotorControl::allPinsOpen() @@ -32,43 +47,63 @@ void MotorControl::allPinsOpen() void MotorControl::halt() { allPinsOpen(); + from_stop = true; } void MotorControl::forward() { - _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + _m = {_w.leftB, _w.rightB, _w.leftF + _adjust.left_adj, + _w.rightF + _adjust.right_adj}; driveMotor(FORWARD); } void MotorControl::backward() { - _m = {_w.leftF, _w.rightF, _w.leftB, _w.rightB}; + _m = {_w.leftF, _w.rightF, _w.leftB + _adjust.left_adj, + _w.rightB + _adjust.right_adj}; driveMotor(BACK); } void MotorControl::left() { - _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + _m = {_w.leftB, _w.rightB, _w.leftF + _adjust.left_adj, + _w.rightF + _adjust.right_adj}; driveMotor(LEFT); } void MotorControl::right() { - _m = {_w.leftB, _w.rightB, _w.leftF, _w.rightF}; + _m = {_w.leftB, _w.rightB, _w.leftF + _adjust.left_adj, + _w.rightF + _adjust.right_adj}; driveMotor(RIGHT); } void MotorControl::cw() { - _m = {_w.leftB, _w.rightF, _w.leftF, _w.rightB}; + _m = {_w.leftB, _w.rightF, _w.leftF + _adjust.left_adj, + _w.rightB + _adjust.right_adj}; driveMotor(CW); } void MotorControl::ccw() { - _m = {_w.leftB, _w.rightF, _w.leftB, _w.rightF}; + _m = {_w.leftB, _w.rightF, _w.leftB + _adjust.left_adj, + _w.rightF + _adjust.right_adj}; driveMotor(CCW); } +void MotorControl::accelerate() +{ + if (from_stop == true) { + Serial.println("Accelerate!"); + digitalWrite(_m.w1, LOW); + digitalWrite(_m.w2, LOW); + analogWrite(_m.w3, _a.speed); + analogWrite(_m.w4, _a.speed); + delay(_a.accel_time); + from_stop = false; + } +} + void MotorControl::driveMotor(int movement) { digitalWrite(_m.w1, LOW); @@ -77,31 +112,37 @@ void MotorControl::driveMotor(int movement) switch (movement) { case FORWARD: + accelerate(); analogWrite(_m.w3, _s.forward); analogWrite(_m.w4, _s.forward); break; case BACK: + accelerate(); analogWrite(_m.w3, _s.backward); analogWrite(_m.w4, _s.left); break; case LEFT: + accelerate(); analogWrite(_m.w3, ZERO); analogWrite(_m.w4, _s.left); break; case RIGHT: + accelerate(); analogWrite(_m.w3, _s.right); analogWrite(_m.w4, ZERO); break; case CW: + accelerate(); analogWrite(_m.w3, _s.cw); analogWrite(_m.w4, _s.cw); break; case CCW: + accelerate(); analogWrite(_m.w3, _s.ccw); analogWrite(_m.w4, _s.ccw); break; diff --git a/libraries/MotorControl/MotorControl.h b/libraries/MotorControl/MotorControl.h index 3988f55..fe43cd2 100644 --- a/libraries/MotorControl/MotorControl.h +++ b/libraries/MotorControl/MotorControl.h @@ -11,29 +11,50 @@ struct Speeds { int forward, backward, left, right, cw, ccw; }; +struct Adjust { + int left_adj, right_adj; +}; + +struct Accel { + int accel_time, speed; +}; + + class MotorControl { - public: - MotorControl(Wheels w, Speeds s); - void halt(); - void forward(); - void backward(); - void left(); - void right(); - void cw(); - void ccw(); - - private: - struct Movement { - int w1, w2, w3, w4; - }; - - Wheels _w; - Speeds _s; - Movement _m; - - void driveMotor(int movement); - void allPinsOpen(); + public: + /* Set up Motor Control with default adjustment */ + MotorControl(Wheels w, Speeds s, Accel a); + + /* Set up Motor Control with user's adjustments */ + /* Adjust wheels' speed so bot run straighter*/ + MotorControl(Wheels w, Speeds s, Accel a, Adjust adjust); + + /* Movement functions*/ + void halt(); + void forward(); + void backward(); + void left(); + void right(); + void cw(); + void ccw(); + + private: + struct Movement { + int w1, w2, w3, w4; + }; + + Wheels _w; + Speeds _s; + Adjust _adjust; + Movement _m; + + bool from_stop; + Accel _a; + + void driveMotor(int movement); + void accelerate(); + void allPinsOpen(); }; #endif -- GitLab From c540eab525a1903dc9d84fe1d0f304f2b80ccb78 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Sun, 23 Feb 2020 01:40:20 -0500 Subject: [PATCH 26/28] More descriptions on the files --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/README.md b/README.md index 339005b..3bc3974 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,58 @@ Swarm Bot Project The goal of this semester-long project is to model and simulate the navigation and environmental sensing of autonomous vehicles by designing an intelligent swarmbot team using a community of two bots. The two bots are to work together, collaborating to solve the problem of safe navigation. + +Libraries: + +FourPinControl - setup four pins as OUTPUT then control them using public functions. KINDA WORKS... + +PinControl - setup one pin as OUTPUT and control it using public functions. WORKS but do we need this? + +GroundSensor - handles color sensing and outputs a command. + Inputs: + - Bounds for blue and red LEDs voltage reading + - NOTE: will need to change these a lot based on testing and observation + - Instructions on what the command should be for each color sense + NOTE: Now handles color transition + +MotorControl - controls the motors. + Inputs: + - Wheels' pins + - Speeds for each direction of movement + - Accel holds the accelartion time and acceleration speed + - Adjust helps make the wheels travel straighter + NOTE: Now handles acceleartion and individual wheel's speed adjustments + + +Relevant Folders: + +AnalogInReadTest - takes in voltage reading and print out their their Arduino value on Serial monitor. + +DistanceTest - makes the bot move forward or backward for a certain time. + +DriveMotorTest - drive motors forward and backward at certain speed from Serial input. + +FollowLineUsingLib - make the bot do certain tasks based on the color it sensed. Use custom libraries. + +GroundSensorTest - use the color sensor to sense color of tapes. Print result on Serial monitor. + +HallSensorTest - use the hall sensor to stop when it sense a magnetic field. UNTESTED! + +HallSensorTestBasic - light up an LED based on hall sensor reading. UNTESTED! + +MotionControl - control bots movement using Serial input. NEED MODIFICATION! + +SearchingTest - test some searching algorithm. + + +Old Folders: + +DriveMotorMiniTest - turn an LED on and off using Serial input. + +FollowTheLine - make bot do certain tasks based on color it sensed. OUTDATED! + +GenerateOutOfPhaseTest - tried to generate two signals out of phase. OUTDATED! UNECCESSARY! + +LockedAntiphase - drive two motors. OUTDATED! + +StateMachine - light up some LED based on the state. State is change using Serial input. OLD! -- GitLab From 842f8335a7dedae2eac9cfd87bafee42de872545 Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Sun, 23 Feb 2020 02:06:12 -0500 Subject: [PATCH 27/28] More readable --- README.md | 56 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 3bc3974..e1719c9 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,61 @@ # JuniorDesign -Swarm Bot Project +**Swarm Bot Project** The goal of this semester-long project is to model and simulate the navigation and environmental sensing of autonomous vehicles by designing an intelligent swarmbot team using a community of two bots. The two bots are to work together, collaborating to solve the problem of safe navigation. -Libraries: +## Libraries: -FourPinControl - setup four pins as OUTPUT then control them using public functions. KINDA WORKS... +**FourPinControl** - setup four pins as OUTPUT then control them using public functions. KINDA WORKS. -PinControl - setup one pin as OUTPUT and control it using public functions. WORKS but do we need this? +**PinControl** - setup one pin as OUTPUT and control it using public functions. WORKS but do we need this? -GroundSensor - handles color sensing and outputs a command. - Inputs: +**GroundSensor** - handles color sensing and outputs a command. +
Inputs: 
+
- Bounds for blue and red LEDs voltage reading - NOTE: will need to change these a lot based on testing and observation - Instructions on what the command should be for each color sense NOTE: Now handles color transition - -MotorControl - controls the motors. - Inputs: - - Wheels' pins + +**MotorControl** - controls the motors. +
Inputs: 
+
+ - Wheels' pins. Indicate four pins for left and right motors - Speeds for each direction of movement - Accel holds the accelartion time and acceleration speed - Adjust helps make the wheels travel straighter NOTE: Now handles acceleartion and individual wheel's speed adjustments +## Relevant Folders: -Relevant Folders: - -AnalogInReadTest - takes in voltage reading and print out their their Arduino value on Serial monitor. - -DistanceTest - makes the bot move forward or backward for a certain time. +**AnalogInReadTest** - takes in voltage reading and print out their their Arduino value on Serial monitor. -DriveMotorTest - drive motors forward and backward at certain speed from Serial input. +**DistanceTest** - makes the bot move forward or backward for a certain time. -FollowLineUsingLib - make the bot do certain tasks based on the color it sensed. Use custom libraries. +**DriveMotorTest** - drive motors forward and backward at certain speed from Serial input. -GroundSensorTest - use the color sensor to sense color of tapes. Print result on Serial monitor. +**FollowLineUsingLib** - make the bot do certain tasks based on the color it sensed. Use custom libraries. -HallSensorTest - use the hall sensor to stop when it sense a magnetic field. UNTESTED! +**GroundSensorTest** - use the color sensor to sense color of tapes. Print result on Serial monitor. -HallSensorTestBasic - light up an LED based on hall sensor reading. UNTESTED! +**HallSensorTest** - use the hall sensor to stop when it sense a magnetic field. UNTESTED! -MotionControl - control bots movement using Serial input. NEED MODIFICATION! +**HallSensorTestBasic** - light up an LED based on hall sensor reading. UNTESTED! -SearchingTest - test some searching algorithm. +**MotionControl** - control bots movement using Serial input. NEED MODIFICATION! +**SearchingTest** - test some searching algorithm. -Old Folders: +## Old Folders: -DriveMotorMiniTest - turn an LED on and off using Serial input. +~~DriveMotorMiniTest~~ - turn an LED on and off using Serial input. -FollowTheLine - make bot do certain tasks based on color it sensed. OUTDATED! +~~FollowTheLine~~ - make bot do certain tasks based on color it sensed. OUTDATED! -GenerateOutOfPhaseTest - tried to generate two signals out of phase. OUTDATED! UNECCESSARY! +~~GenerateOutOfPhaseTest~~ - tried to generate two signals out of phase. OUTDATED! UNECCESSARY! -LockedAntiphase - drive two motors. OUTDATED! +~~LockedAntiphase~~ - drive two motors. OUTDATED! -StateMachine - light up some LED based on the state. State is change using Serial input. OLD! +~~StateMachine~~ - light up some LED based on the state. State is change using Serial input. OLD! -- GitLab From d366afecf007591bafaea7a1a90bed07d48a8f9e Mon Sep 17 00:00:00 2001 From: Luan Banh <49538471+luanbanh@users.noreply.github.com> Date: Sun, 23 Feb 2020 02:06:47 -0500 Subject: [PATCH 28/28] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e1719c9..882f186 100644 --- a/README.md +++ b/README.md @@ -13,20 +13,20 @@ the problem of safe navigation. **GroundSensor** - handles color sensing and outputs a command.
Inputs: 
-
- Bounds for blue and red LEDs voltage reading - NOTE: will need to change these a lot based on testing and observation - Instructions on what the command should be for each color sense NOTE: Now handles color transition + **MotorControl** - controls the motors.
Inputs: 
-
- Wheels' pins. Indicate four pins for left and right motors - Speeds for each direction of movement - Accel holds the accelartion time and acceleration speed - Adjust helps make the wheels travel straighter NOTE: Now handles acceleartion and individual wheel's speed adjustments + ## Relevant Folders: -- GitLab