► Warning fixes

- Changed all float constants to use f suffix to prevent double conversions
- Removed compile warnings due to HAL_GPIO_* related calls
- Added comms.h with prototypes for functions which were used in main()
- Casts and externs to fix compile warnings in various files.
- Made a bunch of file-local variables static.
- Fixed buzzerFreq/buzzerPattern extern declarations with correct type (uint8_t)
- Since this is C, void func() { } needs to be void func(void) { }, so fixed that in all instances.
These updates follows from @trollcop
This commit is contained in:
EmanuelFeru
2019-06-10 20:18:37 +02:00
parent 9fdbba1c37
commit 43b4f4aa20
8 changed files with 120 additions and 91 deletions

View File

@@ -19,10 +19,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h> // for abs()
#include "stm32f1xx_hal.h"
#include "defines.h"
#include "setup.h"
#include "config.h"
#include "comms.h"
//#include "hd44780.h"
// Matlab includes and defines - from auto-code generation
@@ -47,6 +49,7 @@ ExtY rtY_Right; /* External outputs */
// ###############################################################################
void SystemClock_Config(void);
void poweroff(void);
extern TIM_HandleTypeDef htim_left;
extern TIM_HandleTypeDef htim_right;
@@ -57,8 +60,8 @@ extern volatile adc_buf_t adc_buffer;
extern I2C_HandleTypeDef hi2c2;
extern UART_HandleTypeDef huart2;
int cmd1; // normalized input values. -1000 to 1000
int cmd2;
static int cmd1; // normalized input values. -1000 to 1000
static int cmd2;
typedef struct{
int16_t steer;
@@ -66,12 +69,12 @@ typedef struct{
//uint32_t crc;
} Serialcommand;
volatile Serialcommand command;
static volatile Serialcommand command;
uint8_t button1, button2;
static uint8_t button1, button2;
int steer; // global variable for steering. -1000 to 1000
int speed; // global variable for speed. -1000 to 1000
static int steer; // global variable for steering. -1000 to 1000
static int speed; // global variable for speed. -1000 to 1000
extern volatile int pwml; // global variable for pwm left. -1000 to 1000
extern volatile int pwmr; // global variable for pwm right. -1000 to 1000
@@ -84,22 +87,20 @@ extern uint8_t enable; // global variable for motor enable
extern volatile uint32_t timeout; // global variable for timeout
extern float batteryVoltage; // global variable for battery voltage
uint32_t inactivity_timeout_counter;
static uint32_t inactivity_timeout_counter;
extern uint8_t nunchuck_data[6];
#ifdef CONTROL_PPM
extern volatile uint16_t ppm_captured_value[PPM_NUM_CHANNELS+1];
#endif
int milli_vel_error_sum = 0;
void poweroff() {
void poweroff(void) {
// if (abs(speed) < 20) { // wait for the speed to drop, then shut down -> this is commented out for SAFETY reasons
buzzerPattern = 0;
enable = 0;
for (int i = 0; i < 8; i++) {
buzzerFreq = i;
buzzerFreq = (uint8_t)i;
HAL_Delay(100);
}
HAL_GPIO_WritePin(OFF_PORT, OFF_PIN, 0);
@@ -172,7 +173,7 @@ int main(void) {
// ###############################################################################
for (int i = 8; i >= 0; i--) {
buzzerFreq = i;
buzzerFreq = (uint8_t)i;
HAL_Delay(100);
}
buzzerFreq = 0;
@@ -267,12 +268,12 @@ int main(void) {
// cmd1 = 0;
// ####### LOW-PASS FILTER #######
steer = steer * (1.0 - FILTER) + cmd1 * FILTER;
speed = speed * (1.0 - FILTER) + cmd2 * FILTER;
steer = (int)(steer * (1.0f - FILTER) + cmd1 * FILTER);
speed = (int)(speed * (1.0f - FILTER) + cmd2 * FILTER);
// ####### MIXER #######
speedR = CLAMP(speed * SPEED_COEFFICIENT - steer * STEER_COEFFICIENT, -1000, 1000);
speedL = CLAMP(speed * SPEED_COEFFICIENT + steer * STEER_COEFFICIENT, -1000, 1000);
speedR = CLAMP((int)(speed * SPEED_COEFFICIENT - steer * STEER_COEFFICIENT), -1000, 1000);
speedL = CLAMP((int)(speed * SPEED_COEFFICIENT + steer * STEER_COEFFICIENT), -1000, 1000);
#ifdef ADDITIONAL_CODE
@@ -300,7 +301,7 @@ int main(void) {
if (inactivity_timeout_counter % 25 == 0) {
// ####### CALC BOARD TEMPERATURE #######
board_temp_adc_filtered = board_temp_adc_filtered * 0.99 + (float)adc_buffer.temp * 0.01;
board_temp_adc_filtered = board_temp_adc_filtered * 0.99f + (float)adc_buffer.temp * 0.01f;
board_temp_deg_c = ((float)TEMP_CAL_HIGH_DEG_C - (float)TEMP_CAL_LOW_DEG_C) / ((float)TEMP_CAL_HIGH_ADC - (float)TEMP_CAL_LOW_ADC) * (board_temp_adc_filtered - (float)TEMP_CAL_LOW_ADC) + (float)TEMP_CAL_LOW_DEG_C;
// ####### DEBUG SERIAL OUT #######
@@ -308,15 +309,14 @@ int main(void) {
// setScopeChannel(0, (int)adc_buffer.l_tx2); // 1: ADC1
// setScopeChannel(1, (int)adc_buffer.l_rx2); // 2: ADC2
#endif
setScopeChannel(0, (int)speedR); // 1: output command: [-1000, 1000]
setScopeChannel(1, (int)speedL); // 2: output command: [-1000, 1000]
setScopeChannel(2, (int)rtY_Right.n_mot); // 3: Real motor speed [rpm]
setScopeChannel(3, (int)rtY_Left.n_mot); // 4: Real motor speed [rpm]
setScopeChannel(4, (int)adc_buffer.batt1); // 5: for battery voltage calibration
setScopeChannel(5, (int)(batteryVoltage * 100.0f)); // 6: for verifying battery voltage calibration
setScopeChannel(6, (int)board_temp_adc_filtered); // 7: for board temperature calibration
setScopeChannel(7, (int)board_temp_deg_c); // 8: for verifying board temperature calibration
setScopeChannel(0, (int16_t)speedR); // 1: output command: [-1000, 1000]
setScopeChannel(1, (int16_t)speedL); // 2: output command: [-1000, 1000]
setScopeChannel(2, (int16_t)rtY_Right.n_mot); // 3: Real motor speed [rpm]
setScopeChannel(3, (int16_t)rtY_Left.n_mot); // 4: Real motor speed [rpm]
setScopeChannel(4, (int16_t)adc_buffer.batt1); // 5: for battery voltage calibration
setScopeChannel(5, (int16_t)(batteryVoltage * 100.0f)); // 6: for verifying battery voltage calibration
setScopeChannel(6, (int16_t)board_temp_adc_filtered); // 7: for board temperature calibration
setScopeChannel(7, (int16_t)board_temp_deg_c); // 8: for verifying board temperature calibration
consoleScope();
}