Page 1 of 1

Uncontrolled Motor Spinup

Posted: Wed Jun 29, 2016 11:10 am
by TU_KL_Robotics
Hi,
for our project we want to implement sbus capabilitys on the CF in combination with the Bigquad Deck. In order to free up USART 2_RX we want to remapp motor output 4 and use the USART 2_RX to read the SBUS signal.

In order to provide easy connection possibilities for our brushless ESC's we decided to remapp M4 to the CPPM connector on the Bigquad Deck. I desoldered the 1k pullup resistor R1 from the Bigquad Deck and resoldered it between the signal and 5V pin of the CPPM connector.
We then tested our SBUS code, getting its signal from the former M4 connector, working flawlessly.

To remapp the M4 output, we did the following changes in motors_def_cf2:

The original mapping

Code: Select all

const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS] =
{
	&DECK_TX2_TIM2,
	&DECK_IO3,
	&DECK_IO2,
	&DECK_RX2_TIM2
};

was changed to:

Code: Select all

const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS] =
{
	&DECK_TX2_TIM2,
	&DECK_IO3,
	&DECK_IO2,
	&DECK_MOSI	
//  &DECK_RX2_TIM2 remapped Motor4 to CPPM Connector to free up USART on E_RX2
};


Now my first question is, why states the comment in the motors_def_cf2 the following :

Code: Select all

/**
 * Brushless motors mapped as on the Big-Quad deck
 * M1 -> IO3
 * M2 -> TX2
 * M3 -> RX2
 * M4 -> IO2
 */
 
althoug the connectors on the Bigquad Deck label TX2 pin to be connected to M1, IO3 to M2, IO2 to M3 and RX3 to M4 ?


Our main problem however is, that when trying to liftoff all the motors start spinning up but after approximately one second the CF decreases the speed of M2,M3 and M4. Only Motor 1 keeps spinning and the CF continually increase power to M1.
Even more confusing is, that according to the attached screenshot from the CF client logging M1 AND M3 are supposed to spin up, but only M1 does so.
Motors.png
Is this behaviour explainable with incorrect motor mapping in our motors_edf_cf2?
When increasing the throttel rapidly from 0 to 50 or even 100% and then quickly lowering it back to 0%, all the motors spin up and down as expected. This leads me to believe the error isn't a hardware problem, induced by moving the pullup resitor from M4 to the CPPM Connector


As described in viewtopic.php?f=6&t=2067 , previously we tried to read the SBUS Signal from the RX pin of the I2C connector, but unfortunately we did not take account of the CrazyFlie's EEPROM on the I2C bus. This lead to errors during initialisation. Since moving away from the I2C pin, initialisation is ofcourse again succesfull on every startup and the communication with the EEPROM isn't disturbed anymore.



See below our complete motors_def_cf2:

Code: Select all


// Connector M1, PA1, TIM2_CH2
static const MotorPerifDef CONN_M1 =
{
    .drvType       = BRUSHED,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_1,
    .gpioPinSource = GPIO_PinSource1,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_PWM_PERIOD,
    .timPrescaler  = MOTORS_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare2,
    .getCompare    = TIM_GetCapture2,
    .ocInit        = TIM_OC2Init,
    .preloadConfig = TIM_OC2PreloadConfig,
};

// Connector M2, PB11, TIM2_CH4
static const MotorPerifDef CONN_M2 =
{
    .drvType       = BRUSHED,
    .gpioPerif     = RCC_AHB1Periph_GPIOB,
    .gpioPort      = GPIOB,
    .gpioPin       = GPIO_Pin_11,
    .gpioPinSource = GPIO_PinSource11,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_PWM_PERIOD,
    .timPrescaler  = MOTORS_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare4,
    .getCompare    = TIM_GetCapture4,
    .ocInit        = TIM_OC4Init,
    .preloadConfig = TIM_OC4PreloadConfig,
};

