BoardController Class Reference

#include <BoardController.h>


Static Public Member Functions

static void blinkLED (unsigned char led_id, unsigned int count, unsigned int delay)
static void disableSerialInterfaces ()
static void disableV24Interrupt ()
static void enableSerialBioloidInterface ()
static void enableSerialV24Interface ()
static void enableV24Interrupt ()
static unsigned char getSwitchState (unsigned char _switch)
static void initPorts ()
static void msDelay (int n)
static void powerOnLED (unsigned char _ledID, bool _status)


Detailed Description

Definition at line 50 of file BoardController.h.


Member Function Documentation

void BoardController::blinkLED ( unsigned char  led_id,
unsigned int  count,
unsigned int  delay 
) [static]

Definition at line 166 of file BoardController.c.

References LED_EXPLORATION, LED_LEARN, LED_POWER, LED_WALK, msDelay(), and powerOnLED().

Referenced by Environment::doAction(), ValueIteration::getGreedyAction(), main(), ValueIteration::moveAndSaveFeedback(), BioloidServo::pingServo(), BioloidServo::RxPacket(), TestClass::TestClass(), and TestClass::testFunction().

00166                                                                                             {
00167 
00168      unsigned char i;
00169 //   DDRB = 0x0F;
00170 //   PORTB |= (1<<PA4) | (1<<PA5) | (1<<PA6) | (1<<PA7);
00171 
00172      for (i=0; i<count; i++) {
00173 
00174           if (led_id & (1<<LED_WALK)) powerOnLED ( LED_WALK, true);
00175           if (led_id & (1<<LED_LEARN)) powerOnLED ( LED_LEARN, true);
00176           if (led_id & (1<<LED_EXPLORATION)) powerOnLED ( LED_EXPLORATION, true);
00177           if (led_id & (1<<LED_POWER)) powerOnLED ( LED_POWER, true);
00178 
00179           msDelay (delay);
00180 
00181           if (led_id & (1<<LED_LEARN)) powerOnLED ( LED_LEARN, false);
00182           if (led_id & (1<<LED_WALK)) powerOnLED ( LED_WALK, false);
00183           if (led_id & (1<<LED_EXPLORATION)) powerOnLED ( LED_EXPLORATION, false);
00184           if (led_id & (1<<LED_POWER)) powerOnLED ( LED_POWER, true);
00185 
00186           msDelay (delay);
00187      }
00188 }

Here is the call graph for this function:

void BoardController::disableSerialInterfaces (  )  [static]

Definition at line 255 of file BoardController.c.

References EN_AIR_V24, EN_RXD_BIOLOID, EN_TXD_BIOLOID, enableSerialV24Interface(), getSwitchState(), and SWITCH_V24.

Referenced by BioloidServo::BioloidServo(), Environment::doAction(), BioloidServo::scanBioloidBus(), and BioloidServo::setPosition().

00255                                               {
00256 
00257      //PORTC  &= ~(1<<CTS);
00258 
00259      // disable serial wires
00260      PORTC  &= ~((1<<EN_TXD_BIOLOID) | (1<<EN_RXD_BIOLOID) | (1<<EN_AIR_V24));
00261      UCSRB &= ~((1<<TXEN) | (1<<RXEN));   // disable TX and RX
00262 
00263      if (getSwitchState(SWITCH_V24)) {
00264           enableSerialV24Interface();
00265      }
00266 }

Here is the call graph for this function:

void BoardController::disableV24Interrupt (  )  [static]

disable serial interrupt

Definition at line 132 of file BoardController.c.

References getSwitchState(), and SWITCH_V24.

Referenced by enableV24Interrupt(), main(), and V24Control::processCommand().

00132                                           { 
00133      if (getSwitchState(SWITCH_V24)) {
00134           //UCSRB &= ~(1 << RXCIE); 
00135           //cli();
00136      }
00137      //PORTC  |= (1<<PC3);
00138      //PORTC |= (1<<PC3);
00139      //UCSRB &= ~(1<<RXEN);
00140 }

Here is the call graph for this function:

void BoardController::enableSerialBioloidInterface (  )  [static]

setup the serial interface

Definition at line 192 of file BoardController.c.

References BIOLOID_UBRR, EN_AIR_V24, EN_RXD_BIOLOID, EN_TXD_BIOLOID, and RTS.

Referenced by BioloidServo::BioloidServo(), Environment::doAction(), BioloidServo::scanBioloidBus(), and BioloidServo::setPosition().

00192                                                    {
00193 
00194      // indicate Host that serial line is not ready for reception
00195      PORTC  |= (1<<RTS);
00196 
00197      // disable serial wires
00198      PORTC  &= ~((1<<EN_TXD_BIOLOID) | (1<<EN_RXD_BIOLOID) | (1<<EN_AIR_V24));
00199 
00200      // flushing the buffer
00201      unsigned char dummy;
00202      while (UCSRA & (1<<RXC)) dummy = UDR;
00203 
00204      // ** Serial init **
00205      // 1) USART
00206      //UCSRB &= ~((1<<TXEN) | (1<<RXEN));   // disable TX and RX
00207 
00208      // set baudrate 
00209      UBRRH = (unsigned char) (BIOLOID_UBRR >> 8);  // load the upper bits
00210      UBRRL = (unsigned char) BIOLOID_UBRR; 
00211 
00212      UCSRA |= (1<<U2X);
00213      UCSRB |= ((1<<TXEN) | (1<<RXEN));   // enable transmit and receive.enable TX and RX
00214      //UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0); // Frame Format: 8data, 1stop bit, noParity 
00215 
00216      // enable bioloid transmission pin
00217      PORTC  |= (1<<EN_TXD_BIOLOID);
00218      PORTC  &= ~((1<<EN_RXD_BIOLOID) | (1<<EN_AIR_V24));
00219 
00220 }

void BoardController::enableSerialV24Interface (  )  [static]

Definition at line 222 of file BoardController.c.

References EN_AIR_V24, EN_RXD_BIOLOID, EN_TXD_BIOLOID, LED_EXPLORATION, msDelay(), powerOnLED(), RTS, and V24_UBRR.

Referenced by disableSerialInterfaces(), V24Control::init(), and main().

00222                                                {
00223 
00224      BoardController::powerOnLED(LED_EXPLORATION, true);
00225 
00226      // disable serial wires
00227      PORTC  &= ~((1<<EN_TXD_BIOLOID) | (1<<EN_RXD_BIOLOID) | (1<<EN_AIR_V24));
00228 
00229      // flushing the buffer
00230      unsigned char dummy;
00231      while (UCSRA & (1<<RXC)) dummy = UDR;
00232 
00233      // ** Serial init **
00234      // 1) USART
00235      //UCSRB &= ~((1<<TXEN) | (1<<RXEN));   // disable TX and RX
00236 
00237      // set baudrate 
00238      UBRRH = (unsigned char) (V24_UBRR >> 8);  // load the upper bits
00239      UBRRL = (unsigned char) V24_UBRR; 
00240 
00241      UCSRA |= (1<<U2X);
00242      UCSRB = ((1<<TXEN) | (1<<RXEN));   // enable transmit and receive.enable TX and RX
00243 
00244      // disable bioloid bus and enable V24
00245      PORTC  |= (1<<EN_AIR_V24);
00246      PORTC  &= ~((1<<EN_TXD_BIOLOID) | (1<<EN_RXD_BIOLOID));
00247 
00248      // ... ready to receive
00249      PORTC  &= ~(1<<RTS);
00250 
00251      BoardController::msDelay(50);
00252      BoardController::powerOnLED(LED_EXPLORATION, false);
00253 }

Here is the call graph for this function:

void BoardController::enableV24Interrupt (  )  [static]

enable serial interrupt

Definition at line 120 of file BoardController.c.

References disableV24Interrupt(), getSwitchState(), and SWITCH_V24.

Referenced by main(), and V24Control::processCommand().

00120                                           { 
00121 
00122      disableV24Interrupt();
00123      if (getSwitchState(SWITCH_V24)) {
00124           //UCSRB |=  (1 << RXCIE); 
00125           //sei();
00126      }
00127      //PORTC &= ~(1<<PC3);
00128      //UCSRB |= (1<<RXEN);
00129 }

Here is the call graph for this function:

unsigned char BoardController::getSwitchState ( unsigned char  _switch  )  [static]

return the switch status !! low-active pins are converted to: On:=1, Off=0)

Definition at line 60 of file BoardController.c.

References LED_EXPLORATION, LED_LEARN, LED_POWER, LED_WALK, msDelay(), powerOnLED(), SWITCH_ENABLE_EXPLORATION, SWITCH_FULL_EXP_AT_START, SWITCH_GAMMA, SWITCH_INV_FB_0, SWITCH_RAM, SWITCH_RAM_VALUE, SWITCH_RANDOM_STATE, SWITCH_V24, SWITCH_VDBE_EGREEDY, and SWITCH_WALK.

Referenced by disableSerialInterfaces(), disableV24Interrupt(), ValueIteration::doNextAction(), enableV24Interrupt(), V24Control::flushReceiveBuffer(), FeedbackSensor::getFeedback(), main(), ValueIteration::moveAndSaveFeedback(), V24Control::processCommand(), V24Control::processGetDebug(), V24Control::processGetExplorationConfig(), V24Control::processGetGamma(), V24Control::processGetGridsize(), V24Control::processGetState(), V24Control::processSetGamma(), V24Control::processSetGridsize(), V24Control::processSetState(), V24Control::receive(), V24Control::receiveCommand(), V24Control::transmitCommand(), V24Control::transmitReceiveCommandProcessed(), and ValueIteration::ValueIteration().

00060                                                                     {
00061 
00062      bool status;
00063 
00064      if (_switch == SWITCH_WALK) {
00065           status = (PINA & (1<<PA0)); // Bioloid
00066           
00067      } else if (_switch == SWITCH_RANDOM_STATE) {
00068           status = (PINA & (1<<PA1)); // Bioloid
00069           
00070      } else if (_switch == SWITCH_INV_FB_0) {
00071           status = (PINA & (1<<PA2)); // Bioloid
00072      
00073      } else if (_switch == SWITCH_ENABLE_EXPLORATION) {
00074           status = (PINA & (1<<PA3)); // Bioloid
00075           
00076      } else if (_switch == SWITCH_FULL_EXP_AT_START) {
00077           status = (PINA & (1<<PA4)); // PCBv2 and Bioloid
00078           
00079      } else if (_switch == SWITCH_V24) {
00080           status = (PINA & (1<<PA5)); // PCBv2 and Bioloid 
00081                               
00082      } else if (_switch == SWITCH_VDBE_EGREEDY) {
00083           status = (PINA & (1<<PA6)); // PCBv2 and Bioloid
00084 
00085      } else if (_switch == SWITCH_GAMMA) {
00086           status = (PINA & (1<<PA7)); // PCBv2 and Bioloid
00087 
00088      } else if (_switch == SWITCH_RAM) {
00089           status = SWITCH_RAM_VALUE; // PCBv2
00090 
00091      // blink if _switch is unknown
00092      } else {
00093           
00094           register char i;
00095           
00096           for (i=0; i<100; i++) {
00097           
00098                powerOnLED(LED_POWER, 1);
00099                powerOnLED(LED_WALK, 0);
00100                powerOnLED(LED_LEARN, 0);
00101                powerOnLED(LED_EXPLORATION, 1);
00102                
00103                msDelay(250);
00104                
00105                powerOnLED(LED_POWER, 0);
00106                powerOnLED(LED_WALK, 1);
00107                powerOnLED(LED_LEARN, 1);
00108                powerOnLED(LED_EXPLORATION, 0);
00109                
00110                msDelay(250);
00111           }
00112           
00113           return 0;
00114      }
00115      
00116      return !status;
00117 }

