From: Xavier L. <Ba...@us...> - 2012-01-28 16:00:55
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 356ea449946b76d194a653473fe99df01c6b6b1a (commit) from 40a60d3a36a22d90795f4a64353fd34cedc4a79a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 356ea449946b76d194a653473fe99df01c6b6b1a Author: Xavier Lagorce <Xav...@cr...> Date: Sat Jan 28 17:03:30 2012 +0100 [Controller_Motor_STM32/lib] Added helpers to rescale encoder output ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.c b/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.c index 6552dbb..10587f0 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.c @@ -12,6 +12,12 @@ #include "stm32lib/stm32f10x_rcc.h" #include "stm32lib/stm32f10x_tim.h" +typedef struct { + uint16_t origin; + float scale; +} enc_params_t; + +enc_params_t enc_params[4]; /* * Function to initialise one encoder interface @@ -101,6 +107,20 @@ void encodersInit(void) { TIM_Cmd(TIM8,ENABLE); TIM_Cmd(TIM1,ENABLE); TIM_Cmd(TIM4,ENABLE); + + // Initialize scaling factors + for (int i=0; i < 4; i++) { + enc_params[i].origin = 0; + enc_params[i].scale= 1.0; + } +} + +/* + * Helper to set the sacling factor for the readout helper + */ +void setEncoderScaling(uint8_t encoder, uint16_t origin, float scale) { + enc_params[encoder].origin = origin; + enc_params[encoder].scale = scale; } /* @@ -125,6 +145,14 @@ uint16_t getEncoderPosition(uint8_t encoder) { return 0; } } +/* + * Helper to get the current encoder position after the applying + * some scaling factors + */ +float getEncoderPosition_f(uint8_t encoder) { + return enc_params[encoder].scale * + (getEncoderPosition(encoder) - enc_params[encoder].origin); +} /* * Helper to get the current direction of evolution of the counter diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.h b/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.h index e94ac88..729c10e 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/lib/encoder.h @@ -6,10 +6,10 @@ #ifndef HEADER__ENCODER #define HEADER__ENCODER -#define ENCODER1 1 -#define ENCODER2 2 -#define ENCODER3 3 -#define ENCODER4 4 +#define ENCODER1 0 +#define ENCODER2 1 +#define ENCODER3 2 +#define ENCODER4 3 #define ENCODER_DIR_UP 0 #define ENCODER_DIR_DOWN 1 @@ -17,9 +17,32 @@ #include <drv/gpio_stm32.h> #include <drv/clock_stm32.h> +/* + * Intializes the encoder interface + */ void encodersInit(void); +/* + * Sets the scaling factors for readout helper + */ +void setEncoderScaling(uint8_t encoder, uint16_t origin, float scale); + +/* + * Returns the current position of a particular encoder + */ uint16_t getEncoderPosition(uint8_t encoder); +/* + * Gets the corrent value of an encoder after scaling process + */ +float getEncoderPosition_f(uint8_t encoder); + +/* + * Resets the counter register associated to a given encoder + */ void resetEncoderPosition(uint8_t encoder); + +/* + * Gets the direction of the evolution of an encoder value + */ uint8_t getEncoderDirection(uint8_t encoder); #endif hooks/post-receive -- krobot |