Commit 9cfc070e authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added the gyro module (initial version).

Added a file wit the motion pages ID's.
parent a60463df
#ifndef _ACTION_ID_H
#define _ACTION_ID_H
#define BOW 1
#define BRAVO 2
#define RAP_CHEST 5
#define SCRATCH_HEAD 8
#define HAND_STANDING 11
#define R_BLOCKING 14
#define L_BLOCKING 16
#define L_KICK 18
#define R_KICK 19
#define R_ATTACK 20
#define L_ATTACK 21
#define F_ATTACK 22
#define DEFENCE 23
#define SIT_DOWN 25
#define STANF_UP 26
#define F_GET_UP 27
#define B_GET_UP 28
#define CLAP_READY 29
#define CLAPPING 30
#define WALK_READY 31
/* forward step */
#define F_S_L 32
#define F_S_R 34
#define F_M_L 36
#define F_M_R 38
#define F_E_L 40
#define F_E_R 42
/* backward step */
#define B_S_L 44
#define B_S_R 46
#define B_M_L 48
#define B_M_R 50
#define B_E_L 52
#define B_E_R 54
/* left turn step */
#define LT_S_L 56
#define LT_S_R 58
#define LT_M_L 60
#define LT_M_R 62
#define LT_E_L 64
#define LT_E_R 66
/* right turn step */
#define RT_S_L 68
#define RT_S_R 70
#define RT_M_L 72
#define RT_M_R 74
#define RT_E_L 76
#define RT_E_R 78
/* left step */
#define L_S_L 80
#define L_S_R 82
#define L_M_L 84
#define L_M_R 86
#define L_E_L 88
#define L_E_R 90
/* right step */
#define R_S_L 92
#define R_S_R 94
#define R_M_L 96
#define R_M_R 98
#define R_E_L 100
#define R_E_R 102
/* forward left turn step */
#define FLT_S_L 104
#define FLT_S_R 106
#define FLT_M_L 108
#define FLT_M_R 110
#define FLT_E_L 112
#define FLT_E_R 114
/* forward right turn step */
#define FRT_S_L 116
#define FRT_S_R 118
#define FRT_M_L 120
#define FRT_M_R 122
#define FRT_E_L 124
#define FRT_E_R 126
/* backward left turn step */
#define BLT_S_L 128
#define BLT_S_R 130
#define BLT_M_L 132
#define BLT_M_R 134
#define BLT_E_L 136
#define BLT_E_R 138
/* backward right turn step */
#define BRT_S_L 140
#define BRT_S_R 142
#define BRT_M_L 144
#define BRT_M_R 146
#define BRT_E_L 148
#define BRT_E_R 150
/* left turn A??? step */
#define LTA_S_L 152
#define LTA_S_R 154
#define LTA_M_L 156
#define LTA_M_R 158
#define LTA_E_L 160
#define LTA_E_R 162
/* right turn A?? step */
#define RTA_S_L 164
#define RTA_S_R 166
#define RTA_M_L 168
#define RTA_M_R 170
#define RTA_E_L 172
#define RTA_E_R 174
/* forward left step */
#define FL_S_L 176
#define FL_S_R 178
#define FL_M_L 180
#define FL_M_R 182
#define FL_E_L 184
#define FL_E_R 186
/* forward right step */
#define FR_S_L 188
#define FR_S_R 190
#define FR_M_L 192
#define FR_M_R 194
#define FR_E_L 196
#define FR_E_R 198
/* backward left step */
#define BL_S_L 200
#define BL_S_R 202
#define BL_M_L 204
#define BL_M_R 206
#define BL_E_L 208
#define BL_E_R 210
/* backward right step */
#define BR_S_L 212
#define BR_S_R 214
#define BR_M_L 216
#define BR_M_R 218
#define BR_E_L 220
#define BR_E_R 222
#define BALANCE 224
#define CLAP_END 225
#endif
#endif
......@@ -7,10 +7,15 @@ extern "C" {
#include "stm32f4xx_hal.h"
typedef enum {ADC_CH1,ADC_CH2,ADC_CH3,ADC_CH4,ADC_CH6,ADC_CH8} adc_ch_t;
// public functions
void adc_init(void);
void adc_start(void);
void adc_set_period(uint8_t period_ms);
unsigned short adc_get_channel(adc_ch_t channel);
unsigned short adc_get_channel_raw(adc_ch_t channel);
unsigned short adc_get_temperature(void);
void adc_stop(void);
// operation functions
uint8_t adc_in_range(unsigned short int address,unsigned short int length);
......
#ifndef BIOLOID_GYRO_H
#define BIOLOID_GYRO_H
/* public functions */
void gyro_init(void);
#endif
......@@ -11,6 +11,8 @@ extern "C" {
#define BAUDRATE_OFFSET ((unsigned short int)0x0004)
#define RETURN_DELAY_OFFSET ((unsigned short int)0x0005)
#define MM_PERIOD_OFFSET ((unsigned short int)0x0006)
#define GYRO_FB_ADC_CH_OFFSET ((unsigned short int)0x0007)
#define GYRO_LR_ADC_CH_OFFSET ((unsigned short int)0x0008)
#define RETURN_LEVEL_OFFSET ((unsigned short int)0x0010)
#define LAST_EEPROM_OFFSET ((unsigned short int)0x0020)
......@@ -24,6 +26,8 @@ typedef enum {
BIOLOID_RETURN_DELAY_TIME = RETURN_DELAY_OFFSET,
BIOLOID_MM_PERIOD_L = MM_PERIOD_OFFSET,
BIOLOID_MM_PERIOD_H = MM_PERIOD_OFFSET+1,
BIOLIOD_GYRO_FB_ADC_CH = GYRO_FB_ADC_CH_OFFSET,
BIOLIOD_GYRO_LR_ADC_CH = GYRO_LR_ADC_CH_OFFSET,
BIOLOID_RETURN_LEVEL = RETURN_LEVEL_OFFSET,
BIOLOID_USER1_LED_CNTRL = 0x20, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
......@@ -179,8 +183,16 @@ typedef enum {
BIOLOID_MM_SERVO31_CUR_POS_L = 0x98,
BIOLOID_MM_SERVO31_CUR_POS_H = 0x99,
BIOLOID_ACTION_PAGE = 0x9A,
BIOLOID_ACTION_CNTRL = 0x9B // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
BIOLOID_ACTION_CNTRL = 0x9B, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | page running | interrupt flag | enable interrupt | stop page | start page
BIOLOID_GYRO_CNTRL = 0x9C, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
//
BIOLOID_GYRO_STATUS = 0x9D, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
//
BIOLOID_GYRO_FWD_FALL_THD = 0x9E,
BIOLOID_GYRO_BWD_FALL_THD = 0x9F,
BIOLOID_GYRO_LEFT_FALL_THD = 0xA0,
BOILOID_GYRO_RIGHT_FALL_THD = 0xA1
} bioloid_registers;
#define GPIO_BASE_ADDRESS 0x20
......
......@@ -362,6 +362,57 @@ void adc_set_period(uint8_t period_ms)
adc_period_ms=period_ms*84;
}
uint16_t adc_get_channel(adc_ch_t channel)
{
uint16_t value;
switch(channel)
{
case ADC_CH1: ram_data[BIOLOID_ADC_CH1_L]+ram_data[BIOLOID_ADC_CH1_H]*256;
break;
case ADC_CH2: ram_data[BIOLOID_ADC_CH2_L]+ram_data[BIOLOID_ADC_CH2_H]*256;
break;
case ADC_CH3: ram_data[BIOLOID_ADC_CH3_L]+ram_data[BIOLOID_ADC_CH3_H]*256;
break;
case ADC_CH4: ram_data[BIOLOID_ADC_CH4_L]+ram_data[BIOLOID_ADC_CH4_H]*256;
break;
case ADC_CH6: ram_data[BIOLOID_ADC_CH6_L]+ram_data[BIOLOID_ADC_CH6_H]*256;
break;
case ADC_CH8: ram_data[BIOLOID_ADC_CH8_L]+ram_data[BIOLOID_ADC_CH8_H]*256;
break;
}
return value;
}
uint16_t adc_get_channel_raw(adc_ch_t channel)
{
uint16_t value;
switch(channel)
{
case ADC_CH1: value=adc_data[0]&0x0000FFFF;
break;
case ADC_CH2: value=(adc_data[0]&0xFFFF0000)>>16;
break;
case ADC_CH3: value=adc_data[1]&0x0000FFFF;
break;
case ADC_CH4: value=(adc_data[1]&0xFFFF0000)>>16;
break;
case ADC_CH6: value=(adc_data[2]&0xFFFF0000)>>16;
break;
case ADC_CH8: value=(adc_data[3]&0xFFFF0000)>>16;
break;
}
return value;
}
uint16_t adc_get_temperature(void)
{
return ram_data[BIOLOID_ADC_TEMP_L]+ram_data[BIOLOID_ADC_TEMP_H]*256;
}
void adc_stop(void)
{
ram_data[BIOLOID_ADC_CNTRL]&=0xFE;
......
#include "bioloid_gyro.h"
#include "adc_dma.h"
/* private functions */
/* public functions */
void gyro_init(void)
{
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment