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

Commit 722ce2f

Browse files
Formatting Arduino Code
1 parent 016e785 commit 722ce2f

File tree

4 files changed

+85
-87
lines changed

4 files changed

+85
-87
lines changed

arduino_controller/arduino_controller.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool new_data = false;
2727
Servo my_servo[NUMBER_MOTORS];
2828
// create a array of ports with the order: motor, counter, reset
2929
// int ports[NUMBER_MOTORS][3] = {{62, 66, 67}};
30-
int ports[NUMBER_MOTORS][3] = {{2, 3, 4},{5, 6, 7},{8, 9, 10}};
30+
int ports[NUMBER_MOTORS][3] = {{2, 3, 4}, {5, 6, 7}, {8, 9, 10}};
3131
// integer array that contains the direction and number of rotations a motor
3232
// needs to go
3333
int motor_commands[NUMBER_MOTORS][2] = {0};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//////////////////////////////////////////////////////////////////////////////
2+
//////////////////////////////////////////////////////////////////////////////
3+
4+
// This file contains functions that help the arduino communitate with the
5+
// raspberry pi
6+
7+
//////////////////////////////////////////////////////////////////////////////
8+
//////////////////////////////////////////////////////////////////////////////
9+
10+
// handles the receiving of data over the serial port
11+
void RecvWithStartEndMarkers()
12+
{
13+
static boolean recvInProgress = false;
14+
static byte ndx = 0;
15+
char startMarker = '<';
16+
char endMarker = '>';
17+
char rc;
18+
19+
while (Serial.available() > 0 && new_data == false)
20+
{
21+
rc = Serial.read();
22+
23+
if (recvInProgress == true)
24+
{
25+
if (rc != endMarker)
26+
{
27+
received_chars[ndx] = rc;
28+
ndx++;
29+
if (ndx >= num_chars)
30+
{
31+
ndx = num_chars - 1;
32+
}
33+
}
34+
else
35+
{
36+
received_chars[ndx] = '\0'; // terminate the string
37+
recvInProgress = false;
38+
ndx = 0;
39+
new_data = true;
40+
}
41+
}
42+
43+
else if (rc == startMarker)
44+
{
45+
recvInProgress = true;
46+
}
47+
}
48+
}
49+
50+
// helps get a particular value from the incoming data string
51+
String getValue(String data, char separator, int index)
52+
{
53+
int found = 0;
54+
int strIndex[] = {0, -1};
55+
int maxIndex = data.length() - 1;
56+
57+
for (int i = 0; i <= maxIndex && found <= index; i++)
58+
{
59+
if (data.charAt(i) == separator || i == maxIndex)
60+
{
61+
found++;
62+
strIndex[0] = strIndex[1] + 1;
63+
strIndex[1] = (i == maxIndex) ? i + 1 : i;
64+
}
65+
}
66+
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
67+
}
68+
69+
// sends message back to raspberry pi saying the command has been executed
70+
void Finished()
71+
{
72+
Serial.println("Finished Current Job!");
73+
Serial.println(">");
74+
}
75+
76+
// sends error message back to raspberry pi
77+
void Invalid()
78+
{
79+
Serial.println("<");
80+
Serial.print("Arduino: ");
81+
Serial.println("Invalid Input!");
82+
Serial.println(">");
83+
}

arduino_controller/communications.ino

Lines changed: 0 additions & 85 deletions
This file was deleted.

arduino_controller/arduino_controller_functions.ino renamed to arduino_controller/functions.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void ProcessData()
123123
{
124124
int reset_counter[NUMBER_MOTORS] = {0};
125125

126-
for (int i = 0; i < NUMBER_MOTORS; ++i){
126+
for (int i = 0; i < NUMBER_MOTORS; ++i) {
127127
reset_counter[i] = 1;
128128
}
129129

0 commit comments

Comments
 (0)