mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-31 12:23:23 +08:00
[mkk_v2] Motor telemetry moved from module to core driver. Impossible to split Rx from Tx in reading Status.
This commit is contained in:
@@ -38,15 +38,6 @@ struct config_mkk_struct config_mkk;
|
||||
#define MAX_MOTORS ACTUATORS_MKK_V2_NB
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Version;
|
||||
uint8_t Current; // in 0.1 A steps, read back from BL
|
||||
uint8_t MaxPWM; // read back from BL -> is less than 255 if BL is in current limit, not running (250) or starting (40)
|
||||
int8_t Temperature; // old BL-Ctrl will return a 255 here, the new version the temp. in °C
|
||||
} __attribute__((packed)) MotorData_t;
|
||||
|
||||
extern MotorData_t Motor[MAX_MOTORS];
|
||||
|
||||
/*
|
||||
typedef struct
|
||||
@@ -75,7 +66,6 @@ uint8_t config_mkk_crc(uint8_t offset)
|
||||
}
|
||||
|
||||
|
||||
MotorData_t Motor[MAX_MOTORS];
|
||||
config_mkk_eeprom_t config_mkk_eeprom;
|
||||
|
||||
|
||||
@@ -102,13 +92,6 @@ void init_config_mkk(void)
|
||||
|
||||
config_mkk.trans.status = I2CTransSuccess;
|
||||
|
||||
for(int i=0; i < MAX_MOTORS; i++)
|
||||
{
|
||||
Motor[i].Version = 0;
|
||||
Motor[i].Current = 0;
|
||||
Motor[i].MaxPWM = 0;
|
||||
Motor[i].Temperature = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#include "subsystems/actuators/actuators_mkk_v2.h"
|
||||
@@ -126,16 +109,7 @@ void periodic_config_mkk_read_status(void)
|
||||
break;
|
||||
case I2CTransSuccess:
|
||||
case I2CTransDone:
|
||||
if (config_mkk.trans.len_r == 3)
|
||||
{
|
||||
Motor[read_nr].Current = config_mkk.trans.buf[0];
|
||||
Motor[read_nr].MaxPWM = config_mkk.trans.buf[1];
|
||||
Motor[read_nr].Temperature = config_mkk.trans.buf[2];
|
||||
}
|
||||
else if (config_mkk.trans.len_r == 8)
|
||||
{
|
||||
config_mkk_parse_eeprom();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
config_mkk.nb_err++;
|
||||
@@ -151,18 +125,6 @@ void periodic_config_mkk_read_status(void)
|
||||
|
||||
i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &config_mkk.trans);
|
||||
}
|
||||
// Read Status
|
||||
else
|
||||
{
|
||||
read_nr++;
|
||||
if (read_nr >= MAX_MOTORS)
|
||||
read_nr = 0;
|
||||
const uint8_t actuators_addr[ACTUATORS_MKK_V2_NB] = ACTUATORS_MKK_V2_ADDR;
|
||||
config_mkk.trans.type = I2CTransRx;
|
||||
config_mkk.trans.len_r = 3;
|
||||
config_mkk.trans.slave_addr = actuators_addr[read_nr];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -178,7 +140,7 @@ void periodic_config_mkk_telemetry(void)
|
||||
{
|
||||
static uint8_t send_nr = 0;
|
||||
|
||||
DOWNLINK_SEND_MKK(DefaultChannel, DefaultDevice, &send_nr, &Motor[send_nr].MaxPWM, &Motor[send_nr].Current, &Motor[send_nr].Temperature);
|
||||
DOWNLINK_SEND_MKK(DefaultChannel, DefaultDevice, &send_nr, &actuators_mkk_v2.data[send_nr].MaxPWM, &actuators_mkk_v2.data[send_nr].Current, &actuators_mkk_v2.data[send_nr].Temperature);
|
||||
|
||||
send_nr++;
|
||||
if (send_nr >= MAX_MOTORS)
|
||||
|
||||
@@ -33,15 +33,21 @@
|
||||
struct actuators_mkk_v2_struct actuators_mkk_v2;
|
||||
|
||||
static uint32_t actuators_delay_time;
|
||||
static uint8_t actuators_read_number;
|
||||
|
||||
void actuators_mkk_v2_init(void) {
|
||||
|
||||
const uint8_t actuators_addr[ACTUATORS_MKK_V2_NB] = ACTUATORS_MKK_V2_ADDR;
|
||||
for (uint8_t i=0; i<ACTUATORS_MKK_V2_NB; i++) {
|
||||
actuators_mkk_v2.trans[i].type = I2CTransTx;
|
||||
actuators_mkk_v2.trans[i].len_w = 2;
|
||||
actuators_mkk_v2.trans[i].type = I2CTransTx;
|
||||
actuators_mkk_v2.trans[i].len_w = 2;
|
||||
actuators_mkk_v2.trans[i].slave_addr = actuators_addr[i];
|
||||
actuators_mkk_v2.trans[i].status = I2CTransSuccess;
|
||||
actuators_mkk_v2.trans[i].status = I2CTransSuccess;
|
||||
|
||||
actuators_mkk_v2.data[i].Version = 0;
|
||||
actuators_mkk_v2.data[i].Current = 0;
|
||||
actuators_mkk_v2.data[i].MaxPWM = 0;
|
||||
actuators_mkk_v2.data[i].Temperature = 0;
|
||||
}
|
||||
|
||||
#if defined ACTUATORS_START_DELAY && ! defined SITL
|
||||
@@ -52,8 +58,18 @@ void actuators_mkk_v2_init(void) {
|
||||
actuators_delay_time = 0;
|
||||
#endif
|
||||
|
||||
actuators_read_number = 0;
|
||||
|
||||
}
|
||||
|
||||
static inline void actuators_mkk_v2_read(void) {
|
||||
actuators_read_number++;
|
||||
if (actuators_read_number >= ACTUATORS_MKK_V2_NB)
|
||||
actuators_read_number = 0;
|
||||
|
||||
actuators_mkk_v2.trans[actuators_read_number].type = I2CTransTxRx;
|
||||
actuators_mkk_v2.trans[actuators_read_number].len_r = 3;
|
||||
}
|
||||
|
||||
void actuators_mkk_v2_set(void) {
|
||||
#if defined ACTUATORS_START_DELAY && ! defined SITL
|
||||
@@ -63,6 +79,21 @@ void actuators_mkk_v2_set(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Read result
|
||||
for (uint8_t i=0; i<ACTUATORS_MKK_V2_NB; i++)
|
||||
{
|
||||
if (actuators_mkk_v2.trans[i].type != I2CTransTx)
|
||||
{
|
||||
actuators_mkk_v2.trans[i].type = I2CTransTx;
|
||||
|
||||
actuators_mkk_v2.data[i].Current = actuators_mkk_v2.trans[i].buf[0];
|
||||
actuators_mkk_v2.data[i].MaxPWM = actuators_mkk_v2.trans[i].buf[1];
|
||||
actuators_mkk_v2.data[i].Temperature = actuators_mkk_v2.trans[i].buf[2];
|
||||
}
|
||||
}
|
||||
|
||||
RunOnceEvery(10, actuators_mkk_v2_read() );
|
||||
|
||||
for (uint8_t i=0; i<ACTUATORS_MKK_V2_NB; i++) {
|
||||
|
||||
#ifdef KILL_MOTORS
|
||||
|
||||
@@ -31,11 +31,18 @@
|
||||
|
||||
#include "generated/airframe.h"
|
||||
|
||||
struct actuators_mkk_v2_telemetry_struct {
|
||||
uint8_t Version; // Motor controller version
|
||||
uint8_t Current; // In 0.1 A steps, read back from BL
|
||||
uint8_t MaxPWM; // Read back from BL -> is less than 255 if BL is in current limit, not running (250) or starting (40)
|
||||
int8_t Temperature; // Old BL-Ctrl will return a 255 here, the new version the temp. in °C
|
||||
};
|
||||
|
||||
struct actuators_mkk_v2_struct {
|
||||
bool_t actuators_delay_done; // config_mkk module wants to know state
|
||||
uint16_t setpoint[ACTUATORS_MKK_V2_NB];
|
||||
struct i2c_transaction trans[ACTUATORS_MKK_V2_NB];
|
||||
struct actuators_mkk_v2_telemetry_struct data[ACTUATORS_MKK_V2_NB];
|
||||
};
|
||||
|
||||
extern struct actuators_mkk_v2_struct actuators_mkk_v2;
|
||||
|
||||
Reference in New Issue
Block a user