diff --git a/src/darwin_robot.cpp b/src/darwin_robot.cpp index a3ad4e545c90890861b4a9a5f9778fd33a61c022..02c857f87a83acd493831c8ddc145dc66549dcde 100644 --- a/src/darwin_robot.cpp +++ b/src/darwin_robot.cpp @@ -193,6 +193,72 @@ bool CDarwinRobot::is_button_pressed(pushbutton_t pushbutton) throw CDarwinRobotException(_HERE_,"Invalid robot device"); } +// ADC interface +void CDarwinRobot::adc_enable(void) +{ + if(this->robot_device!=NULL) + this->robot_device->write_byte_register(DARWIN_ADC_CNTRL,ADC_START); + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} + +void CDarwinRobot::adc_set_period(unsigned char period_ms) +{ + if(this->robot_device!=NULL) + this->robot_device->write_byte_register(DARWIN_ADC_PERIOD,period_ms); + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} +double CDarwinRobot::adc_get_value(adc_t adc) +{ + unsigned short int value; + + if(this->robot_device!=NULL) + { + this->robot_device->read_word_register(DARWIN_ADC_CH1_L+((int)adc)*2,&value); + + return ((double)value)/((double)(1<<12)); + } + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} + +double CDarwinRobot::adc_get_temperature(void) +{ + unsigned short int value; + + if(this->robot_device!=NULL) + { + this->robot_device->read_word_register(DARWIN_ADC_TEMP_L,&value); + + return ((double)value)/((double)(1<<10)); + } + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} + +double CDarwinRobot::adc_get_vrefint(void) +{ + unsigned short int value; + + if(this->robot_device!=NULL) + { + this->robot_device->read_word_register(DARWIN_ADC_VREF_L,&value); + + return ((double)value)/((double)(1<<12)); + } + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} + +void CDarwinRobot::adc_disable(void) +{ + if(this->robot_device!=NULL) + this->robot_device->write_byte_register(DARWIN_ADC_CNTRL,ADC_STOP); + else + throw CDarwinRobotException(_HERE_,"Invalid robot device"); +} + // motion manager interface /*void CDarwinRobot::mm_set_period(double period_ms) { diff --git a/src/darwin_robot.h b/src/darwin_robot.h index 3bb810ae47edc11a3caf678f9064daf72a501ed2..ee2cf12e69e563d1405f454f1846be07bd387c09 100644 --- a/src/darwin_robot.h +++ b/src/darwin_robot.h @@ -31,6 +31,11 @@ typedef struct typedef enum {START_PB=0,MODE_PB=1} pushbutton_t; +#define ADC_NUM_CHANNELS 16 + +typedef enum {ADC_CH1=0,ADC_CH2=1,ADC_CH3=2,ADC_CH4=3,ADC_CH5=4,ADC_CH6=5,ADC_CH7=6,ADC_CH8=7, + ADC_CH9=8,ADC_CH10=9,ADC_CH11=10,ADC_CH12=11,ADC_CH13=12,ADC_CH14=13,ADC_CH16=15,ADC_CH18=17} adc_t; + class CDarwinRobot { private: @@ -50,6 +55,13 @@ class CDarwinRobot void gpio_aux1_color(double red, double green, double blue); void gpio_aux2_color(double red, double green, double blue); bool is_button_pressed(pushbutton_t pushbutton); + // ADC interface + void adc_enable(void); + void adc_set_period(unsigned char period_ms); + double adc_get_value(adc_t adc); + double adc_get_temperature(void); + double adc_get_vrefint(void); + void adc_disable(void); // motion manager interface void mm_set_period(double period_ms); double mm_get_period(void); @@ -89,8 +101,6 @@ class CDarwinRobot bool imu_is_gyro_detected(void); void imu_get_accel_data(short int *x,short int *y,short int *z); void imu_get_gyro_data(short int *x,short int *y,short int *z); - // adc interface - void adc_get_data(void); // walking interface void walking_set_speeds(double fw_step,double side_step,double turn); void walking_start(void); diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 72a43c17331bff04616c7f278776dba807e4297f..eafec7f769a1af0c36b754191f697cdfc5613094 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -8,6 +8,11 @@ ADD_EXECUTABLE(darwin_gpio_test darwin_gpio_test.cpp) # link necessary libraries TARGET_LINK_LIBRARIES(darwin_gpio_test darwin_robot) +# create an example application +ADD_EXECUTABLE(darwin_adc_test darwin_adc_test.cpp) +# link necessary libraries +TARGET_LINK_LIBRARIES(darwin_adc_test darwin_robot) + # create an example application #ADD_EXECUTABLE(darwin_joint_motion_test darwin_joint_motion_test.cpp) # link necessary libraries