Skip to content

Commit c7c4acc

Browse files
committed
Changed acceleration logic for remote controller and enabled connection protocol for steering controller
1 parent 0fd863f commit c7c4acc

File tree

10 files changed

+126
-122
lines changed

10 files changed

+126
-122
lines changed

Steering/Firmware/Remote_Controller/RC_1R1/RC_1R1/RC_1R1.cproj

+77-77
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
<EraseKey />
3131
<AsfFrameworkConfig>
3232
<framework-data>
33-
<options />
34-
<configurations />
35-
<files />
36-
<documentation help="" />
37-
<offline-documentation help="" />
38-
<dependencies>
39-
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.42.0" />
40-
</dependencies>
41-
</framework-data>
33+
<options />
34+
<configurations />
35+
<files />
36+
<documentation help="" />
37+
<offline-documentation help="" />
38+
<dependencies>
39+
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.42.0" />
40+
</dependencies>
41+
</framework-data>
4242
</AsfFrameworkConfig>
4343
<avrtool>com.atmel.avrdbg.tool.ispmk2</avrtool>
4444
<avrtoolserialnumber>000200149999</avrtoolserialnumber>
@@ -60,79 +60,79 @@
6060
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
6161
<ToolchainSettings>
6262
<AvrGcc>
63-
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega328pb"</avrgcc.common.Device>
64-
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
65-
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
66-
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
67-
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
68-
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
69-
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
70-
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
71-
<avrgcc.compiler.symbols.DefSymbols>
72-
<ListValues>
73-
<Value>NDEBUG</Value>
74-
</ListValues>
75-
</avrgcc.compiler.symbols.DefSymbols>
76-
<avrgcc.compiler.directories.IncludePaths>
77-
<ListValues>
78-
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
79-
</ListValues>
80-
</avrgcc.compiler.directories.IncludePaths>
81-
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
82-
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
83-
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
84-
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
85-
<avrgcc.linker.libraries.Libraries>
86-
<ListValues>
87-
<Value>libm</Value>
88-
</ListValues>
89-
</avrgcc.linker.libraries.Libraries>
90-
<avrgcc.assembler.general.IncludePaths>
91-
<ListValues>
92-
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
93-
</ListValues>
94-
</avrgcc.assembler.general.IncludePaths>
95-
</AvrGcc>
63+
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega328pb"</avrgcc.common.Device>
64+
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
65+
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
66+
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
67+
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
68+
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
69+
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
70+
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
71+
<avrgcc.compiler.symbols.DefSymbols>
72+
<ListValues>
73+
<Value>NDEBUG</Value>
74+
</ListValues>
75+
</avrgcc.compiler.symbols.DefSymbols>
76+
<avrgcc.compiler.directories.IncludePaths>
77+
<ListValues>
78+
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
79+
</ListValues>
80+
</avrgcc.compiler.directories.IncludePaths>
81+
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
82+
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
83+
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
84+
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
85+
<avrgcc.linker.libraries.Libraries>
86+
<ListValues>
87+
<Value>libm</Value>
88+
</ListValues>
89+
</avrgcc.linker.libraries.Libraries>
90+
<avrgcc.assembler.general.IncludePaths>
91+
<ListValues>
92+
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
93+
</ListValues>
94+
</avrgcc.assembler.general.IncludePaths>
95+
</AvrGcc>
9696
</ToolchainSettings>
9797
</PropertyGroup>
9898
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
9999
<ToolchainSettings>
100100
<AvrGcc>
101-
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega328pb"</avrgcc.common.Device>
102-
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
103-
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
104-
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
105-
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
106-
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
107-
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
108-
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
109-
<avrgcc.compiler.symbols.DefSymbols>
110-
<ListValues>
111-
<Value>DEBUG</Value>
112-
</ListValues>
113-
</avrgcc.compiler.symbols.DefSymbols>
114-
<avrgcc.compiler.directories.IncludePaths>
115-
<ListValues>
116-
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
117-
</ListValues>
118-
</avrgcc.compiler.directories.IncludePaths>
119-
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
120-
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
121-
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
122-
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
123-
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
124-
<avrgcc.linker.libraries.Libraries>
125-
<ListValues>
126-
<Value>libm</Value>
127-
</ListValues>
128-
</avrgcc.linker.libraries.Libraries>
129-
<avrgcc.assembler.general.IncludePaths>
130-
<ListValues>
131-
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
132-
</ListValues>
133-
</avrgcc.assembler.general.IncludePaths>
134-
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
135-
</AvrGcc>
101+
<avrgcc.common.Device>-mmcu=atmega328pb -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega328pb"</avrgcc.common.Device>
102+
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
103+
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
104+
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
105+
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
106+
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
107+
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
108+
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
109+
<avrgcc.compiler.symbols.DefSymbols>
110+
<ListValues>
111+
<Value>DEBUG</Value>
112+
</ListValues>
113+
</avrgcc.compiler.symbols.DefSymbols>
114+
<avrgcc.compiler.directories.IncludePaths>
115+
<ListValues>
116+
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
117+
</ListValues>
118+
</avrgcc.compiler.directories.IncludePaths>
119+
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
120+
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
121+
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
122+
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
123+
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
124+
<avrgcc.linker.libraries.Libraries>
125+
<ListValues>
126+
<Value>libm</Value>
127+
</ListValues>
128+
</avrgcc.linker.libraries.Libraries>
129+
<avrgcc.assembler.general.IncludePaths>
130+
<ListValues>
131+
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
132+
</ListValues>
133+
</avrgcc.assembler.general.IncludePaths>
134+
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
135+
</AvrGcc>
136136
</ToolchainSettings>
137137
</PropertyGroup>
138138
<ItemGroup>

Steering/Firmware/Remote_Controller/RC_1R1/RC_1R1/controlSend.c

+28-21
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,30 @@ ISR(INT0_vect) {
4848
}
4949

5050
ISR(PCINT0_vect) {
51-
/*usart0_transmit_string("Acc sw trgd.\r\n");*/
5251
if (READ_ACCEL_SW_1) {
5352
accel_sw_1 = true;
54-
//usart0_transmit_string("1\n");
5553
}
5654
else {
5755
accel_sw_1 = false;
5856
}
59-
if (READ_ACCEL_SW_4) {
60-
//usart0_transmit_string("4\n");
61-
accel_sw_4 = true;
62-
}
63-
else {
64-
accel_sw_4 = false;
65-
}
6657
if (READ_ACCEL_SW_2) {
67-
//usart0_transmit_string("2\n");
6858
accel_sw_2 = true;
6959
}
7060
else {
7161
accel_sw_2 = false;
7262
}
7363
if (READ_ACCEL_SW_3) {
74-
//usart0_transmit_string("3\n");
7564
accel_sw_3 = true;
7665
}
7766
else {
7867
accel_sw_3 = false;
7968
}
69+
if (READ_ACCEL_SW_4) {
70+
accel_sw_4 = true;
71+
}
72+
else {
73+
accel_sw_4 = false;
74+
}
8075

8176
}
8277

@@ -103,26 +98,34 @@ void str_data_conversion() {
10398
}
10499

105100
void accel_data_conversion() {
106-
if (accel_sw_4 && accel_sw_3) {
101+
if (accel_sw_1 && !accel_sw_2 && accel_sw_3 && accel_sw_4) {
107102
accel_data = ACCEL_NONE;
103+
//usart0_transmit_string("none");
108104
}
109-
else if (!accel_sw_1 && !accel_sw_2 && accel_sw_3) {
105+
else if (accel_sw_1 && !accel_sw_2 && accel_sw_3 && !accel_sw_4) {
110106
accel_data = ACCEL_LOW;
107+
//usart0_transmit_string("low");
111108
}
112-
else if (accel_sw_1 && !accel_sw_2) {
109+
else if (!accel_sw_1 && !accel_sw_2 && accel_sw_3 && !accel_sw_4) {
113110
accel_data = ACCEL_MEDIUM;
111+
//usart0_transmit_string("medium");
114112
}
115-
else if (accel_sw_2 && accel_sw_3) {
113+
else if (accel_sw_1 && accel_sw_2 && !accel_sw_3 && !accel_sw_4) {
116114
accel_data = ACCEL_HIGH;
115+
//usart0_transmit_string("high");
117116
}
118117
}
119118

120119
void instructionSend() {
121120
set_RTS_flag(false);
121+
// sprintf(input_buffer, "\n\r ADC: %i %i %i %i \n\r", (int16_t)accel_sw_1, (int16_t)accel_sw_2, (int16_t)accel_sw_3, (int16_t)accel_sw_4 );
122+
// usart0_transmit_string(input_buffer);
122123

123124
sendValue = 0b10000000;
124125
sendValue &=~ (1 << FUTURE);
125126

127+
accel_data_conversion();
128+
126129
switch (str_data)
127130
{
128131
case STR_FULL_L:
@@ -160,24 +163,28 @@ void instructionSend() {
160163
switch (accel_data)
161164
{
162165
case ACCEL_HIGH:
163-
//sendValue |= (1 << SPEED_HIGH); // CHANGE THESE!!!!!!!!!!
166+
//usart0_transmit_string("high");
167+
sendValue |= (1 << SPEED_HIGH); // CHANGE THESE!!!!!!!!!!
164168
//sendValue = 65;
165169
break;
166170

167171
case ACCEL_MEDIUM:
168-
//sendValue |= (1 << SPEED_MED);
172+
//usart0_transmit_string("medium");
173+
sendValue |= (1 << SPEED_MED);
169174
//sendValue = 66;
170175
break;
171176

172177
case ACCEL_LOW:
173-
//sendValue |= (1 << SPEED_LOW);
178+
//usart0_transmit_string("low");
179+
sendValue |= (1 << SPEED_LOW);
174180
//sendValue = 67;
175181
break;
176182

177183
case ACCEL_NONE:
178-
// sendValue &= ~(1 << SPEED_HIGH);
179-
// sendValue &= ~(1 << SPEED_MED);
180-
// sendValue &= ~(1 << SPEED_LOW);
184+
//usart0_transmit_string("none");
185+
sendValue &= ~(1 << SPEED_HIGH);
186+
sendValue &= ~(1 << SPEED_MED);
187+
sendValue &= ~(1 << SPEED_LOW);
181188
//sendValue = 68;
182189
break;
183190
};

Steering/Firmware/Remote_Controller/RC_1R1/RC_1R1/main.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
volatile uint8_t transmitTimerCounter = 0; // This counter checks if enough time has passed for BLE transmission to occur
2020

2121
ISR(TIMER0_COMPA_vect) {
22-
if (transmitTimerCounter < 60) {
22+
if (transmitTimerCounter < 30) { //SET 20
2323
transmitTimerCounter++;
2424
}
2525
else {
2626
// // Set RTS true for BLE transmission
2727
get_instruction_byte();
28-
//usart0_transmit_string("hello\r\n");
2928
transmitTimerCounter = 0;
3029
}
3130
}
@@ -45,7 +44,6 @@ int main(void)
4544
str_data_conversion();
4645
accel_data_conversion();
4746
instructionSend();
48-
4947
}
5048
}
5149

Steering/Firmware/Remote_Controller/RC_1R1/RC_1R1/timer0.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ void timer0_init(){
1212
TCCR0A |= (1 << WGM01); // Set Timer to CTC mode
1313
TCCR0B |= (1 << CS01) | (1 << CS00); // Set prescaler to 64
1414
OCR0A = 124; // Set timer overflow at 1ms
15-
TIMSK0 |= (1 << OCIE0A);
15+
TIMSK0 |= (1 << OCIE0A);
1616
}

Steering/Firmware/Steering_Controller/Steering_Controller/Steering_Controller/control.c

-15
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
#include "uart.h"
1212
#include "steering.h"
1313

14-
// DEBUGGING
15-
#include <stdio.h> //
16-
#include <string.h> //
17-
char input_buffer[20]; //
18-
1914
// Stores input data
2015
static volatile char input_data;
2116

@@ -69,30 +64,20 @@ void set_turn_angle(){
6964
if(RIGHT_H){
7065
if(HALF_TURN_H){
7166
set_half_r_turn();
72-
sprintf(input_buffer, "Set Output (Half R): %i \n\r", set_point_angle); //
73-
usart0_transmit_string(input_buffer); //
7467
}
7568
else if (FULL_TURN_H){
7669
set_full_r_turn();
77-
sprintf(input_buffer, "Set Output (Full R): %i \n\r", set_point_angle); //
78-
usart0_transmit_string(input_buffer); //
7970
}
8071
} // LEFT TURN
8172
else{
8273
if(HALF_TURN_H){
8374
set_half_l_turn();
84-
sprintf(input_buffer, "Set Output (Half L): %i \n\r", set_point_angle); //
85-
usart0_transmit_string(input_buffer); //
8675
}
8776
else if (FULL_TURN_H){
8877
set_full_l_turn();
89-
sprintf(input_buffer, "Set Output (Full R): %i \n\r", set_point_angle); //
90-
usart0_transmit_string(input_buffer); //
9178
}
9279
else{
9380
set_straight_turn();
94-
sprintf(input_buffer, "Set Output (Straight): %i \n\r", set_point_angle); //
95-
usart0_transmit_string(input_buffer); //
9681
}
9782
}
9883
}

Steering/Firmware/Steering_Controller/Steering_Controller/Steering_Controller/global.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ uint16_t turn_range;
4444
volatile int16_t t_on;
4545

4646
// Timeout Counter
47-
#define MAX_TIMEOUT_COUNT 50 // in ms
47+
#define STATE_CONNECT_COUNT 500 // in ms
48+
#define MAX_TIMEOUT_COUNT 500 // in ms
4849
volatile uint8_t timeout_count;
4950

5051
// Calibration timer

Steering/Firmware/Steering_Controller/Steering_Controller/Steering_Controller/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int main(void)
3030

3131
sei();
3232
while (1) {
33-
33+
3434
}
3535
}
3636

Steering/Firmware/Steering_Controller/Steering_Controller/Steering_Controller/pi_controller.c

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ static volatile int16_t input;
1818
static volatile int16_t integrator;
1919
static volatile int16_t set_output;
2020

21+
22+
#include <stdio.h> //
23+
#include <string.h> //
24+
char input_buffer[20]; //
25+
2126
// PI Controller Function
2227
void pi_controller(){
2328
input = adc_read(); // Reads current input

0 commit comments

Comments
 (0)