// Connector M3, PA15, TIM2_CH1
static const MotorPerifDef CONN_M3 =
{
    .drvType       = BRUSHED,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_15,
    .gpioPinSource = GPIO_PinSource15,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_PWM_PERIOD,
    .timPrescaler  = MOTORS_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare1,
    .getCompare    = TIM_GetCapture1,
    .ocInit        = TIM_OC1Init,
    .preloadConfig = TIM_OC1PreloadConfig,
};

// Connector M4, PB9, TIM4_CH4
static const MotorPerifDef CONN_M4 =
{
    .drvType       = BRUSHED,
    .gpioPerif     = RCC_AHB1Periph_GPIOB,
    .gpioPort      = GPIOB,
    .gpioPin       = GPIO_Pin_9,
    .gpioPinSource = GPIO_PinSource9,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM4,
    .timPerif      = RCC_APB1Periph_TIM4,
    .tim           = TIM4,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM4_STOP,
    .timPeriod     = MOTORS_PWM_PERIOD,
    .timPrescaler  = MOTORS_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare4,
    .getCompare    = TIM_GetCapture4,
    .ocInit        = TIM_OC4Init,
    .preloadConfig = TIM_OC4PreloadConfig,
};

// Connector M1, PA1, TIM2_CH2, Brushless config
static const MotorPerifDef CONN_M1_BL =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_1,
    .gpioPinSource = GPIO_PinSource1,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_Low,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare2,
    .getCompare    = TIM_GetCapture2,
    .ocInit        = TIM_OC2Init,
    .preloadConfig = TIM_OC2PreloadConfig,
};

// Connector M2, PB11, TIM2_CH4, Brushless config
static const MotorPerifDef CONN_M2_BL =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOB,
    .gpioPort      = GPIOB,
    .gpioPin       = GPIO_Pin_11,
    .gpioPinSource = GPIO_PinSource11,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_Low,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare4,
    .getCompare    = TIM_GetCapture4,
    .ocInit        = TIM_OC4Init,
    .preloadConfig = TIM_OC4PreloadConfig,
};

// Connector M3, PA15, TIM2_CH1, Brushless config
static const MotorPerifDef CONN_M3_BL =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_15,
    .gpioPinSource = GPIO_PinSource15,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_Low,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare1,
    .getCompare    = TIM_GetCapture1,
    .ocInit        = TIM_OC1Init,
    .preloadConfig = TIM_OC1PreloadConfig,
};

// Connector M4, PB9, TIM4_CH4, Brushless config
static const MotorPerifDef CONN_M4_BL =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOB,
    .gpioPort      = GPIOB,
    .gpioPin       = GPIO_Pin_9,
    .gpioPinSource = GPIO_PinSource9,
    .gpioOType     = GPIO_OType_PP,
    .gpioAF        = GPIO_AF_TIM4,
    .timPerif      = RCC_APB1Periph_TIM4,
    .tim           = TIM4,
    .timPolarity   = TIM_OCPolarity_Low,
    .timDbgStop    = DBGMCU_TIM4_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare4,
    .getCompare    = TIM_GetCapture4,
    .ocInit        = TIM_OC4Init,
    .preloadConfig = TIM_OC4PreloadConfig,
};

// Motor1, Deck TX2, PA2, TIM2_CH3
static const MotorPerifDef DECK_TX2_TIM2 =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_2,
    .gpioPinSource = GPIO_PinSource2,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare3,
    .getCompare    = TIM_GetCapture3,
    .ocInit        = TIM_OC3Init,
    .preloadConfig = TIM_OC3PreloadConfig,
};

// Motor1, Deck TX2, PA2, TIM5_CH3
static const MotorPerifDef DECK_TX2_TIM5 =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_2,
    .gpioPinSource = GPIO_PinSource2,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM5,
    .timPerif      = RCC_APB1Periph_TIM5,
    .tim           = TIM5,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM5_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare3,
    .getCompare    = TIM_GetCapture3,
    .ocInit        = TIM_OC3Init,
    .preloadConfig = TIM_OC3PreloadConfig,
};

// Motor4, Deck RX2, PA3, TIM2_CH4
static const MotorPerifDef DECK_RX2_TIM2 =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_3,
    .gpioPinSource = GPIO_PinSource3,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare4,
    .getCompare    = TIM_GetCapture4,
    .ocInit        = TIM_OC4Init,
    .preloadConfig = TIM_OC4PreloadConfig,
};

// Motor4, Deck RX2, PA3, TIM5_CH4
static const MotorPerifDef DECK_RX2_TIM5 =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_3,
    .gpioPinSource = GPIO_PinSource3,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM5,
    .timPerif      = RCC_APB1Periph_TIM5,
    .tim           = TIM5,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM5_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare4,
    .getCompare    = TIM_GetCapture4,
    .ocInit        = TIM_OC4Init,
    .preloadConfig = TIM_OC4PreloadConfig,
};

// E_CS3, Deck IO1, PB8, TIM4_CH3
static const MotorPerifDef DECK_IO1_TIM4 =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOB,
    .gpioPort      = GPIOB,
    .gpioPin       = GPIO_Pin_8,
    .gpioPinSource = GPIO_PinSource8,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM4,
    .timPerif      = RCC_APB1Periph_TIM4,
    .tim           = TIM4,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM4_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare3,
    .getCompare    = TIM_GetCapture3,
    .ocInit        = TIM_OC3Init,
    .preloadConfig = TIM_OC3PreloadConfig,
};

// Motor3, Deck IO2, PB5, TIM3_CH2
static const MotorPerifDef DECK_IO2 =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOB,
    .gpioPort      = GPIOB,
    .gpioPin       = GPIO_Pin_5,
    .gpioPinSource = GPIO_PinSource5,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM3,
    .timPerif      = RCC_APB1Periph_TIM3,
    .tim           = TIM3,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM3_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare2,
    .getCompare    = TIM_GetCapture2,
    .ocInit        = TIM_OC2Init,
    .preloadConfig = TIM_OC2PreloadConfig,
};

// Motor2, Deck IO3, PB4, TIM3_CH1
static const MotorPerifDef DECK_IO3 =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOB,
    .gpioPort      = GPIOB,
    .gpioPin       = GPIO_Pin_4,
    .gpioPinSource = GPIO_PinSource4,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM3,
    .timPerif      = RCC_APB1Periph_TIM3,
    .tim           = TIM3,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM3_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare1,
    .getCompare    = TIM_GetCapture1,
    .ocInit        = TIM_OC1Init,
    .preloadConfig = TIM_OC1PreloadConfig,
};

// Deck SCK, PA5, TIM2_CH1
static const MotorPerifDef DECK_SCK =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_5,
    .gpioPinSource = GPIO_PinSource5,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM2,
    .timPerif      = RCC_APB1Periph_TIM2,
    .tim           = TIM2,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM2_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare1,
    .getCompare    = TIM_GetCapture1,
    .ocInit        = TIM_OC1Init,
    .preloadConfig = TIM_OC1PreloadConfig,
};

// Deck MISO, PA6, TIM3_CH1
static const MotorPerifDef DECK_MISO =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_6,
    .gpioPinSource = GPIO_PinSource6,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM3,
    .timPerif      = RCC_APB1Periph_TIM3,
    .tim           = TIM3,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM3_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare1,
    .getCompare    = TIM_GetCapture1,
    .ocInit        = TIM_OC1Init,
    .preloadConfig = TIM_OC1PreloadConfig,
};

// Deck MOSI, PA7, TIM3_CH2
//		#### can be used to output Motor4 instead of E_RX2
//		### this enables USART capability to be used on E_RX2
static const MotorPerifDef DECK_MOSI =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_7,
    .gpioPinSource = GPIO_PinSource7,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM3,
    .timPerif      = RCC_APB1Periph_TIM3,
    .tim           = TIM3,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM3_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare2,
    .getCompare    = TIM_GetCapture2,
    .ocInit        = TIM_OC2Init,
    .preloadConfig = TIM_OC2PreloadConfig,
};

