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

Commit 5d8d825

Browse files
Ran clang-format on code and added some more comments
1 parent fc49d26 commit 5d8d825

File tree

3 files changed

+81
-64
lines changed

3 files changed

+81
-64
lines changed

arduino_controller/arduino_controller.ino

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include <String.h>
21
#include <Servo.h>
2+
#include <String.h>
33

44
// constants
5-
#define DEBOUNCE_TIME .5
6-
#define SAMPLE_FREQUENCY 20
7-
#define MAXIMUM (DEBOUNCE_TIME * SAMPLE_FREQUENCY)
5+
#define DEBOUNCE_TIME .5
6+
#define SAMPLE_FREQUENCY 20
7+
#define MAXIMUM (DEBOUNCE_TIME * SAMPLE_FREQUENCY)
88
#define NUMBER_MOTORS 2
99

1010
// function declarations
@@ -20,34 +20,37 @@ bool newData = false;
2020
// initialize motors
2121
Servo myServo[NUMBER_MOTORS];
2222
// create a array of ports with the order: motor, counter, reset
23-
int ports[NUMBER_MOTORS][3] = {{2, 3, 4},{5, 6, 7}};
23+
int ports[NUMBER_MOTORS][3] = {{2, 3, 4}, {5, 6, 7}};
2424

2525
// string array of motor directions
26-
String motor_direction[NUMBER_MOTORS] = {""};;
27-
// array of how many rotations a motor has to go
26+
String motor_direction[NUMBER_MOTORS] = {""};
27+
28+
// array of how many rotations a motor has to go
2829
byte motor_rotation_number[NUMBER_MOTORS] = {0};
2930
// array of new switch values
30-
byte motor_sensor_counter1[NUMBER_MOTORS] = {0};;
31+
byte motor_sensor_counter1[NUMBER_MOTORS] = {0};
32+
3133
// array of old switch values
32-
byte motor_sensor_counter2[NUMBER_MOTORS] = {0};;
34+
byte motor_sensor_counter2[NUMBER_MOTORS] = {0};
3335

3436
// 0 or 1 depending on the input signal
3537
byte input[NUMBER_MOTORS] = {0};
36-
// will range from 0 to the specified MAXIMUM
38+
// will range from 0 to the specified MAXIMUM
3739
int integrator[NUMBER_MOTORS] = {0};
3840
// cleaned-up version of the input signal
39-
byte output[NUMBER_MOTORS]= {0};;
41+
byte output[NUMBER_MOTORS] = {0};
4042

41-
42-
void setup() {
43+
void setup()
44+
{
4345
// setup serial port
4446
Serial.begin(9600);
45-
47+
4648
// initialize all motor ports
4749
Serial.println("Begining Initialization");
4850
Serial.print("Motor Ports: ");
49-
for (int i = 0; i < NUMBER_MOTORS; i++) {
50-
int x = ports[i][0];\
51+
for (int i = 0; i < NUMBER_MOTORS; i++)
52+
{
53+
int x = ports[i][0];
5154
Serial.print(x);
5255
Serial.print(" ");
5356
myServo[i].attach(x);
@@ -56,7 +59,8 @@ void setup() {
5659
// initialize all counter ports
5760
Serial.println("");
5861
Serial.print("Counter Ports: ");
59-
for (int i = 0; i < NUMBER_MOTORS; i++) {
62+
for (int i = 0; i < NUMBER_MOTORS; i++)
63+
{
6064
int x = ports[i][1];
6165
Serial.print(x);
6266
Serial.print(" ");
@@ -66,7 +70,8 @@ void setup() {
6670
// initialize all reset ports
6771
Serial.println("");
6872
Serial.print("Reset Ports: ");
69-
for (int i = 0; i < NUMBER_MOTORS; i++) {
73+
for (int i = 0; i < NUMBER_MOTORS; i++)
74+
{
7075
int x = ports[i][2];
7176
Serial.print(x);
7277
Serial.print(" ");
@@ -78,13 +83,14 @@ void setup() {
7883
Serial.println(">");
7984
}
8085

81-
82-
void loop() {
86+
void loop()
87+
{
8388
// check to see if there is any new data
8489
RecvWithStartEndMarkers();
8590

8691
// if there is new data process it
87-
if (newData == true) {
92+
if (newData == true)
93+
{
8894
newData = false;
8995
Serial.println("<");
9096
Serial.print("Arduino: ");

arduino_controller/arduino_controller_functions.ino

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

4-
// This file contains funcitons that process the data that is recieved from the raspberry pi
4+
// This file contains funcitons that process the data that is recieved from the
5+
// raspberry pi
56

67
//////////////////////////////////////////////////////////////////////////////
78
//////////////////////////////////////////////////////////////////////////////
89

910
void ProcessData() {
1011

11-
/* // variables
12+
/* // variables
1213
String recievedString = "";
1314
String motor_rotation_string = "";
1415
String motor_rotation_string2 = "";
@@ -73,16 +74,15 @@ void ProcessData() {
7374

7475
// Send Finished Signal
7576
Finished();
76-
7777
}
7878

7979
//////////////////////////////////////////////////////////////////////////////
8080
//////////////////////////////////////////////////////////////////////////////
8181

8282
void checkswitch(int switchPort) {
8383
// /* Step 1: Update the integrator based on the input signal. Note that the
84-
// integrator follows the input, decreasing or increasing towards the limits as
85-
// determined by the input state (0 or 1). */
84+
// integrator follows the input, decreasing or increasing towards the limits
85+
// as determined by the input state (0 or 1). */
8686
// input = digitalRead(switchPort);
8787

8888
// if (input == 0)
@@ -94,8 +94,8 @@ void checkswitch(int switchPort) {
9494
// integrator++;
9595

9696
// /* Step 2: Update the output state based on the integrator. Note that the
97-
// output will only change states if the integrator has reached a limit, either
98-
// 0 or MAXIMUM. */
97+
// output will only change states if the integrator has reached a limit,
98+
// either 0 or MAXIMUM. */
9999

100100
// if (integrator == 0)
101101
// output = 0;
@@ -105,10 +105,10 @@ void checkswitch(int switchPort) {
105105
// integrator = MAXIMUM; /* defensive code if integrator got corrupted */
106106
// }
107107

108-
// /********************************************************* End of debounce.c */
108+
// /********************************************************* End of
109+
// debounce.c */
109110
}
110111

111-
112112
/* void Reset1() {
113113
myservo1.write(100);
114114
while(true) {

arduino_controller/communications.ino

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,84 @@
11
//////////////////////////////////////////////////////////////////////////////
22
//////////////////////////////////////////////////////////////////////////////
33

4-
// This file contains funcitons that help the arduino communitate with the raspberry pi
4+
// This file contains funcitons that help the arduino communitate with the
5+
// raspberry pi
56

67
//////////////////////////////////////////////////////////////////////////////
78
//////////////////////////////////////////////////////////////////////////////
89

910
// handles the recieving of data over the serial port
10-
void RecvWithStartEndMarkers() {
11-
static boolean recvInProgress = false;
12-
static byte ndx = 0;
13-
char startMarker = '<';
14-
char endMarker = '>';
15-
char rc;
11+
void RecvWithStartEndMarkers()
12+
{
13+
static boolean recvInProgress = false;
14+
static byte ndx = 0;
15+
char startMarker = '<';
16+
char endMarker = '>';
17+
char rc;
1618

17-
while (Serial.available() > 0 && newData == false) {
18-
rc = Serial.read();
19+
while (Serial.available() > 0 && newData == false)
20+
{
21+
rc = Serial.read();
1922

20-
if (recvInProgress == true) {
21-
if (rc != endMarker) {
22-
receivedChars[ndx] = rc;
23-
ndx++;
24-
if (ndx >= numChars) {
25-
ndx = numChars - 1;
23+
if (recvInProgress == true)
24+
{
25+
if (rc != endMarker)
26+
{
27+
receivedChars[ndx] = rc;
28+
ndx++;
29+
if (ndx >= numChars)
30+
{
31+
ndx = numChars - 1;
32+
}
33+
}
34+
else
35+
{
36+
receivedChars[ndx] = '\0'; // terminate the string
37+
recvInProgress = false;
38+
ndx = 0;
39+
newData = true;
40+
}
2641
}
27-
}
28-
else {
29-
receivedChars[ndx] = '\0'; // terminate the string
30-
recvInProgress = false;
31-
ndx = 0;
32-
newData = true;
33-
}
34-
}
3542

36-
else if (rc == startMarker) {
37-
recvInProgress = true;
43+
else if (rc == startMarker)
44+
{
45+
recvInProgress = true;
46+
}
3847
}
39-
}
40-
4148
}
4249

4350
// helps get a particular value from the incoming data string
4451
String getValue(String data, char separator, int index)
4552
{
4653
int found = 0;
47-
int strIndex[] = { 0, -1 };
54+
int strIndex[] = {0, -1};
4855
int maxIndex = data.length() - 1;
4956

50-
for (int i = 0; i <= maxIndex && found <= index; i++) {
51-
if (data.charAt(i) == separator || i == maxIndex) {
57+
for (int i = 0; i <= maxIndex && found <= index; i++)
58+
{
59+
if (data.charAt(i) == separator || i == maxIndex)
60+
{
5261
found++;
5362
strIndex[0] = strIndex[1] + 1;
54-
strIndex[1] = (i == maxIndex) ? i+1 : i;
63+
strIndex[1] = (i == maxIndex) ? i + 1 : i;
5564
}
5665
}
5766
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
5867
}
5968

6069
// sends message back to raspberry pi saying the command has been executed
61-
void Finished() {
70+
void Finished()
71+
{
6272
Serial.println("Finished Current Job");
6373
Serial.println("---------");
6474
Serial.println("Ready for New Job");
6575
Serial.println(">");
6676
}
6777

6878
// sends error message back to raspberry pi
69-
void Invalid() {
70-
Serial.println("<");
79+
void Invalid()
80+
{
81+
Serial.println("<");
7182
Serial.print("Arduino: ");
7283
Serial.println("Invalid Input!");
7384
Serial.println(">");

0 commit comments

Comments
 (0)