Commit 79dcac66 authored by Benjamin Vedder's avatar Benjamin Vedder

Updated to firmware 2.16 and implemented CAN forwarding for bldc_interface

parent 9e97202d
This diff is collapsed.
/* /*
Copyright 2015 Benjamin Vedder benjamin@vedder.se Copyright 2016 Benjamin Vedder benjamin@vedder.se
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -15,13 +15,6 @@ ...@@ -15,13 +15,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/*
* bldc_interface.h
*
* Created on: 6 aug 2015
* Author: benjamin
*/
#ifndef BLDC_INTERFACE_H_ #ifndef BLDC_INTERFACE_H_
#define BLDC_INTERFACE_H_ #define BLDC_INTERFACE_H_
...@@ -29,12 +22,14 @@ ...@@ -29,12 +22,14 @@
// interface functions // interface functions
void bldc_interface_init(void(*func)(unsigned char *data, unsigned int len)); void bldc_interface_init(void(*func)(unsigned char *data, unsigned int len));
void bldc_interface_set_forward_can(int32_t vesc_id);
void bldc_interface_set_forward_func(void(*func)(unsigned char *data, unsigned int len)); void bldc_interface_set_forward_func(void(*func)(unsigned char *data, unsigned int len));
void bldc_interface_send_packet(unsigned char *data, unsigned int len); void bldc_interface_send_packet(unsigned char *data, unsigned int len);
void bldc_interface_process_packet(unsigned char *data, unsigned int len); void bldc_interface_process_packet(unsigned char *data, unsigned int len);
// Function pointer setters // Function pointer setters
void bldc_interface_set_rx_value_func(void(*func)(mc_values *values)); void bldc_interface_set_rx_value_func(void(*func)(mc_values *values));
void bldc_interface_set_rx_printf_func(void(*func)(char *str));
void bldc_interface_set_rx_fw_func(void(*func)(int major, int minor)); void bldc_interface_set_rx_fw_func(void(*func)(int major, int minor));
void bldc_interface_set_rx_rotor_pos_func(void(*func)(float pos)); void bldc_interface_set_rx_rotor_pos_func(void(*func)(float pos));
void bldc_interface_set_rx_mcconf_func(void(*func)(mc_configuration *conf)); void bldc_interface_set_rx_mcconf_func(void(*func)(mc_configuration *conf));
...@@ -48,6 +43,7 @@ void bldc_interface_set_rx_mcconf_received_func(void(*func)(void)); ...@@ -48,6 +43,7 @@ void bldc_interface_set_rx_mcconf_received_func(void(*func)(void));
void bldc_interface_set_rx_appconf_received_func(void(*func)(void)); void bldc_interface_set_rx_appconf_received_func(void(*func)(void));
// Setters // Setters
void bldc_interface_terminal_cmd(char* cmd);
void bldc_interface_set_duty_cycle(float dutyCycle); void bldc_interface_set_duty_cycle(float dutyCycle);
void bldc_interface_set_current(float current); void bldc_interface_set_current(float current);
void bldc_interface_set_current_brake(float current); void bldc_interface_set_current_brake(float current);
......
/* /*
Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se Copyright 2012-2016 Benjamin Vedder benjamin@vedder.se
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -15,13 +15,6 @@ ...@@ -15,13 +15,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/*
* datatypes.h
*
* Created on: 14 sep 2014
* Author: benjamin
*/
#ifndef DATATYPES_H_ #ifndef DATATYPES_H_
#define DATATYPES_H_ #define DATATYPES_H_
...@@ -29,14 +22,6 @@ ...@@ -29,14 +22,6 @@
#include <stdbool.h> #include <stdbool.h>
#include "ch.h" #include "ch.h"
// Data types
typedef enum {
MC_STATE_OFF = 0,
MC_STATE_DETECTING,
MC_STATE_RUNNING,
MC_STATE_FULL_BRAKE,
} mc_state;
typedef enum { typedef enum {
PWM_MODE_NONSYNCHRONOUS_HISW = 0, // This mode is not recommended PWM_MODE_NONSYNCHRONOUS_HISW = 0, // This mode is not recommended
PWM_MODE_SYNCHRONOUS, // The recommended and most tested mode PWM_MODE_SYNCHRONOUS, // The recommended and most tested mode
...@@ -54,9 +39,16 @@ typedef enum { ...@@ -54,9 +39,16 @@ typedef enum {
SENSOR_MODE_HYBRID SENSOR_MODE_HYBRID
} mc_sensor_mode; } mc_sensor_mode;
typedef enum {
FOC_SENSOR_MODE_SENSORLESS = 0,
FOC_SENSOR_MODE_ENCODER,
FOC_SENSOR_MODE_HALL
} mc_foc_sensor_mode;
typedef enum { typedef enum {
MOTOR_TYPE_BLDC = 0, MOTOR_TYPE_BLDC = 0,
MOTOR_TYPE_DC, MOTOR_TYPE_DC,
MOTOR_TYPE_FOC
} mc_motor_type; } mc_motor_type;
typedef enum { typedef enum {
...@@ -69,24 +61,28 @@ typedef enum { ...@@ -69,24 +61,28 @@ typedef enum {
FAULT_CODE_OVER_TEMP_MOTOR FAULT_CODE_OVER_TEMP_MOTOR
} mc_fault_code; } mc_fault_code;
typedef enum { // VESC Types
CONTROL_MODE_DUTY = 0,
CONTROL_MODE_SPEED,
CONTROL_MODE_CURRENT,
CONTROL_MODE_CURRENT_BRAKE,
CONTROL_MODE_POS,
CONTROL_MODE_NONE
} mc_control_mode;
typedef struct { typedef struct {
float cycle_int_limit; float v_in;
float cycle_int_limit_running; float temp_mos1;
float cycle_int_limit_max; float temp_mos2;
float comm_time_sum; float temp_mos3;
float comm_time_sum_min_rpm; float temp_mos4;
int32_t comms; float temp_mos5;
uint32_t time_at_comm; float temp_mos6;
} mc_rpm_dep_struct; float temp_pcb;
float current_motor;
float current_in;
float rpm;
float duty_now;
float amp_hours;
float amp_hours_charged;
float watt_hours;
float watt_hours_charged;
int32_t tachometer;
int tachometer_abs;
mc_fault_code fault_code;
} mc_values;
typedef struct { typedef struct {
// Switching and drive // Switching and drive
...@@ -132,6 +128,30 @@ typedef struct { ...@@ -132,6 +128,30 @@ typedef struct {
// Hall sensor // Hall sensor
int8_t hall_table[8]; int8_t hall_table[8];
float hall_sl_erpm; float hall_sl_erpm;
// FOC
float foc_current_kp;
float foc_current_ki;
float foc_f_sw;
float foc_dt_us;
float foc_encoder_offset;
bool foc_encoder_inverted;
float foc_encoder_ratio;
float foc_motor_l;
float foc_motor_r;
float foc_motor_flux_linkage;
float foc_observer_gain;
float foc_pll_kp;
float foc_pll_ki;
float foc_duty_dowmramp_kp;
float foc_duty_dowmramp_ki;
float foc_openloop_rpm;
float foc_sl_openloop_hyst;
float foc_sl_openloop_time;
float foc_sl_d_current_duty;
float foc_sl_d_current_factor;
mc_foc_sensor_mode foc_sensor_mode;
uint8_t foc_hall_table[8];
float foc_hall_sl_erpm;
// Speed PID // Speed PID
float s_pid_kp; float s_pid_kp;
float s_pid_ki; float s_pid_ki;
...@@ -141,6 +161,7 @@ typedef struct { ...@@ -141,6 +161,7 @@ typedef struct {
float p_pid_kp; float p_pid_kp;
float p_pid_ki; float p_pid_ki;
float p_pid_kd; float p_pid_kd;
float p_pid_ang_div;
// Current controller // Current controller
float cc_startup_boost_duty; float cc_startup_boost_duty;
float cc_min_current; float cc_min_current;
...@@ -151,6 +172,7 @@ typedef struct { ...@@ -151,6 +172,7 @@ typedef struct {
float m_duty_ramp_step; float m_duty_ramp_step;
float m_duty_ramp_step_rpm_lim; float m_duty_ramp_step_rpm_lim;
float m_current_backoff_gain; float m_current_backoff_gain;
uint32_t m_encoder_counts;
} mc_configuration; } mc_configuration;
// Applications to use // Applications to use
...@@ -201,6 +223,7 @@ typedef enum { ...@@ -201,6 +223,7 @@ typedef enum {
ADC_CTRL_TYPE_CURRENT_REV_BUTTON, ADC_CTRL_TYPE_CURRENT_REV_BUTTON,
ADC_CTRL_TYPE_CURRENT_NOREV_BRAKE_CENTER, ADC_CTRL_TYPE_CURRENT_NOREV_BRAKE_CENTER,
ADC_CTRL_TYPE_CURRENT_NOREV_BRAKE_BUTTON, ADC_CTRL_TYPE_CURRENT_NOREV_BRAKE_BUTTON,
ADC_CTRL_TYPE_CURRENT_NOREV_BRAKE_ADC,
ADC_CTRL_TYPE_DUTY, ADC_CTRL_TYPE_DUTY,
ADC_CTRL_TYPE_DUTY_REV_CENTER, ADC_CTRL_TYPE_DUTY_REV_CENTER,
ADC_CTRL_TYPE_DUTY_REV_BUTTON ADC_CTRL_TYPE_DUTY_REV_BUTTON
...@@ -244,6 +267,62 @@ typedef struct { ...@@ -244,6 +267,62 @@ typedef struct {
float tc_max_diff; float tc_max_diff;
} chuk_config; } chuk_config;
// NRF Datatypes
typedef enum {
NRF_SPEED_250K = 0,
NRF_SPEED_1M,
NRF_SPEED_2M
} NRF_SPEED;
typedef enum {
NRF_POWER_M18DBM = 0,
NRF_POWER_M12DBM,
NRF_POWER_M6DBM,
NRF_POWER_0DBM
} NRF_POWER;
typedef enum {
NRF_AW_3 = 0,
NRF_AW_4,
NRF_AW_5
} NRF_AW;
typedef enum {
NRF_CRC_DISABLED = 0,
NRF_CRC_1B,
NRF_CRC_2B
} NRF_CRC;
typedef enum {
NRF_RETR_DELAY_250US = 0,
NRF_RETR_DELAY_500US,
NRF_RETR_DELAY_750US,
NRF_RETR_DELAY_1000US,
NRF_RETR_DELAY_1250US,
NRF_RETR_DELAY_1500US,
NRF_RETR_DELAY_1750US,
NRF_RETR_DELAY_2000US,
NRF_RETR_DELAY_2250US,
NRF_RETR_DELAY_2500US,
NRF_RETR_DELAY_2750US,
NRF_RETR_DELAY_3000US,
NRF_RETR_DELAY_3250US,
NRF_RETR_DELAY_3500US,
NRF_RETR_DELAY_3750US,
NRF_RETR_DELAY_4000US
} NRF_RETR_DELAY;
typedef struct {
NRF_SPEED speed;
NRF_POWER power;
NRF_CRC crc_type;
NRF_RETR_DELAY retry_delay;
unsigned char retries;
unsigned char channel;
unsigned char address[3];
bool send_crc_ack;
} nrf_config;
typedef struct { typedef struct {
// Settings // Settings
uint8_t controller_id; uint8_t controller_id;
...@@ -266,6 +345,9 @@ typedef struct { ...@@ -266,6 +345,9 @@ typedef struct {
// Nunchuk application settings // Nunchuk application settings
chuk_config app_chuk_conf; chuk_config app_chuk_conf;
// NRF application settings
nrf_config app_nrf_conf;
} app_configuration; } app_configuration;
// Communication commands // Communication commands
...@@ -284,119 +366,28 @@ typedef enum { ...@@ -284,119 +366,28 @@ typedef enum {
COMM_SET_SERVO_POS, COMM_SET_SERVO_POS,
COMM_SET_MCCONF, COMM_SET_MCCONF,
COMM_GET_MCCONF, COMM_GET_MCCONF,
COMM_GET_MCCONF_DEFAULT,
COMM_SET_APPCONF, COMM_SET_APPCONF,
COMM_GET_APPCONF, COMM_GET_APPCONF,
COMM_GET_APPCONF_DEFAULT,
COMM_SAMPLE_PRINT, COMM_SAMPLE_PRINT,
COMM_TERMINAL_CMD, COMM_TERMINAL_CMD,
COMM_PRINT, COMM_PRINT,
COMM_ROTOR_POSITION, COMM_ROTOR_POSITION,
COMM_EXPERIMENT_SAMPLE, COMM_EXPERIMENT_SAMPLE,
COMM_DETECT_MOTOR_PARAM, COMM_DETECT_MOTOR_PARAM,
COMM_DETECT_MOTOR_R_L,
COMM_DETECT_MOTOR_FLUX_LINKAGE,
COMM_DETECT_ENCODER,
COMM_DETECT_HALL_FOC,
COMM_REBOOT, COMM_REBOOT,
COMM_ALIVE, COMM_ALIVE,
COMM_GET_DECODED_PPM, COMM_GET_DECODED_PPM,
COMM_GET_DECODED_ADC, COMM_GET_DECODED_ADC,
COMM_GET_DECODED_CHUK, COMM_GET_DECODED_CHUK,
COMM_FORWARD_CAN COMM_FORWARD_CAN,
COMM_SET_CHUCK_DATA,
COMM_CUSTOM_APP_DATA
} COMM_PACKET_ID; } COMM_PACKET_ID;
// CAN commands
typedef enum {
CAN_PACKET_SET_DUTY = 0,
CAN_PACKET_SET_CURRENT,
CAN_PACKET_SET_CURRENT_BRAKE,
CAN_PACKET_SET_RPM,
CAN_PACKET_SET_POS,
CAN_PACKET_FILL_RX_BUFFER,
CAN_PACKET_FILL_RX_BUFFER_LONG,
CAN_PACKET_PROCESS_RX_BUFFER,
CAN_PACKET_PROCESS_SHORT_BUFFER,
CAN_PACKET_STATUS
} CAN_PACKET_ID;
// Logged fault data
typedef struct {
mc_fault_code fault;
float current;
float current_filtered;
float voltage;
float duty;
float rpm;
int tacho;
int cycles_running;
int pwm_cycles;
int tim_val_samp;
int tim_current_samp;
int tim_top;
int comm_step;
float temperature;
} fault_data;
// External LED state
typedef enum {
LED_EXT_OFF = 0,
LED_EXT_NORMAL,
LED_EXT_BRAKE,
LED_EXT_TURN_LEFT,
LED_EXT_TURN_RIGHT,
LED_EXT_BRAKE_TURN_LEFT,
LED_EXT_BRAKE_TURN_RIGHT,
LED_EXT_BATT
} LED_EXT_STATE;
typedef struct {
int js_x;
int js_y;
int acc_x;
int acc_y;
int acc_z;
bool bt_c;
bool bt_z;
} chuck_data;
typedef struct {
int id;
systime_t rx_time;
float rpm;
float current;
float duty;
} can_status_msg;
typedef struct {
uint8_t js_x;
uint8_t js_y;
bool bt_c;
bool bt_z;
bool bt_push;
float vbat;
} mote_state;
typedef enum {
MOTE_PACKET_BATT_LEVEL = 0,
MOTE_PACKET_BUTTONS,
MOTE_PACKET_ALIVE
} MOTE_PACKET;
typedef struct {
float v_in;
float temp_mos1;
float temp_mos2;
float temp_mos3;
float temp_mos4;
float temp_mos5;
float temp_mos6;
float temp_pcb;
float current_motor;
float current_in;
float rpm;
float duty_now;
float amp_hours;
float amp_hours_charged;
float watt_hours;
float watt_hours_charged;
int tachometer;
int tachometer_abs;
mc_fault_code fault_code;
} mc_values;
#endif /* DATATYPES_H_ */ #endif /* DATATYPES_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment