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

Added support for the ADC converter.

parent 2ea23ed4
No related branches found
No related tags found
No related merge requests found
...@@ -197,6 +197,63 @@ bool CBioloidRobot::is_button_pressed(pushbutton_t pushbutton) ...@@ -197,6 +197,63 @@ bool CBioloidRobot::is_button_pressed(pushbutton_t pushbutton)
return false; return false;
} }
// ADC interface
void CBioloidRobot::adc_enable(void)
{
}
void CBioloidRobot::adc_set_period(unsigned char perios_ms)
{
}
double CBioloidRobot::adc_get_value(adc_t adc)
{
unsigned short int value;
switch(adc)
{
case ADC_CH1: this->robot_device->read_word_register(BIOLOID_ADC_CH1_L,&value);
break;
case ADC_CH2: this->robot_device->read_word_register(BIOLOID_ADC_CH2_L,&value);
break;
case ADC_CH3: this->robot_device->read_word_register(BIOLOID_ADC_CH3_L,&value);
break;
case ADC_CH4: this->robot_device->read_word_register(BIOLOID_ADC_CH4_L,&value);
break;
case ADC_CH5: this->robot_device->read_word_register(BIOLOID_ADC_CH6_L,&value);
break;
case ADC_CH6: this->robot_device->read_word_register(BIOLOID_ADC_CH8_L,&value);
break;
}
return ((double)value)/((double)(1<<12));
}
double CBioloidRobot::adc_get_temperature(void)
{
unsigned short int value;
this->robot_device->read_word_register(BIOLOID_ADC_TEMP_L,&value);
return ((double)value)/((double)(1<<10));
}
double CBioloidRobot::adc_get_vrefint(void)
{
unsigned short int value;
this->robot_device->read_word_register(BIOLOID_ADC_VREF_L,&value);
return ((double)value)/((double)(1<<12));
}
void CBioloidRobot::adc_disable(void)
{
}
// motion manager interface // motion manager interface
/*void CBioloidRobot::mm_set_period(double period_ms) /*void CBioloidRobot::mm_set_period(double period_ms)
{ {
......
...@@ -16,6 +16,8 @@ typedef enum {BIOLOD_MM_NONE=0x00,BIOLOID_MM_ACTION=0x01,BIOLOID_MM_WALKING=0x02 ...@@ -16,6 +16,8 @@ typedef enum {BIOLOD_MM_NONE=0x00,BIOLOID_MM_ACTION=0x01,BIOLOID_MM_WALKING=0x02
typedef enum {USER1_LED,USER2_LED,RXD_LED,TXD_LED} led_t; typedef enum {USER1_LED,USER2_LED,RXD_LED,TXD_LED} led_t;
/* available pushbuttons */ /* available pushbuttons */
typedef enum {USER_PB,RESET_PB,START_PB,MODE_PB} pushbutton_t; typedef enum {USER_PB,RESET_PB,START_PB,MODE_PB} pushbutton_t;
/* available ADC channels */
typedef enum {ADC_CH1, ADC_CH2, ADC_CH3, ADC_CH4, ADC_CH5, ADC_CH6} adc_t;
class CBioloidRobot class CBioloidRobot
{ {
...@@ -109,6 +111,13 @@ class CBioloidRobot ...@@ -109,6 +111,13 @@ class CBioloidRobot
break; break;
} }
} }
// ADC interface
void adc_enable(void);
void adc_set_period(unsigned char perios_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);
unsigned char mm_get_num_servos(void); unsigned char mm_get_num_servos(void);
......
...@@ -35,7 +35,7 @@ int main(int argc, char *argv[]) ...@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
try{ try{
CBioloidRobot tina("Tina",robot_device,921600,0x02,GPIO2,25); CBioloidRobot tina("Tina",robot_device,921600,0x02,GPIO2,25);
tina.assign_button_callback(USER_PB,&callbacks,&CCallbacks::user_pb_callback); /* tina.assign_button_callback(USER_PB,&callbacks,&CCallbacks::user_pb_callback);
tina.assign_button_callback(RESET_PB,&callbacks,&CCallbacks::reset_pb_callback); tina.assign_button_callback(RESET_PB,&callbacks,&CCallbacks::reset_pb_callback);
tina.assign_button_callback(START_PB,&callbacks,&CCallbacks::start_pb_callback); tina.assign_button_callback(START_PB,&callbacks,&CCallbacks::start_pb_callback);
tina.assign_button_callback(MODE_PB,&callbacks,&CCallbacks::mode_pb_callback); tina.assign_button_callback(MODE_PB,&callbacks,&CCallbacks::mode_pb_callback);
...@@ -62,22 +62,19 @@ int main(int argc, char *argv[]) ...@@ -62,22 +62,19 @@ int main(int argc, char *argv[])
tina.clear_led(TXD_LED); tina.clear_led(TXD_LED);
tina.clear_led(USER1_LED); tina.clear_led(USER1_LED);
tina.clear_led(USER2_LED); tina.clear_led(USER2_LED);
sleep(10); sleep(10);*/
/* for(i=0;i<100;i++) for(i=0;i<100;i++)
{ {
if(tina.is_button_pressed(RESET_PB)) std::cout << "temperature: " << tina.adc_get_temperature() << std::endl;
std::cout << "Reset button pressed" << std::endl; std::cout << "Vref_int: " << tina.adc_get_vrefint() << std::endl;
else std::cout << "Channel 1: " << tina.adc_get_value(ADC_CH1) << std::endl;
std::cout << "Reset button not pressed" << std::endl; std::cout << "Channel 2: " << tina.adc_get_value(ADC_CH2) << std::endl;
std::cout << "Channel 3: " << tina.adc_get_value(ADC_CH3) << std::endl;
std::cout << "Channel 4: " << tina.adc_get_value(ADC_CH4) << std::endl;
std::cout << "Channel 5: " << tina.adc_get_value(ADC_CH5) << std::endl;
std::cout << "Channel 6: " << tina.adc_get_value(ADC_CH6) << std::endl;
usleep(100000); usleep(100000);
}*/ }
// tina.clear_led(USER1_LED);
/* for(i=0;i<10;i++)
{
std::cout << "toggle led" << std::endl;
tina.toggle_led(USER1_LED);
sleep(1);
}*/
}catch(CException &e){ }catch(CException &e){
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }
......
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