Here is the call graph for this function:

void BoardController::initPorts (  )  [static]

initialize ports for LEDs, switches and the serial interface.

Definition at line 16 of file BoardController.c.

References CTS, EN_AIR_V24, EN_RXD_BIOLOID, EN_TXD_BIOLOID, LED_EXPLORATION, LED_LEARN, LED_POWER, LED_WALK, msDelay(), powerOnLED(), and RTS.

Referenced by main().

00016                                 {
00017 
00018      // initialize switch-pins as inputs (PA0-7)
00019      DDRA = 0x00;
00020      // enable internal pull-ups for switch-pins (PA0-7)
00021      PORTA |= (1<<PA0) | (1<<PA1) | (1<<PA2) | (1<<PA3) | (1<<PA4) | (1<<PA5) | (1<<PA6) | (1<<PA7);
00022 
00023 
00024      // initialize LED pins as outputs (PB0-3)
00025      DDRB = (1<<PB0) | (1<<PB1) | (1<<PB2) | (1<<PB3); // LED1..4
00026 
00027      // turn on power led
00028      powerOnLED(LED_POWER, true);
00029      powerOnLED(LED_WALK, true);
00030      powerOnLED(LED_LEARN, true);
00031      powerOnLED(LED_EXPLORATION, true);
00032 
00033      msDelay(800);
00034 
00035      // LED test (turn all LEDs off)
00036      powerOnLED(LED_POWER, true);
00037      powerOnLED(LED_WALK, false);
00038      powerOnLED(LED_LEARN, false);
00039      powerOnLED(LED_EXPLORATION, false);
00040 
00041 
00042 
00043      // define serial interface control pins as outputs ... 
00044      DDRC |= (1<<EN_TXD_BIOLOID) | (1<<EN_RXD_BIOLOID) | (1<<EN_AIR_V24) | (1<<RTS);
00045 
00046      // disable serial port
00047      UCSRB &= ~((1<<TXEN) | (1<<RXEN));   // disable TX and RX
00048 
00049      // define RTS as input
00050      DDRC &= ~(1<<CTS);
00051      // indicate Host that serial line is not ready for reception
00052      PORTC |= (1<<RTS);
00053 
00054      // USART pins
00055      DDRD |= (1<<PD1);
00056      DDRD &= ~(1<<PD0);
00057 }

Here is the call graph for this function:

void BoardController::msDelay ( int  n  )  [static]

delay of approx. n milli-seconds

Definition at line 144 of file BoardController.c.

Referenced by blinkLED(), Environment::doAction(), enableSerialV24Interface(), ValueIteration::exploreAllFeedbacks(), getSwitchState(), initPorts(), main(), V24Control::processCommand(), V24Control::receive(), and BioloidServo::TxPacket().

00144                                     {
00145 
00146      //double maxDelay = (262.14 / (double)((11059200UL / 1000000)));
00147      double maxDelay = (262.14 / (double)((16000000UL / 1000000)));
00148 
00149      for (int i=0; i< (n/maxDelay); i++) {
00150           _delay_ms (maxDelay);
00151      }
00152 }

void BoardController::powerOnLED ( unsigned char  _ledID,
bool  _status 
) [static]

turns a specific LED on (_status=true) of off (_status=false)

Definition at line 156 of file BoardController.c.

Referenced by blinkLED(), Environment::doAction(), enableSerialV24Interface(), ValueIteration::exploreAllFeedbacks(), getSwitchState(), initPorts(), main(), ValueIteration::moveAndSaveFeedback(), V24Control::processCommand(), V24Control::receive(), and ValueIteration::valueIterateAllStates().

00156                                                                    {
00157 
00158      if (_status == true) {
00159           PORTB &= ~(1<<_ledID);
00160      } else {
00161           PORTB |= (1<<_ledID);
00162      }
00163 }


The documentation for this class was generated from the following files:

Generated on Wed Nov 25 11:27:44 2009 for Crawling Robot Microcontroller Software by  doxygen 1.5.5