/**
 * Default brushed mapping to M1-M4 connectors.
 */
const MotorPerifDef* motorMapDefaultBrushed[NBR_OF_MOTORS] =
{
  &CONN_M1,
  &CONN_M2,
  &CONN_M3,
  &CONN_M4
};

/**
 * Brushless motors mapped as on the Big-Quad deck
 * M1 -> IO3
 * M2 -> TX2
 * M3 -> RX2
 * M4 -> IO2
 */
const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS] =
{
	&DECK_TX2_TIM2,
	&DECK_IO3,
	&DECK_IO2,
	&DECK_MOSI
	
//  &DECK_RX2_TIM2 remapped Motor4 to CPPM Connector to free up USART on E_RX2

};

/**
 * Brushless motors mapped to the standard motor connectors with pull-ups (~1K) to VBAT soldered.
 */
const MotorPerifDef* motorMapDefaltConBrushless[NBR_OF_MOTORS] =
{
  &CONN_M1_BL,
  &CONN_M2_BL,
  &CONN_M3_BL,
  &CONN_M4_BL
};


Re: Uncontrolled Motor Spinup

Posted: Wed Jun 29, 2016 1:57 pm
by tobias
First thing as you anticipated you found a typo in the comment, the mapping should be as in the definition:

Code: Select all

/**
 * Brushless motors mapped as on the Big-Quad deck
 * M1 -> TX2
 * M2 -> IO3
 * M3 -> IO2
 * M4 -> RX2
 */
As for the difference in log value pf the PWM and the output I'm not so sure, could it be a resource conflict? Measuring the true output with a scope might be the quickest way to find out. I might have an idea why they drift apart though and that might be because the yaw input isn't zero and as it is a "rate" input the error quickly gest accumulated and if the CF2 can't compensate for it, e.g. because of standing on the ground, that will be the effect. If you have modded the extrx module to decode the SBUS you can have a look at the log values to see if they are zero or not.

Might be a dumb question but couldn't you have used the RX1 (GPS input) for the SBUS?

Re: Uncontrolled Motor Spinup

Posted: Wed Jun 29, 2016 9:44 pm
by TU_KL_Robotics
First of all thank you for the clarification regarding the motormapping. The commented section caused quite some confusion.

Monitoring the output with a scope showed us, that althoug the logging claims to raise M1 and M3 speed, the actual output was only increasing on motor 1.
Reconfiguring our Radiotransmitter to have a deadband around the neutral position of the left stick helped to assure, that yaw is exactly at 0. This improved the uncontrolled spinup. Setting the throttel to a rather low value and letting the motors spin does not cause problems anymore.
Hovering the copter however is currently still not possible. When trying to liftoff, a small Yaw input to the right results in an uncontrollable accumulating error, which spins up Motor 1 and 3. Interestingly the error still keeps rising, even if YAW is lowered to 0 again.

Right now the question remains, why flying with the quadcopter was possible without this problem, when we previously used USART1 to read the SBUS signal. Since we did not change anything in the code apart from, from which usart the sbus signal is read, liftoff should not have been working from the beginning.

The next step for us is to implement autonomus, GPS based flight. Therefore the GPS Port isn't available for anything other than the GPS Module.

Re: Uncontrolled Motor Spinup

Posted: Thu Jun 30, 2016 2:36 pm
by TU_KL_Robotics
Today we made a few more tests.

We took our firmware where eeprom test failed, but with untouched bigquaddeck motormapping. As described, sometimes initialisation was succesful and we were able to fly the crazyflie with Taranis radio. The control was very good without any issue.

Then we only changed the last motor output so it was mapped to cppm header of bigquaddeck, as you can see in the following code extract

Code: Select all

const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS] =
{
  &DECK_TX2_TIM2,
  &DECK_IO3,
  &DECK_IO2,
  &DECK_MOSI
};
Afterwards we made a testflight again and we encountered the same problems as before: The quadrocopter tilted to the back left side, we were not able to compensate this even with countersteering.

We would be very happy if someone else could try to reproduce this behavior. For this modification it is necessary to hook up a 1k pullup resistor between cppm signal pin and vcc.

Re: Uncontrolled Motor Spinup

Posted: Thu Jun 30, 2016 6:04 pm
by tobias
I think I found the problem. Motor output IO2 is also mapped to TIM3 CH2 so there is a conflict.

I see no problem in running the UART1_RX instead of I2C1_SDA as the eeprom is only read at startup so if the peripheral is switched after that is should be fine. As the I2C1_CLK isn't clocked the eeprom will not answer to traffic on UART1_RX. You will however not be able to write to the eeprom after that so doing configs from the cfclient will not be possible without switching to I2C mode again and disconnecting the receiver.

Re: Uncontrolled Motor Spinup

Posted: Fri Jul 01, 2016 8:07 am
by TU_KL_Robotics
Thanks for your help!
We already checked if each motor output pin has its own timer channel and at this point we didn't find any conflict. But only taking account of the comments in code, not the actual allocation!
Regarding STM32 datasheet, the real timer mapping is following:

DECK_TX2_TIM2 --> TIM2_CH3
DECK_IO3 --> TIM3_CH1
DECK_IO2 --> TIM3_CH2
DECK_MOSI --> TIM3_CH2

So again we got trapped with the wrong code comments.

Would it be possible to use TIM14_CH1 instead of TIM3_CH2 for DECK_MOSI Pin? This would be the changes to make in code:

Code: Select all

static const MotorPerifDef DECK_MOSI =
{
    .drvType       = BRUSHLESS,
    .gpioPerif     = RCC_AHB1Periph_GPIOA,
    .gpioPort      = GPIOA,
    .gpioPin       = GPIO_Pin_7,
    .gpioPinSource = GPIO_PinSource7,
    .gpioOType     = GPIO_OType_OD,
    .gpioAF        = GPIO_AF_TIM14,
    .timPerif      = RCC_APB1Periph_TIM14,
    .tim           = TIM14,
    .timPolarity   = TIM_OCPolarity_High,
    .timDbgStop    = DBGMCU_TIM14_STOP,
    .timPeriod     = MOTORS_BL_PWM_PERIOD,
    .timPrescaler  = MOTORS_BL_PWM_PRESCALE,
    .setCompare    = TIM_SetCompare1,
    .getCompare    = TIM_GetCapture1,
    .ocInit        = TIM_OC1Init,
    .preloadConfig = TIM_OC1PreloadConfig,
};
If not possible, we would use UART1_RX Pin as you suggested.

Re: Uncontrolled Motor Spinup

Posted: Fri Jul 01, 2016 9:03 am
by tobias
Can you please point me to the comments that are wrong so we can fix it.

We have not tested with other timers so we don't know but in theory it should work so I suggest you to try. The TIM14 is used in the CPPM input as you probably know so that can't be used at the same time.

Re: Uncontrolled Motor Spinup

Posted: Fri Jul 01, 2016 10:57 am
by TU_KL_Robotics
Just tested our setup with TIM14_CH1 on DECK_MOSI Pin.

Now everything works very well, we don't even need the dead band on input channels :lol:

Many thanks for your great help!

Re: Uncontrolled Motor Spinup

Posted: Fri Jul 01, 2016 11:50 am
by TU_KL_Robotics
Additionally we created a pull request on the bitcraze/crazyflie-firmware github with revised comments for the default mapping and a corrected timer for PA7.
We decided to use timer 14 channel 1 and propose this change for the master branch, since it is unlikely someone wants to use cppm and simultaniously wants to change the motor mapping to the cppm pin.

Re: Uncontrolled Motor Spinup

Posted: Sat Jul 02, 2016 5:08 pm
by tobias
Great news!

I think we need some way to detect/prevent TIM14 being in conflict even though it is highly unlikely. Either we do it with the pre-processor so it is not possible to define the mapping and enable CPPM driver at the same time, or doing it in runtime so the CPPM driver can't initialize.