diff --git a/conf/modules/configure_actuators_mkk.xml b/conf/modules/configure_actuators_mkk.xml deleted file mode 100644 index bac54bd12c..0000000000 --- a/conf/modules/configure_actuators_mkk.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - Configure Mikrokopter MKK v1.0 and v2.0 BLDC motor controllers (requires subsystem actuators_mkk) - -
- -
- - - - - - - -
- diff --git a/conf/modules/configure_actuators_mkk_v2.xml b/conf/modules/configure_actuators_mkk_v2.xml new file mode 100644 index 0000000000..9a377a41ec --- /dev/null +++ b/conf/modules/configure_actuators_mkk_v2.xml @@ -0,0 +1,18 @@ + + + + + Configure Mikrokopter MKK v2.0 BLDC motor controllers (requires subsystem actuators_mkk_v2) + +
+ +
+ + + + + + + +
+ diff --git a/conf/settings/modules/config_mkk_v2.xml b/conf/settings/modules/config_mkk_v2.xml new file mode 100644 index 0000000000..bbd59bf174 --- /dev/null +++ b/conf/settings/modules/config_mkk_v2.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/conf/settings/modules/configure_mkk.xml b/conf/settings/modules/configure_mkk.xml deleted file mode 100644 index fd853fcb5c..0000000000 --- a/conf/settings/modules/configure_mkk.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/sw/airborne/modules/config/config_mkk.c b/sw/airborne/modules/config/config_mkk.c deleted file mode 100644 index 56233affbd..0000000000 --- a/sw/airborne/modules/config/config_mkk.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2013 Christophe De Wagter - * - * This file is part of paparazzi. - * - * paparazzi is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * paparazzi is distributed in the hope that it will be useful, - * 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -#include "config_mkk.h" -#include "generated/airframe.h" - - - -void config_mkk_read_eeprom(void); -void config_mkk_parse_eeprom(void); -uint8_t config_mkk_crc(uint8_t offset); - - -// Following 2 structs are known from: http://mikrokopter.de/mikrosvn/FlightCtrl/tags/V0.88n/twimaster.h - - -struct config_mkk_struct config_mkk; - -#define MAX_MOTORS ACTUATORS_MKK_V2_NB - - - -/* -typedef struct -{ - uint8_t revision; // must be BL_revision - uint8_t SetMask; // settings mask - uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit - uint8_t CurrentLimit; // current limit in A - uint8_t TempLimit; // in °C - uint8_t CurrentScaling; // scaling factor for current measurement - uint8_t BitConfig; // see defines above - uint8_t crc; // checksum -} __attribute__((packed)) config_mkk_eeprom_t; - -extern config_mkk_eeprom_t config_mkk_eeprom; -*/ - -uint8_t config_mkk_crc(uint8_t offset) -{ - uint8_t crc = 0xaa; - for(int i=offset; i<(offset+7); i++) - { - crc += config_mkk.trans.buf[i]; - } - return crc; -} - - -config_mkk_eeprom_t config_mkk_eeprom; - - -#define BL_READMODE_CONFIG 16 - -#define CONFIG_MKK_EEPROM_REVISION 2 - -#define MASK_SET_PWM_SCALING 0x01 -#define MASK_SET_CURRENT_LIMIT 0x02 -#define MASK_SET_TEMP_LIMIT 0x04 -#define MASK_SET_CURRENT_SCALING 0x08 -#define MASK_SET_BITCONFIG 0x10 -#define MASK_RESET_CAPCOUNTER 0x20 -#define MASK_SET_DEFAULT_PARAMS 0x40 -#define MASK_SET_SAVE_EEPROM 0x80 - -#define BITCONF_REVERSE_ROTATION 0x01 - - -void init_config_mkk(void) -{ - config_mkk.nb_err = 0; - config_mkk.read_config = 0; - - config_mkk.trans.status = I2CTransSuccess; - -} - -#include "subsystems/actuators/actuators_mkk_v2.h" - -void periodic_config_mkk_read_status(void) -{ - static int read_nr = 0; - - if (!actuators_mkk_v2.actuators_delay_done) - return; - - switch (config_mkk.trans.status) { - case I2CTransFailed: - config_mkk.nb_err++; - break; - case I2CTransSuccess: - case I2CTransDone: - config_mkk_parse_eeprom(); - break; - default: - config_mkk.nb_err++; - return; - } - - // Read Config - if (config_mkk.read_config > 0) - { - config_mkk.read_config = 0; - config_mkk_read_eeprom(); - - - i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &config_mkk.trans); - } - -} - -#ifndef DOWNLINK_DEVICE -#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE -#endif -#include "mcu_periph/uart.h" -#include "messages.h" -#include "subsystems/datalink/downlink.h" - - -void periodic_config_mkk_telemetry(void) -{ - static uint8_t send_nr = 0; - - 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) - send_nr = 0; -} - - -#define RETURN_IF_NOT_KILLMODE() {} - -void config_mkk_read_eeprom(void) -{ - // Do not read config while running - RETURN_IF_NOT_KILLMODE(); - - // New I2C Write/Read Transaction - config_mkk.trans.type = I2CTransTxRx; - config_mkk.trans.slave_addr = 0x52 + config_mkk.addr * 2; - config_mkk.trans.len_w = 2; - config_mkk.trans.buf[0] = 0; - config_mkk.trans.buf[1] = (BL_READMODE_CONFIG<<3); - config_mkk.trans.len_r = 8; -} - -void config_mkk_parse_eeprom(void) -{ - config_mkk_eeprom.crc = config_mkk.trans.buf[7]; // checksum - if (config_mkk_crc(0) != config_mkk_eeprom.crc) - { - config_mkk.nb_err++; - } - else - { - config_mkk_eeprom.revision = config_mkk.trans.buf[0]; // must be BL_revision - config_mkk_eeprom.SetMask = config_mkk.trans.buf[1]; // settings mask - config_mkk_eeprom.PwmScaling = config_mkk.trans.buf[2]; // maximum value of control pwm, acts like a thrust limit - config_mkk_eeprom.CurrentLimit = config_mkk.trans.buf[3]; // current limit in A - config_mkk_eeprom.TempLimit = config_mkk.trans.buf[4]; // in °C - config_mkk_eeprom.CurrentScaling = config_mkk.trans.buf[5]; // scaling factor for current measurement - config_mkk_eeprom.BitConfig = config_mkk.trans.buf[6]; // see defines above - } -} - -void config_mkk_send_eeprom(void) -{ - // Do not upload while running - RETURN_IF_NOT_KILLMODE(); - - // Do not upload bad data: - if (config_mkk_eeprom.revision != CONFIG_MKK_EEPROM_REVISION) - return; - - // New I2C Write Transaction - config_mkk.trans.type = I2CTransTx; - config_mkk.trans.slave_addr = 0x52 + config_mkk.addr * 2; - config_mkk.trans.len_w = 10; - config_mkk.trans.buf[0] = 0; - config_mkk.trans.buf[1] = (BL_READMODE_CONFIG<<3); - - config_mkk.trans.buf[2] = config_mkk_eeprom.revision; - config_mkk.trans.buf[3] = config_mkk_eeprom.SetMask; - config_mkk.trans.buf[4] = config_mkk_eeprom.PwmScaling; - config_mkk.trans.buf[5] = config_mkk_eeprom.CurrentLimit; - config_mkk.trans.buf[6] = config_mkk_eeprom.TempLimit; - config_mkk.trans.buf[7] = config_mkk_eeprom.CurrentScaling; - config_mkk.trans.buf[8] = config_mkk_eeprom.BitConfig; - config_mkk.trans.buf[9] = config_mkk_crc(2); - - i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &config_mkk.trans); - -} - diff --git a/sw/airborne/modules/config/config_mkk.h b/sw/airborne/modules/config/config_mkk.h deleted file mode 100644 index 897090b088..0000000000 --- a/sw/airborne/modules/config/config_mkk.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2013 Christophe De Wagter - * - * This file is part of paparazzi. - * - * paparazzi is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * paparazzi is distributed in the hope that it will be useful, - * 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 paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -/** \file config_mkk.h - * - * Read Status and Config from MKK (Mikrokopter) BLDC motor controllers - */ - -#ifndef CONFIG_MKK_MODULE_H -#define CONFIG_MKK_MODULE_H - -#include "std.h" - -#include "mcu_periph/i2c.h" - -typedef struct -{ - uint8_t revision; - uint8_t SetMask; - uint8_t PwmScaling; - uint8_t CurrentLimit; - uint8_t TempLimit; - uint8_t CurrentScaling; - uint8_t BitConfig; - uint8_t crc; -} config_mkk_eeprom_t; - -extern config_mkk_eeprom_t config_mkk_eeprom; - -struct config_mkk_struct -{ - int read_config; - int addr; - - int nb_err; - - uint8_t read_nr; - struct i2c_transaction trans; -}; - -extern struct config_mkk_struct config_mkk; - -extern void config_mkk_send_eeprom(void); - -#define config_mkk_SetConfig(_v) { \ - config_mkk.addr = _v; \ - config_mkk_send_eeprom(); \ -} - -#define config_mkk_GetConfig(_v) { \ - config_mkk.addr = _v; \ - config_mkk.read_config = 1; \ -} - - - -void init_config_mkk(void); -void periodic_config_mkk_read_status(void); -void periodic_config_mkk_telemetry(void); - - -#endif - - - diff --git a/sw/airborne/modules/config/config_mkk_v2.c b/sw/airborne/modules/config/config_mkk_v2.c new file mode 100644 index 0000000000..fe416141d1 --- /dev/null +++ b/sw/airborne/modules/config/config_mkk_v2.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2013 Christophe De Wagter + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * 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 paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "config_mkk_v2.h" +#include "generated/airframe.h" + +void config_mkk_v2_parse_eeprom(void); + +struct config_mkk_v2_struct config_mkk_v2; + +void config_mkk_v2_init(void) +{ + config_mkk_v2.nb_err = 0; + config_mkk_v2.read_config = 0; + + config_mkk_v2.trans.status = I2CTransSuccess; + +} + +#include "subsystems/actuators/actuators_mkk_v2.h" + +void config_mkk_v2_periodic_read_status(void) +{ + // Read Config + if (config_mkk_v2.read_config > 0) + { + switch (config_mkk_v2.trans.status) { + case I2CTransFailed: + config_mkk_v2.read_config = 0; + break; + case I2CTransSuccess: + case I2CTransDone: + config_mkk_v2_parse_eeprom(); + config_mkk_v2.read_config = 0; + break; + default: + return; + } + } +} + +#ifndef DOWNLINK_DEVICE +#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE +#endif +#include "mcu_periph/uart.h" +#include "messages.h" +#include "subsystems/datalink/downlink.h" + + +void config_mkk_v2_periodic_telemetry(void) +{ + static uint8_t send_nr = 0; + + 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 >= ACTUATORS_MKK_V2_NB) + send_nr = 0; +} + + + +////////////////////////////////////////////////////////////////// +// MKK Config + +uint8_t config_mkk_v2_crc(uint8_t offset); + +// Following 2 structs are known from: http://mikrokopter.de/mikrosvn/FlightCtrl/tags/V0.88n/twimaster.h + +/* +typedef struct +{ + uint8_t revision; // must be BL_revision + uint8_t SetMask; // settings mask + uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit + uint8_t CurrentLimit; // current limit in A + uint8_t TempLimit; // in °C + uint8_t CurrentScaling; // scaling factor for current measurement + uint8_t BitConfig; // see defines above + uint8_t crc; // checksum +} __attribute__((packed)) config_mkk_v2_eeprom_t; + +extern config_mkk_v2_eeprom_t config_mkk_v2_eeprom; +*/ + +uint8_t config_mkk_v2_crc(uint8_t offset) +{ + uint8_t crc = 0xaa; + for(int i=offset; i<(offset+7); i++) + { + crc += config_mkk_v2.trans.buf[i]; + } + return crc; +} + + +config_mkk_v2_eeprom_t config_mkk_v2_eeprom; + + +#define BL_READMODE_CONFIG 16 +#define config_mkk_v2_EEPROM_REVISION 2 + + +#define RETURN_IF_NOT_KILLMODE() \ +{ \ + if (!actuators_mkk_v2.actuators_delay_done) \ + return; \ +} + +void config_mkk_v2_read_eeprom(void) +{ + // Do not read config while running + RETURN_IF_NOT_KILLMODE(); + + // New I2C Write/Read Transaction + config_mkk_v2.trans.type = I2CTransTxRx; + config_mkk_v2.trans.slave_addr = 0x52 + config_mkk_v2.addr * 2; + config_mkk_v2.trans.len_w = 2; + config_mkk_v2.trans.buf[0] = 0; + config_mkk_v2.trans.buf[1] = (BL_READMODE_CONFIG<<3); + config_mkk_v2.trans.len_r = 8; + + i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &config_mkk_v2.trans); +} + +void config_mkk_v2_parse_eeprom(void) +{ + config_mkk_v2_eeprom.crc = config_mkk_v2.trans.buf[7]; // checksum + if (config_mkk_v2_crc(0) != config_mkk_v2_eeprom.crc) + { + config_mkk_v2.nb_err++; + } + else + { + config_mkk_v2_eeprom.revision = config_mkk_v2.trans.buf[0]; // must be BL_revision + config_mkk_v2_eeprom.SetMask = config_mkk_v2.trans.buf[1]; // settings mask + config_mkk_v2_eeprom.PwmScaling = config_mkk_v2.trans.buf[2]; // maximum value of control pwm, acts like a thrust limit + config_mkk_v2_eeprom.CurrentLimit = config_mkk_v2.trans.buf[3]; // current limit in A + config_mkk_v2_eeprom.TempLimit = config_mkk_v2.trans.buf[4]; // in °C + config_mkk_v2_eeprom.CurrentScaling = config_mkk_v2.trans.buf[5]; // scaling factor for current measurement + config_mkk_v2_eeprom.BitConfig = config_mkk_v2.trans.buf[6]; // see defines above + } +} + +void config_mkk_v2_send_eeprom(void) +{ + // Do not upload while running + RETURN_IF_NOT_KILLMODE(); + + // Do not upload bad data: + if (config_mkk_v2_eeprom.revision != config_mkk_v2_EEPROM_REVISION) + return; + + // New I2C Write Transaction + config_mkk_v2.trans.type = I2CTransTx; + config_mkk_v2.trans.slave_addr = 0x52 + config_mkk_v2.addr * 2; + config_mkk_v2.trans.len_w = 10; + config_mkk_v2.trans.buf[0] = 0; + config_mkk_v2.trans.buf[1] = (BL_READMODE_CONFIG<<3); + + config_mkk_v2.trans.buf[2] = config_mkk_v2_eeprom.revision; + config_mkk_v2.trans.buf[3] = config_mkk_v2_eeprom.SetMask; + config_mkk_v2.trans.buf[4] = config_mkk_v2_eeprom.PwmScaling; + config_mkk_v2.trans.buf[5] = config_mkk_v2_eeprom.CurrentLimit; + config_mkk_v2.trans.buf[6] = config_mkk_v2_eeprom.TempLimit; + config_mkk_v2.trans.buf[7] = config_mkk_v2_eeprom.CurrentScaling; + config_mkk_v2.trans.buf[8] = config_mkk_v2_eeprom.BitConfig; + config_mkk_v2.trans.buf[9] = config_mkk_v2_crc(2); + + i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &config_mkk_v2.trans); + +} + diff --git a/sw/airborne/modules/config/config_mkk_v2.h b/sw/airborne/modules/config/config_mkk_v2.h new file mode 100644 index 0000000000..0aba5d06c7 --- /dev/null +++ b/sw/airborne/modules/config/config_mkk_v2.h @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2013 Christophe De Wagter + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * 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 paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +/** \file config_mkk_v2.h + * + * Read Status and Config from MKK (Mikrokopter) BLDC motor controllers + */ + +#ifndef config_mkk_v2_MODULE_H +#define config_mkk_v2_MODULE_H + +#include "std.h" + +#include "mcu_periph/i2c.h" + +struct config_mkk_v2_struct +{ + uint8_t read_config; + uint8_t addr; + + int nb_err; + + struct i2c_transaction trans; +}; + +extern struct config_mkk_v2_struct config_mkk_v2; + +void config_mkk_v2_init(void); +void config_mkk_v2_periodic_read_status(void); +void config_mkk_v2_periodic_telemetry(void); + +////////////////////////////////////////////////////////////////// +// MKK Config + +typedef struct +{ + uint8_t revision; + uint8_t SetMask; + uint8_t PwmScaling; + uint8_t CurrentLimit; + uint8_t TempLimit; + uint8_t CurrentScaling; + uint8_t BitConfig; + uint8_t crc; +} config_mkk_v2_eeprom_t; + +extern config_mkk_v2_eeprom_t config_mkk_v2_eeprom; + + +#define CONFIG_MKK_V2_MASK_SET_PWM_SCALING 0x01 +#define CONFIG_MKK_V2_MASK_SET_CURRENT_LIMIT 0x02 +#define CONFIG_MKK_V2_MASK_SET_TEMP_LIMIT 0x04 +#define CONFIG_MKK_V2_MASK_SET_CURRENT_SCALING 0x08 +#define CONFIG_MKK_V2_MASK_SET_BITCONFIG 0x10 +#define CONFIG_MKK_V2_MASK_RESET_CAPCOUNTER 0x20 +#define CONFIG_MKK_V2_MASK_SET_DEFAULT_PARAMS 0x40 +#define CONFIG_MKK_V2_MASK_SET_SAVE_EEPROM 0x80 + +#define BITCONF_REVERSE_ROTATION 0x01 + + +extern void config_mkk_v2_send_eeprom(void); +extern void config_mkk_v2_read_eeprom(void); + +#define config_mkk_v2_ResetDefault(_v) { \ + config_mkk_v2_eeprom.SetMask = CONFIG_MKK_V2_MASK_SET_SAVE_EEPROM | CONFIG_MKK_V2_MASK_SET_DEFAULT_PARAMS; \ + config_mkk_v2_send_eeprom(); \ +} + +#define config_mkk_v2_SetPwmScaling(_v) { \ + config_mkk_v2_eeprom.PwmScaling = _v; \ + config_mkk_v2_eeprom.SetMask = CONFIG_MKK_V2_MASK_SET_SAVE_EEPROM | CONFIG_MKK_V2_MASK_SET_PWM_SCALING; \ + config_mkk_v2_send_eeprom(); \ +} + +#define config_mkk_v2_SetCurrentLimit(_v) { \ + config_mkk_v2_eeprom.CurrentLimit = _v; \ + config_mkk_v2_eeprom.SetMask = CONFIG_MKK_V2_MASK_SET_SAVE_EEPROM | CONFIG_MKK_V2_MASK_SET_CURRENT_LIMIT; \ + config_mkk_v2_send_eeprom(); \ +} + +#define config_mkk_v2_SetTempLimit(_v) { \ + config_mkk_v2_eeprom.TempLimit = _v; \ + config_mkk_v2_eeprom.SetMask = CONFIG_MKK_V2_MASK_SET_SAVE_EEPROM | CONFIG_MKK_V2_MASK_SET_TEMP_LIMIT; \ + config_mkk_v2_send_eeprom(); \ +} + +#define config_mkk_v2_SetCurrentScaling(_v) { \ + config_mkk_v2_eeprom.CurrentScaling = _v; \ + config_mkk_v2_eeprom.SetMask = CONFIG_MKK_V2_MASK_SET_SAVE_EEPROM | CONFIG_MKK_V2_MASK_SET_CURRENT_SCALING; \ + config_mkk_v2_send_eeprom(); \ +} + +#define config_mkk_v2_SetBitConfig(_v) { \ + config_mkk_v2_eeprom.BitConfig = _v; \ + config_mkk_v2_eeprom.SetMask = CONFIG_MKK_V2_MASK_SET_SAVE_EEPROM | CONFIG_MKK_V2_MASK_SET_BITCONFIG; \ + config_mkk_v2_send_eeprom(); \ +} + +#define config_mkk_v2_GetConfig(_v) { \ + config_mkk_v2.addr = _v; \ + config_mkk_v2_read_eeprom(); \ +} + + + +#endif + + +