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

Commit 7ac6190

Browse files
Fixed Code Bugs
1 parent f6eca1e commit 7ac6190

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed
8 Bytes
Binary file not shown.
4.19 MB
Binary file not shown.
8 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.

arduino_controller/arduino_controller.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define SAMPLE_FREQUENCY 20
77
#define MAXIMUM (DEBOUNCE_TIME * SAMPLE_FREQUENCY)
88
#define NUMBER_MOTORS 2
9+
// #define NUMBER_MOTORS 3
910

1011
// function declarations
1112
void RecvWithStartEndMarkers();
@@ -22,21 +23,22 @@ bool new_data = false;
2223
Servo my_servo[NUMBER_MOTORS];
2324
// create a array of ports with the order: motor, counter, reset
2425
int ports[NUMBER_MOTORS][3] = {{2, 3, 4}, {5, 6, 7}};
26+
// int ports[NUMBER_MOTORS][3] = {{2, 3, 4}, {5, 6, 7},{8, 9, 10}};
2527

2628
// integer array that contains the direction and number of rotations a motor
2729
// needs to go
2830
int motor_commands[NUMBER_MOTORS][2] = {0};
2931

3032
// array of new switch values
31-
byte motor_sensor_counter1[NUMBER_MOTORS] = {0};
33+
byte motor_sensor_counter1[NUMBER_MOTORS] = {1};
3234

3335
// array of old switch values
34-
byte motor_sensor_counter2[NUMBER_MOTORS] = {0};
36+
byte motor_sensor_counter2[NUMBER_MOTORS] = {1};
3537

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

arduino_controller/arduino_controller_functions.ino

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ void ProcessData()
1111
{
1212

1313
PopulateArray();
14-
1514
// initialize all motors and get them moving
1615
for (int i = 0; i < NUMBER_MOTORS; i++)
1716
{
1817
if (motor_commands[i][0] == 0)
1918
{
2019
my_servo[i].write(100);
20+
Serial.println("Reached Up");
2121
}
2222
else if (motor_commands[i][0] == 1)
2323
{
2424
my_servo[i].write(80);
25+
Serial.println("Reached Down");
2526
}
2627
else if (motor_commands[i][0] == 2)
2728
{
2829
my_servo[i].write(90);
30+
Serial.println("Reached Stopped");
2931
}
3032
else if (motor_commands[i][0] == 3)
3133
{
@@ -34,7 +36,6 @@ void ProcessData()
3436
else
3537
{
3638
// Sends Error Message
37-
Invalid();
3839
}
3940
}
4041

@@ -47,12 +48,17 @@ void ProcessData()
4748
for (int i = 0; i < NUMBER_MOTORS; i++)
4849
{
4950
motor_sensor_counter2[i] = motor_sensor_counter1[i];
50-
motor_sensor_counter1[i] = CheckSwitch(i, ports[i][0]);
51-
51+
motor_sensor_counter1[i] = CheckSwitch(i, ports[i][1]);
52+
5253
if (motor_sensor_counter1[i] == 1 && motor_sensor_counter2[i] == 0)
5354
{
5455
motor_commands[i][1] = motor_commands[i][1] - 1;
5556
}
57+
58+
if (motor_commands[i][1] < 0)
59+
{
60+
motor_commands[i][1] = 0;
61+
}
5662
}
5763
// stop motors that have reached 0
5864
for (int i = 0; i < NUMBER_MOTORS; i++)
@@ -66,7 +72,20 @@ void ProcessData()
6672
for (int i = 0; i < NUMBER_MOTORS; i++)
6773
{
6874
total_turns += motor_commands[i][1];
75+
// Serial.print("Total number of turns in array: ");
76+
// Serial.println(total_turns);
6977
}
78+
// print the total number of turns left for each motor
79+
for (int i = 0; i < NUMBER_MOTORS; i++)
80+
{
81+
Serial.print("Motor ");
82+
Serial.print(i);
83+
Serial.print(": ");
84+
Serial.print(motor_commands[i][1]);
85+
Serial.print(" -- ");
86+
}
87+
Serial.println("");
88+
7089
// exit loop if there are no more motor rotations remaining
7190
if (total_turns <= 0)
7291
{
@@ -130,9 +149,9 @@ void PopulateArray()
130149
{
131150
Serial.print("Motor Number: ");
132151
Serial.print(i);
133-
Serial.print(" - ");
152+
Serial.print(" - Direction: ");
134153
Serial.print(motor_commands[i][0]);
135-
Serial.print(" - ");
154+
Serial.print(" - Rotations: ");
136155
Serial.println(motor_commands[i][1]);
137156
}
138157
}

0 commit comments

Comments
 (0)