Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit fc49d26

Browse files
Cleaned up code and added comments
1 parent 2439ca6 commit fc49d26

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

arduino_controller/arduino_controller.ino

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <String.h>
22
#include <Servo.h>
33

4+
// constants
45
#define DEBOUNCE_TIME .5
56
#define SAMPLE_FREQUENCY 20
67
#define MAXIMUM (DEBOUNCE_TIME * SAMPLE_FREQUENCY)
7-
88
#define NUMBER_MOTORS 2
99

1010
// function declarations
@@ -19,13 +19,16 @@ bool newData = false;
1919

2020
// initialize motors
2121
Servo myServo[NUMBER_MOTORS];
22-
// create a array of ports. Each line corresponds to the motor number starting from 0.
23-
// the order of the ports is motor, counter, reset
22+
// create a array of ports with the order: motor, counter, reset
2423
int ports[NUMBER_MOTORS][3] = {{2, 3, 4},{5, 6, 7}};
2524

25+
// string array of motor directions
2626
String motor_direction[NUMBER_MOTORS] = {""};;
27+
// array of how many rotations a motor has to go
2728
byte motor_rotation_number[NUMBER_MOTORS] = {0};
29+
// array of new switch values
2830
byte motor_sensor_counter1[NUMBER_MOTORS] = {0};;
31+
// array of old switch values
2932
byte motor_sensor_counter2[NUMBER_MOTORS] = {0};;
3033

3134
// 0 or 1 depending on the input signal
@@ -35,7 +38,9 @@ int integrator[NUMBER_MOTORS] = {0};
3538
// cleaned-up version of the input signal
3639
byte output[NUMBER_MOTORS]= {0};;
3740

41+
3842
void setup() {
43+
// setup serial port
3944
Serial.begin(9600);
4045

4146
// initialize all motor ports
@@ -73,8 +78,17 @@ void setup() {
7378
Serial.println(">");
7479
}
7580

81+
7682
void loop() {
83+
// check to see if there is any new data
7784
RecvWithStartEndMarkers();
78-
ShowNewData();
79-
}
8085

86+
// if there is new data process it
87+
if (newData == true) {
88+
newData = false;
89+
Serial.println("<");
90+
Serial.print("Arduino: ");
91+
Serial.println(receivedChars);
92+
ProcessData();
93+
}
94+
}

arduino_controller/arduino_controller_functions.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//////////////////////////////////////////////////////////////////////////////
22
//////////////////////////////////////////////////////////////////////////////
33

4+
// This file contains funcitons that process the data that is recieved from the raspberry pi
5+
6+
//////////////////////////////////////////////////////////////////////////////
7+
//////////////////////////////////////////////////////////////////////////////
8+
49
void ProcessData() {
510

611
/* // variables
@@ -104,9 +109,6 @@ void checkswitch(int switchPort) {
104109
}
105110

106111

107-
108-
109-
110112
/* void Reset1() {
111113
myservo1.write(100);
112114
while(true) {

arduino_controller/communications.ino

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//////////////////////////////////////////////////////////////////////////////
22
//////////////////////////////////////////////////////////////////////////////
33

4+
// This file contains funcitons that help the arduino communitate with the raspberry pi
5+
6+
//////////////////////////////////////////////////////////////////////////////
7+
//////////////////////////////////////////////////////////////////////////////
8+
9+
// handles the recieving of data over the serial port
410
void RecvWithStartEndMarkers() {
511
static boolean recvInProgress = false;
612
static byte ndx = 0;
@@ -34,10 +40,7 @@ void RecvWithStartEndMarkers() {
3440

3541
}
3642

37-
//////////////////////////////////////////////////////////////////////////////
38-
//////////////////////////////////////////////////////////////////////////////
39-
40-
43+
// helps get a particular value from the incoming data string
4144
String getValue(String data, char separator, int index)
4245
{
4346
int found = 0;
@@ -54,35 +57,15 @@ String getValue(String data, char separator, int index)
5457
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
5558
}
5659

57-
//////////////////////////////////////////////////////////////////////////////
58-
//////////////////////////////////////////////////////////////////////////////
59-
60-
void ShowNewData() {
61-
if (newData == true) {
62-
newData = false;
63-
Serial.println("<");
64-
Serial.print("Arduino: ");
65-
Serial.println(receivedChars);
66-
// NOT SURE IF I NEED THIS MARKER
67-
// Serial.println(" >");
68-
// From here we execute the commands that were send via the message
69-
ProcessData();
70-
}
71-
}
72-
73-
//////////////////////////////////////////////////////////////////////////////
74-
//////////////////////////////////////////////////////////////////////////////
75-
60+
// sends message back to raspberry pi saying the command has been executed
7661
void Finished() {
7762
Serial.println("Finished Current Job");
7863
Serial.println("---------");
7964
Serial.println("Ready for New Job");
8065
Serial.println(">");
8166
}
8267

83-
//////////////////////////////////////////////////////////////////////////////
84-
//////////////////////////////////////////////////////////////////////////////
85-
68+
// sends error message back to raspberry pi
8669
void Invalid() {
8770
Serial.println("<");
8871
Serial.print("Arduino: ");

0 commit comments

Comments
 (0)