2015-12-08 12:01:23 -08:00
|
|
|
/*
|
2016-11-04 07:18:34 -07:00
|
|
|
Copyright 2016 Benjamin Vedder benjamin@vedder.se
|
2015-12-08 12:01:23 -08:00
|
|
|
|
2016-11-04 07:18:34 -07:00
|
|
|
This file is part of the VESC firmware.
|
|
|
|
|
|
|
|
The VESC firmware is free software: you can redistribute it and/or modify
|
2015-12-08 12:01:23 -08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-04 07:18:34 -07:00
|
|
|
The VESC firmware is distributed in the hope that it will be useful,
|
2015-12-08 12:01:23 -08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-11-04 07:18:34 -07:00
|
|
|
*/
|
2015-12-08 12:01:23 -08:00
|
|
|
|
|
|
|
#ifndef MC_INTERFACE_H_
|
|
|
|
#define MC_INTERFACE_H_
|
|
|
|
|
|
|
|
#include "conf_general.h"
|
2017-09-04 12:12:43 -07:00
|
|
|
#include "hw.h"
|
2022-04-07 00:09:31 -07:00
|
|
|
#include "datatypes.h"
|
2015-12-08 12:01:23 -08:00
|
|
|
|
|
|
|
// Functions
|
2020-03-16 10:32:39 -07:00
|
|
|
void mc_interface_init(void);
|
2020-03-16 14:42:44 -07:00
|
|
|
int mc_interface_motor_now(void);
|
2020-03-16 10:32:39 -07:00
|
|
|
void mc_interface_select_motor_thread(int motor);
|
|
|
|
int mc_interface_get_motor_thread(void);
|
2015-12-08 12:01:23 -08:00
|
|
|
const volatile mc_configuration* mc_interface_get_configuration(void);
|
|
|
|
void mc_interface_set_configuration(mc_configuration *configuration);
|
2020-09-13 22:12:11 -07:00
|
|
|
unsigned mc_interface_calc_crc(mc_configuration* conf, bool is_motor_2);
|
2021-06-06 05:13:09 -07:00
|
|
|
bool mc_interface_dccal_done(void);
|
2015-12-08 12:01:23 -08:00
|
|
|
void mc_interface_set_pwm_callback(void (*p_func)(void));
|
|
|
|
void mc_interface_lock(void);
|
|
|
|
void mc_interface_unlock(void);
|
|
|
|
void mc_interface_lock_override_once(void);
|
|
|
|
mc_fault_code mc_interface_get_fault(void);
|
|
|
|
const char* mc_interface_fault_to_string(mc_fault_code fault);
|
|
|
|
mc_state mc_interface_get_state(void);
|
2022-04-07 00:22:00 -07:00
|
|
|
mc_control_mode mc_interface_get_control_mode(void);
|
2015-12-08 12:01:23 -08:00
|
|
|
void mc_interface_set_duty(float dutyCycle);
|
|
|
|
void mc_interface_set_duty_noramp(float dutyCycle);
|
|
|
|
void mc_interface_set_pid_speed(float rpm);
|
|
|
|
void mc_interface_set_pid_pos(float pos);
|
|
|
|
void mc_interface_set_current(float current);
|
|
|
|
void mc_interface_set_brake_current(float current);
|
2017-09-04 12:12:43 -07:00
|
|
|
void mc_interface_set_current_rel(float val);
|
|
|
|
void mc_interface_set_brake_current_rel(float val);
|
2016-11-04 07:18:34 -07:00
|
|
|
void mc_interface_set_handbrake(float current);
|
2018-03-02 02:48:49 -08:00
|
|
|
void mc_interface_set_handbrake_rel(float val);
|
2019-12-07 08:07:05 -08:00
|
|
|
int mc_interface_set_tachometer_value(int steps);
|
2015-12-08 12:01:23 -08:00
|
|
|
void mc_interface_brake_now(void);
|
|
|
|
void mc_interface_release_motor(void);
|
2021-06-13 04:46:27 -07:00
|
|
|
void mc_interface_release_motor_override(void);
|
2021-05-13 01:42:40 -07:00
|
|
|
bool mc_interface_wait_for_motor_release(float timeout);
|
2015-12-08 12:01:23 -08:00
|
|
|
float mc_interface_get_duty_cycle_set(void);
|
|
|
|
float mc_interface_get_duty_cycle_now(void);
|
2016-04-27 06:32:32 -07:00
|
|
|
float mc_interface_get_sampling_frequency_now(void);
|
2015-12-08 12:01:23 -08:00
|
|
|
float mc_interface_get_rpm(void);
|
|
|
|
float mc_interface_get_amp_hours(bool reset);
|
|
|
|
float mc_interface_get_amp_hours_charged(bool reset);
|
|
|
|
float mc_interface_get_watt_hours(bool reset);
|
|
|
|
float mc_interface_get_watt_hours_charged(bool reset);
|
|
|
|
float mc_interface_get_tot_current(void);
|
|
|
|
float mc_interface_get_tot_current_filtered(void);
|
|
|
|
float mc_interface_get_tot_current_directional(void);
|
|
|
|
float mc_interface_get_tot_current_directional_filtered(void);
|
|
|
|
float mc_interface_get_tot_current_in(void);
|
|
|
|
float mc_interface_get_tot_current_in_filtered(void);
|
2021-04-27 08:48:15 -07:00
|
|
|
float mc_interface_get_input_voltage_filtered(void);
|
2015-12-08 12:01:23 -08:00
|
|
|
int mc_interface_get_tachometer_value(bool reset);
|
|
|
|
int mc_interface_get_tachometer_abs_value(bool reset);
|
2015-12-23 15:43:31 -08:00
|
|
|
float mc_interface_get_last_inj_adc_isr_duration(void);
|
2015-12-08 12:01:23 -08:00
|
|
|
float mc_interface_read_reset_avg_motor_current(void);
|
|
|
|
float mc_interface_read_reset_avg_input_current(void);
|
2016-11-04 07:18:34 -07:00
|
|
|
float mc_interface_read_reset_avg_id(void);
|
|
|
|
float mc_interface_read_reset_avg_iq(void);
|
2019-09-08 09:25:38 -07:00
|
|
|
float mc_interface_read_reset_avg_vd(void);
|
|
|
|
float mc_interface_read_reset_avg_vq(void);
|
2016-02-24 12:17:39 -08:00
|
|
|
float mc_interface_get_pid_pos_set(void);
|
|
|
|
float mc_interface_get_pid_pos_now(void);
|
2021-07-11 11:19:26 -07:00
|
|
|
void mc_interface_update_pid_pos_offset(float angle_now, bool store);
|
2016-01-30 06:57:51 -08:00
|
|
|
float mc_interface_get_last_sample_adc_isr_duration(void);
|
2021-10-18 12:45:47 -07:00
|
|
|
void mc_interface_sample_print_data(debug_sampling_mode mode, uint16_t len, uint8_t decimation, bool raw);
|
2017-09-04 12:12:43 -07:00
|
|
|
float mc_interface_temp_fet_filtered(void);
|
|
|
|
float mc_interface_temp_motor_filtered(void);
|
2019-02-18 10:30:19 -08:00
|
|
|
float mc_interface_get_battery_level(float *wh_left);
|
|
|
|
float mc_interface_get_speed(void);
|
|
|
|
float mc_interface_get_distance(void);
|
|
|
|
float mc_interface_get_distance_abs(void);
|
2020-09-16 08:19:36 -07:00
|
|
|
|
2021-05-11 10:25:03 -07:00
|
|
|
setup_values mc_interface_get_setup_values(void);
|
|
|
|
|
2020-09-16 08:19:36 -07:00
|
|
|
// odometer
|
2021-04-11 10:36:11 -07:00
|
|
|
uint64_t mc_interface_get_odometer(void);
|
|
|
|
void mc_interface_set_odometer(uint64_t new_odometer_meters);
|
2020-09-16 08:19:36 -07:00
|
|
|
|
2021-05-11 10:25:03 -07:00
|
|
|
void mc_interface_ignore_input(int time_ms);
|
2015-12-08 12:01:23 -08:00
|
|
|
|
2021-05-15 06:24:39 -07:00
|
|
|
void mc_interface_set_current_off_delay(float delay_sec);
|
|
|
|
|
2022-02-13 06:18:22 -08:00
|
|
|
void mc_interface_ignore_input_both(int time_ms);
|
|
|
|
void mc_interface_release_motor_override_both(void);
|
|
|
|
bool mc_interface_wait_for_motor_release_both(float timeout);
|
|
|
|
|
2021-11-10 16:08:21 -08:00
|
|
|
// Statistics
|
|
|
|
float mc_interface_stat_speed_avg(void);
|
|
|
|
float mc_interface_stat_speed_max(void);
|
|
|
|
float mc_interface_stat_power_avg(void);
|
|
|
|
float mc_interface_stat_power_max(void);
|
|
|
|
float mc_interface_stat_current_avg(void);
|
|
|
|
float mc_interface_stat_current_max(void);
|
|
|
|
float mc_interface_stat_temp_mosfet_avg(void);
|
|
|
|
float mc_interface_stat_temp_mosfet_max(void);
|
|
|
|
float mc_interface_stat_temp_motor_avg(void);
|
|
|
|
float mc_interface_stat_temp_motor_max(void);
|
|
|
|
float mc_interface_stat_count_time(void);
|
|
|
|
void mc_interface_stat_reset(void);
|
|
|
|
|
2015-12-08 12:01:23 -08:00
|
|
|
// MC implementation functions
|
2020-04-03 11:12:12 -07:00
|
|
|
void mc_interface_fault_stop(mc_fault_code fault, bool is_second_motor, bool is_isr);
|
2015-12-08 12:01:23 -08:00
|
|
|
int mc_interface_try_input(void);
|
2020-03-16 10:32:39 -07:00
|
|
|
void mc_interface_mc_timer_isr(bool is_second_motor);
|
2015-12-08 12:01:23 -08:00
|
|
|
|
|
|
|
// Interrupt handlers
|
|
|
|
void mc_interface_adc_inj_int_handler(void);
|
|
|
|
|
|
|
|
// External variables
|
|
|
|
extern volatile uint16_t ADC_Value[];
|
2021-02-28 11:36:02 -08:00
|
|
|
extern volatile float ADC_curr_norm_value[];
|
2015-12-08 12:01:23 -08:00
|
|
|
|
|
|
|
// Common fixed parameters
|
2019-01-30 19:49:26 -08:00
|
|
|
#ifndef HW_DEAD_TIME_NSEC
|
|
|
|
#define HW_DEAD_TIME_NSEC 360.0 // Dead time
|
2017-09-04 12:12:43 -07:00
|
|
|
#endif
|
2015-12-08 12:01:23 -08:00
|
|
|
|
2019-01-30 19:49:26 -08:00
|
|
|
|
2015-12-08 12:01:23 -08:00
|
|
|
#endif /* MC_INTERFACE_H_ */
|