Skip to content
Snippets Groups Projects
Commit 75f9ea34 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added the necessary API to access the ADC module.

parent b7d9ad23
No related branches found
No related tags found
No related merge requests found
...@@ -193,6 +193,72 @@ bool CDarwinRobot::is_button_pressed(pushbutton_t pushbutton) ...@@ -193,6 +193,72 @@ bool CDarwinRobot::is_button_pressed(pushbutton_t pushbutton)
throw CDarwinRobotException(_HERE_,"Invalid robot device"); 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 // motion manager interface
/*void CDarwinRobot::mm_set_period(double period_ms) /*void CDarwinRobot::mm_set_period(double period_ms)
{ {
......
...@@ -31,6 +31,11 @@ typedef struct ...@@ -31,6 +31,11 @@ typedef struct
typedef enum {START_PB=0,MODE_PB=1} pushbutton_t; 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 class CDarwinRobot
{ {
private: private:
...@@ -50,6 +55,13 @@ class CDarwinRobot ...@@ -50,6 +55,13 @@ class CDarwinRobot
void gpio_aux1_color(double red, double green, double blue); void gpio_aux1_color(double red, double green, double blue);
void gpio_aux2_color(double red, double green, double blue); void gpio_aux2_color(double red, double green, double blue);
bool is_button_pressed(pushbutton_t pushbutton); 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 // motion manager interface
void mm_set_period(double period_ms); void mm_set_period(double period_ms);
double mm_get_period(void); double mm_get_period(void);
...@@ -89,8 +101,6 @@ class CDarwinRobot ...@@ -89,8 +101,6 @@ class CDarwinRobot
bool imu_is_gyro_detected(void); bool imu_is_gyro_detected(void);
void imu_get_accel_data(short int *x,short int *y,short int *z); 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); void imu_get_gyro_data(short int *x,short int *y,short int *z);
// adc interface
void adc_get_data(void);
// walking interface // walking interface
void walking_set_speeds(double fw_step,double side_step,double turn); void walking_set_speeds(double fw_step,double side_step,double turn);
void walking_start(void); void walking_start(void);
......
...@@ -8,6 +8,11 @@ ADD_EXECUTABLE(darwin_gpio_test darwin_gpio_test.cpp) ...@@ -8,6 +8,11 @@ ADD_EXECUTABLE(darwin_gpio_test darwin_gpio_test.cpp)
# link necessary libraries # link necessary libraries
TARGET_LINK_LIBRARIES(darwin_gpio_test darwin_robot) 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 # create an example application
#ADD_EXECUTABLE(darwin_joint_motion_test darwin_joint_motion_test.cpp) #ADD_EXECUTABLE(darwin_joint_motion_test darwin_joint_motion_test.cpp)
# link necessary libraries # link necessary libraries
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment