Skip to content

Commit

Permalink
Merge pull request #1 from bitcraze/master
Browse files Browse the repository at this point in the history
최신 업데이트
  • Loading branch information
chcbaram committed Aug 21, 2015
2 parents 5ce44cc + db20e52 commit 55a0360
Show file tree
Hide file tree
Showing 21 changed files with 1,193 additions and 385 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ PROJ_OBJ_CF2 += imu_cf2.o pm_f405.o syslink.o radiolink.o ow_syslink.o proximity
PROJ_OBJ += system.o comm.o console.o pid.o crtpservice.o param.o mem.o
PROJ_OBJ += commander.o controller.o sensfusion6.o stabilizer.o
PROJ_OBJ += log.o worker.o trigger.o sitaw.o
PROJ_OBJ_CF2 += neopixelring.o expbrd.o platformservice.o
PROJ_OBJ_CF2 += neopixelring.o expbrd.o platformservice.o bigquad.o

# Expansion boards
PROJ_OBJ_CF2 += exptest.o
Expand Down
6 changes: 3 additions & 3 deletions config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define PROTOCOL_VERSION 2

#ifdef STM32F4XX
#define P_NAME "Crazyflie 2.0 Rev.C"
#define P_NAME "Crazyflie 2.0"
#define QUAD_FORMATION_X

#define CONFIG_BLOCK_ADDRESS (2048 * (64-1))
Expand All @@ -57,8 +57,8 @@
#define FREERTOS_MCU_CLOCK_HZ 168000000

#else
#define P_NAME "Crazyflie Rev.F"
#define CONFIG_BLOCK_ADDRESS (1024 * (64-1))
#define P_NAME "Crazyflie 1.0"
#define CONFIG_BLOCK_ADDRESS (1024 * (128-1))
#define MCU_ID_ADDRESS 0x1FFFF7E8
#define MCU_FLASH_SIZE_ADDRESS 0x1FFFF7E0
#define FREERTOS_HEAP_SIZE 15000
Expand Down
58 changes: 34 additions & 24 deletions drivers/interface/motors.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,10 @@
#include "stm32fxxx.h"

/******** Defines ********/
/**
* *VARNING* Flashing the brushless driver on the Crazyflie with normal brushed motors connected
* will turn it on at full speed when it is powered on!
*
* Generates a PWM wave (50 - 200 Hz update rate with 1-2 ms high pulse) using the timer. That way we can use the same
* base as for the regular PWM driver. This means it will be a PWM with a period of the update rate configured to be high
* only in the 1-2 ms range.
* The BLMC input signal are meant to be connected to the Crazyflie round motor solder pad (open-drain output). A resistor
* around 470 ohm needs to pull the signal high to the voltage level of the BLMC (normally 5V).
*/
#define BLMC_PERIOD 0.0025 // 2.5ms = 400Hz
#define TIM_CLOCK_HZ 84000000
#define MOTORS_BL_PWM_PRESCALE_RAW (uint32_t)((TIM_CLOCK_HZ/0xFFFF) * BLMC_PERIOD + 1) // +1 is to not end up above 0xFFFF in the end
#define MOTORS_BL_PWM_CNT_FOR_PERIOD (uint32_t)(TIM_CLOCK_HZ * BLMC_PERIOD / MOTORS_BL_PWM_PRESCALE_RAW)
#define MOTORS_BL_PWM_CNT_FOR_1MS (uint32_t)(TIM_CLOCK_HZ * 0.001 / MOTORS_BL_PWM_PRESCALE_RAW)
#define MOTORS_BL_PWM_PERIOD MOTORS_BL_PWM_CNT_FOR_PERIOD
#define MOTORS_BL_PWM_PRESCALE (uint16_t)(MOTORS_BL_PWM_PRESCALE_RAW - 1)
#define MOTORS_BL_POLARITY TIM_OCPolarity_Low

#ifdef PLATFORM_CF1
// The following defines gives a PWM of 9 bits at ~140KHz for a sysclock of 72MHz
#define TIM_CLOCK_HZ 72000000
#define MOTORS_PWM_BITS 9
#define MOTORS_PWM_PERIOD ((1<<MOTORS_PWM_BITS) - 1)
#define MOTORS_PWM_PRESCALE 0
Expand All @@ -76,6 +59,7 @@
#else
// The following defines gives a PWM of 8 bits at ~328KHz for a sysclock of 168MHz
// CF2 PWM ripple is filtered better at 328kHz. At 168kHz the NCP702 regulator is affected.
#define TIM_CLOCK_HZ 84000000
#define MOTORS_PWM_BITS 8
#define MOTORS_PWM_PERIOD ((1<<MOTORS_PWM_BITS) - 1)
#define MOTORS_PWM_PRESCALE 0
Expand All @@ -94,6 +78,22 @@
#define ENABLE_THRUST_BAT_COMPENSATED
#endif

/**
* *VARNING* Make sure the brushless driver is configured correctly as on the Crazyflie with normal
* brushed motors connected they can turn on at full speed when it is powered on!
*
* Generates a PWM wave (50 - 400 Hz update rate with 1-2 ms high pulse) using the timer. That way we can use the same
* base as for the regular PWM driver. This means it will be a PWM with a period of the update rate configured to be high
* only in the 1-2 ms range.
*/
#define BLMC_PERIOD 0.0025 // 2.5ms = 400Hz
#define MOTORS_BL_PWM_PRESCALE_RAW (uint32_t)((TIM_CLOCK_HZ/0xFFFF) * BLMC_PERIOD + 1) // +1 is to not end up above 0xFFFF in the end
#define MOTORS_BL_PWM_CNT_FOR_PERIOD (uint32_t)(TIM_CLOCK_HZ * BLMC_PERIOD / MOTORS_BL_PWM_PRESCALE_RAW)
#define MOTORS_BL_PWM_CNT_FOR_1MS (uint32_t)(TIM_CLOCK_HZ * 0.001 / MOTORS_BL_PWM_PRESCALE_RAW)
#define MOTORS_BL_PWM_PERIOD MOTORS_BL_PWM_CNT_FOR_PERIOD
#define MOTORS_BL_PWM_PRESCALE (uint16_t)(MOTORS_BL_PWM_PRESCALE_RAW - 1)
#define MOTORS_BL_POLARITY TIM_OCPolarity_Low

#define NBR_OF_MOTORS 4
// Motors IDs define
#define MOTOR_M1 0
Expand Down Expand Up @@ -163,12 +163,20 @@
#define FULL 1000
#define STOP 0

typedef enum
{
BRUSHED,
BRUSHLESS
} motorsDrvType;

typedef struct
{
motorsDrvType drvType;
uint32_t gpioPerif;
GPIO_TypeDef* gpioPort;
uint32_t gpioPin;
uint32_t gpioPinSource;
uint32_t gpioOType;
uint32_t gpioAF;
uint32_t timPerif;
TIM_TypeDef* tim;
Expand All @@ -177,8 +185,6 @@ typedef struct
uint32_t timPeriod;
uint16_t timPrescaler;
/* Function pointers */
uint16_t (*convBitsTo16)(uint16_t bits);
uint16_t (*conv16ToBits)(uint16_t bits);
#ifdef PLATFORM_CF1
void (*setCompare)(TIM_TypeDef* TIMx, uint16_t Compare);
uint16_t (*getCompare)(TIM_TypeDef* TIMx);
Expand All @@ -190,7 +196,11 @@ typedef struct
void (*preloadConfig)(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
} MotorPerifDef;

extern const MotorPerifDef* motorMapBrushed[NBR_OF_MOTORS];
/**
* Motor mapping configurations
*/
extern const MotorPerifDef* motorMapDefaultBrushed[NBR_OF_MOTORS];
extern const MotorPerifDef* motorMapDefaltConBrushless[NBR_OF_MOTORS];
extern const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS];

/*** Public interface ***/
Expand All @@ -201,7 +211,7 @@ extern const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS];
void motorsInit(const MotorPerifDef** motorMapSelect);

/**
* DeInitialisation. Reset to defult
* DeInitialisation. Reset to default
*/
void motorsDeInit(const MotorPerifDef** motorMapSelect);

Expand All @@ -214,12 +224,12 @@ bool motorsTest(void);
/**
* Set the PWM ratio of the motor 'id'
*/
void motorsSetRatio(int id, uint16_t ratio);
void motorsSetRatio(uint32_t id, uint16_t ratio);

/**
* Get the PWM ratio of the motor 'id'. Return -1 if wrong ID.
*/
int motorsGetRatio(int id);
int motorsGetRatio(uint32_t id);

/**
* FreeRTOS Task to test the Motors driver
Expand Down
Loading

0 comments on commit 55a0360

Please sign in to comment.