Skip to content

Commit

Permalink
[mkk_v2] Rename subsystem and its internal structures from mkk2 -> mk…
Browse files Browse the repository at this point in the history
…k_v2
  • Loading branch information
dewagter committed Mar 4, 2013
1 parent 45e07b1 commit 5b6984c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
Expand Up @@ -5,40 +5,40 @@
# <firmware name="rotorcraft">
# ...
# <subsystem name="actuators" type="mkk">
# <configure name="MKK_I2C_SCL_TIME" value="50"/> <!-- this is optional, 150 is default, use 50 for 8 motors-->
# <configure name="MKK_V2_I2C_SCL_TIME" value="50"/> <!-- this is optional, 150 is default, use 50 for 8 motors-->
# </subsystem>
# <define name="I2C_TRANSACTION_QUEUE_LEN" value="10"/> <!-- default is 8, increase to 10 or more for 8 motors-->
# </firmware>
#
#
# required xml configuration:
# <section name="ACTUATORS_MKK2" prefix="ACTUATORS_MKK2_">
# <section name="ACTUATORS_MKK_V2" prefix="ACTUATORS_MKK_V2_">
# <define name="NB" value="4"/>
# <define name="ADDR" value="{ 0x52, 0x54, 0x56, 0x58 }"/>
# </section>
#
# servo section with driver="Mkk"
# servo section with driver="Mkk_v2"
# command_laws section to map motor_mixing commands to servos
# max command = 2047

$(TARGET).CFLAGS += -DACTUATORS
ap.srcs += subsystems/actuators/actuators_mkk2.c
ap.srcs += subsystems/actuators/actuators_mkk_v2.c

ifeq ($(ARCH), lpc21)

# set default i2c timing if not already configured
ifeq ($(MKK2_I2C_SCL_TIME), )
MKK_I2C2_SCL_TIME=150
ifeq ($(MKK_V2_I2C_SCL_TIME), )
MKK_V2_I2C2_SCL_TIME=150
endif

ap.CFLAGS += -DACTUATORS_MKK2_DEVICE=i2c0
ap.CFLAGS += -DUSE_I2C0 -DI2C0_SCLL=$(MKK2_I2C_SCL_TIME) -DI2C0_SCLH=$(MKK2_I2C_SCL_TIME)
ap.CFLAGS += -DACTUATORS_MKK_V2_DEVICE=i2c0
ap.CFLAGS += -DUSE_I2C0 -DI2C0_SCLL=$(MKK_V2_I2C_SCL_TIME) -DI2C0_SCLH=$(MKK_V2_I2C_SCL_TIME)

else ifeq ($(ARCH), stm32)
ap.CFLAGS += -DACTUATORS_MKK2_DEVICE=i2c1
ap.CFLAGS += -DACTUATORS_MKK_V2_DEVICE=i2c1
ap.CFLAGS += -DUSE_I2C1
endif

# Simulator
nps.srcs += subsystems/actuators/actuators_mkk.c
nps.CFLAGS += -DUSE_I2C0 -DACTUATORS_MKK_DEVICE=i2c0
# Simulator:
nps.srcs += subsystems/actuators/actuators_mkk_v2.c
nps.CFLAGS += -DUSE_I2C0 -DACTUATORS_MKK_V2_DEVICE=i2c0
12 changes: 6 additions & 6 deletions sw/airborne/modules/config/config_mkk.c
Expand Up @@ -35,7 +35,7 @@ uint8_t config_mkk_crc(uint8_t offset);

struct config_mkk_struct config_mkk;

#define MAX_MOTORS ACTUATORS_MKK2_NB
#define MAX_MOTORS ACTUATORS_MKK_V2_NB


typedef struct
Expand Down Expand Up @@ -111,13 +111,13 @@ void init_config_mkk(void)
}
}

#include "subsystems/actuators/actuators_mkk2.h"
#include "subsystems/actuators/actuators_mkk_v2.h"

void periodic_config_mkk_read_status(void)
{
static int read_nr = 0;

if (!actuators_mkk2.actuators_delay_done)
if (!actuators_mkk_v2.actuators_delay_done)
return;

switch (config_mkk.trans.status) {
Expand Down Expand Up @@ -149,15 +149,15 @@ void periodic_config_mkk_read_status(void)
config_mkk_read_eeprom();


i2c_submit(&ACTUATORS_MKK2_DEVICE, &config_mkk.trans);
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_MKK2_NB] = ACTUATORS_MKK2_ADDR;
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];
Expand Down Expand Up @@ -246,7 +246,7 @@ void config_mkk_send_eeprom(void)
config_mkk.trans.buf[8] = config_mkk_eeprom.BitConfig;
config_mkk.trans.buf[9] = config_mkk_crc(2);

i2c_submit(&ACTUATORS_MKK2_DEVICE, &config_mkk.trans);
i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &config_mkk.trans);

}

Expand Up @@ -19,60 +19,60 @@
* Boston, MA 02111-1307, USA.
*/

/** @file actuators_mkk.c
/** @file actuators_mkk_v2.c
* Actuators driver for Mikrokopter motor controllers.
*/

#include "subsystems/actuators.h"
#include "subsystems/actuators/actuators_mkk2.h"
#include "subsystems/actuators/actuators_mkk_v2.h"

#include "mcu_periph/i2c.h"
#include "mcu_periph/sys_time.h"


struct ActuatorsMkk2 actuators_mkk2;
struct actuators_mkk_v2_struct actuators_mkk_v2;

static uint32_t actuators_delay_time;

void actuators_mkk2_init(void) {
void actuators_mkk_v2_init(void) {

const uint8_t actuators_addr[ACTUATORS_MKK2_NB] = ACTUATORS_MKK2_ADDR;
for (uint8_t i=0; i<ACTUATORS_MKK2_NB; i++) {
actuators_mkk2.trans[i].type = I2CTransTx;
actuators_mkk2.trans[i].len_w = 2;
actuators_mkk2.trans[i].slave_addr = actuators_addr[i];
actuators_mkk2.trans[i].status = I2CTransSuccess;
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].slave_addr = actuators_addr[i];
actuators_mkk_v2.trans[i].status = I2CTransSuccess;
}

#if defined ACTUATORS_START_DELAY && ! defined SITL
actuators_mkk2.actuators_delay_done = FALSE;
actuators_mkk_v2.actuators_delay_done = FALSE;
SysTimeTimerStart(actuators_delay_time);
#else
actuators_mkk2.actuators_delay_done = TRUE;
actuators_mkk_v2.actuators_delay_done = TRUE;
actuators_delay_time = 0;
#endif

}


void actuators_mkk2_set(void) {
void actuators_mkk_v2_set(void) {
#if defined ACTUATORS_START_DELAY && ! defined SITL
if (!actuators_mkk2.actuators_delay_done) {
if (!actuators_mkk_v2.actuators_delay_done) {
if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) return;
else actuators_mkk2.actuators_delay_done = TRUE;
else actuators_mkk_v2.actuators_delay_done = TRUE;
}
#endif

for (uint8_t i=0; i<ACTUATORS_MKK2_NB; i++) {
for (uint8_t i=0; i<ACTUATORS_MKK_V2_NB; i++) {

#ifdef KILL_MOTORS
actuators_mkk2.trans[i].buf[0] = 0;
actuators_mkk2.trans[i].buf[1] = 0;
actuators_mkk_v2.trans[i].buf[0] = 0;
actuators_mkk_v2.trans[i].buf[1] = 0;
#else
actuators_mkk2.trans[i].buf[0] = (actuators_mkk2.setpoint[i] >> 3);
actuators_mkk2.trans[i].buf[1] = actuators_mkk2.setpoint[i] & 0x07;
actuators_mkk_v2.trans[i].buf[0] = (actuators_mkk_v2.setpoint[i] >> 3);
actuators_mkk_v2.trans[i].buf[1] = actuators_mkk_v2.setpoint[i] & 0x07;
#endif

i2c_submit(&ACTUATORS_MKK2_DEVICE, &actuators_mkk2.trans[i]);
i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &actuators_mkk_v2.trans[i]);
}
}
Expand Up @@ -19,32 +19,32 @@
* Boston, MA 02111-1307, USA.
*/

/** @file actuators_mkk.h
/** @file actuators_mkk_v2.h
* Actuators driver for Mikrokopter motor controllers.
*/

#ifndef ACTUATORS_MKK_H
#define ACTUATORS_MKK_H
#ifndef ACTUATORS_MKK_V2_H
#define ACTUATORS_MKK_V2_H

#include "std.h"
#include "mcu_periph/i2c.h"

#include "generated/airframe.h"


struct ActuatorsMkk2 {
bool_t actuators_delay_done; // mkk_config module wants to know state
uint16_t setpoint[ACTUATORS_MKK2_NB];
struct i2c_transaction trans[ACTUATORS_MKK2_NB];
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];
};

extern struct ActuatorsMkk2 actuators_mkk2;
extern struct actuators_mkk_v2_struct actuators_mkk_v2;

extern void actuators_mkk2_init(void);
extern void actuators_mkk2_set(void);
extern void actuators_mkk_v2_init(void);
extern void actuators_mkk_v2_set(void);

#define ActuatorMkk2Set(_i, _v) { actuators_mkk2.setpoint[_i] = _v; }
#define ActuatorsMkk2Init() actuators_mkk2_init()
#define ActuatorsMkk2Commit() actuators_mkk2_set()
#define ActuatorMkk_v2Set(_i, _v) { actuators_mkk_v2.setpoint[_i] = _v; }
#define ActuatorsMkk_v2Init() actuators_mkk_v2_init()
#define ActuatorsMkk_v2Commit() actuators_mkk_v2_set()

#endif /* ACTUATORS_MKK_H */
#endif /* ACTUATORS_MKK_V2_H */

0 comments on commit 5b6984c

Please sign in to comment.