Class Bertl

Dependencies:   HCSR

Dependents:   LEDTestmitButton

Fork of ur_Bertl by BERTL_CHEL18

Embed: (wiki syntax)

« Back to documentation index

ur_Bertl Class Reference

name: ur_Bertl.h
version: 3.0
class Bertl included
author:PE HTL BULME
email: pe@bulme.at
WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage
description: Definition and documentation portion of the class ur_Bertl The Robot. More...

#include <ur_Bertl.h>

Inherited by Bertl, and Robot.

Public Member Functions

 ur_Bertl ()
 default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE
 ur_Bertl (PinName pin)
 parameterized constructor; on what pin should the interrupt work; SPEED, DISTANCE or ANGLE have to bee defined in config.h
void Move ()
 Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()
void TurnLeft ()
 Robot turns left as much as the constant ANGLE.
void PutBeeper ()
 if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()
void PickBeeper ()
 if Robot stands on a black item he can pick one or more Beeper (max.
void TurnOff ()
 turnes the robot off
bool WaitUntilButtonPressed ()
 wait until any button is pressed at the robot
bool FrontIsClear ()
 returns a boolean value true if front is free; if not false
bool NextToABeeper ()
 returns a boolean value true if the robot is on a black place or line; if not --> false
bool IsButtonPressed (const int btn)
 returns true if Button btn is pressed, else false
int ReturnButtonPressed ()
 returns the int value of button pressed
int AnyBeeperInBag ()
 returns an int value (if > 0 equal true) how many beepers in bag; if zero --> false
void NibbleLeds (int value)
 methode for the 4 (half byte) yellow LEDs at the back left side; ie.
void TurnLedOn (int16_t led)
 turns the specified one or more LEDs ON; description and name in const.h, such as LED_FL1 = 0x01; front LED white
void TurnLedOff (int16_t led)
 turns the specified one or more LEDs OFF; description and name in const.h, such as LED_FL1 = 0x01; front LED white
void RGBLed (bool red, bool green, bool blue)
 RGB Led with red, green and blue component of the Color.
void BlueLedsOFF ()
 OFF all blue LEDs which are on the same Port 1_28.
void BlueLedsON ()
 ON all blue LEDs which are on the same Port 1_28.

Protected Member Functions

void increment ()
 protected methodes for internal purposes only
bool backIsClear ()
 don't now for what
bool frontButtonPressed ()
 TRUE if a a button on the front of Robot is pressed else FALSE.
int bottomIsBlack ()
 check line sensor; returns BCD value
void error ()
 Error: stops the robot and all LEDs are blinking.

Protected Attributes

int beepersInBag
 how many beepers does the robot have in his bag;
you can show it with: karel.NibbleLeds(karel.AnyBeeperInBag())
char cmd [3]
 I2C command.
int16_t btns
 which button is pressed
InterruptIn _interrupt
 interrupted used
volatile int _count
 values of motor sensor

Detailed Description

name: ur_Bertl.h
version: 3.0
class Bertl included
author:PE HTL BULME
email: pe@bulme.at
WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage
description: Definition and documentation portion of the class ur_Bertl The Robot.

//

Example motor sensor test:

#include "mbed.h"
#include "ur_Bertl.h"
#include "const.h"
 
int main()
{
    ur_Bertl karel(LEFTSENSOR);  // RIGHTSENSOR

    while(true) {
        karel.NibbleLeds(karel.Read());
    }
}

Example moving the robot around:

#include "mbed.h"
#include "ur_Bertl.h"
#include "const.h"

int main()
{
    ur_Bertl karel;
    
    while(karel.WaitUntilButtonPressed()){}
    //karel.Move();
    karel.TurnLeft();
    karel.ShutOff();
}

Example LEDs:

#include "mbed.h"
#include "ur_Bertl.h"
#include "const.h"

int main()
{
   ur_Bertl karel;
   
   while(karel.WaitUntilButtonPressed()){}

   karel.TurnLedOn(LED_FL1 | LED_FR1);  // see const.h
   wait(1);
   karel.TurnLedOn(0xFF);               // or use hex
   wait(1);
   karel.RGBLed(1,0,0);     // red
   wait(1);
   karel.RGBLed(0,1,0);     // green
   wait(1);
   karel.RGBLed(0,0,1);     // blue
   karel.BlueLedsON();
   karel.NibbleLeds(karel.Read());
   wait(1);
   karel.BlueLedsOFF();
   karel.TurnLedOff(0xFF);
   karel.ShutOff();
} 

Example IF/ELSE Commands (update ur_Bertl 2.0 from https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/

/*Sorry, but there are Javascript problems with this code

int main()
{
    ur_Bertl karel;

    while( karel.WaitUntilButtonPressed() ) {}
    if( karel.NextToABeeper()) {
        karel.PickBeeper();
        karel.NibbleLeds(karel.AnyBeeperInBag());   //show number of beepers in bag on 4 yellow Leds
    }
    wait(1);
    if( karel.AnyBeeperInBag() ) {
        karel.PutBeeper();
        karel.NibbleLeds(karel.AnyBeeperInBag());  
    }
    wait(1);
    if( karel.FrontIsClear() )
        karel.Move();
    else
        karel.TurnLeft();

    karel.ShutOff();
}

Definition at line 128 of file ur_Bertl.h.


Constructor & Destructor Documentation

ur_Bertl (  )

default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE

Definition at line 17 of file ur_Bertl.cpp.

ur_Bertl ( PinName  pin )

parameterized constructor; on what pin should the interrupt work; SPEED, DISTANCE or ANGLE have to bee defined in config.h

Definition at line 34 of file ur_Bertl.cpp.


Member Function Documentation

int AnyBeeperInBag (  )

returns an int value (if > 0 equal true) how many beepers in bag; if zero --> false

Definition at line 252 of file ur_Bertl.cpp.

bool backIsClear (  ) [protected]

don't now for what

Definition at line 308 of file ur_Bertl.cpp.

void BlueLedsOFF (  )

OFF all blue LEDs which are on the same Port 1_28.

Definition at line 135 of file ur_Bertl.cpp.

void BlueLedsON (  )

ON all blue LEDs which are on the same Port 1_28.

Definition at line 130 of file ur_Bertl.cpp.

int bottomIsBlack (  ) [protected]

check line sensor; returns BCD value

Definition at line 300 of file ur_Bertl.cpp.

void error (  ) [protected]

Error: stops the robot and all LEDs are blinking.

Definition at line 355 of file ur_Bertl.cpp.

bool frontButtonPressed (  ) [protected]

TRUE if a a button on the front of Robot is pressed else FALSE.

Definition at line 330 of file ur_Bertl.cpp.

bool FrontIsClear (  )

returns a boolean value true if front is free; if not false

Definition at line 187 of file ur_Bertl.cpp.

void increment (  ) [protected]

protected methodes for internal purposes only

ISR to increment sensor values of motor

Definition at line 377 of file ur_Bertl.cpp.

bool IsButtonPressed ( const int  btn )

returns true if Button btn is pressed, else false

Definition at line 260 of file ur_Bertl.cpp.

void Move (  )

Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()

Definition at line 48 of file ur_Bertl.cpp.

bool NextToABeeper (  )

returns a boolean value true if the robot is on a black place or line; if not --> false

Definition at line 244 of file ur_Bertl.cpp.

void NibbleLeds ( int  value )

methode for the 4 (half byte) yellow LEDs at the back left side; ie.

you can show how many beeper a robot has in his bag with: karel.NibbleLeds(karel.AnyBeeperInBag())

Definition at line 180 of file ur_Bertl.cpp.

void PickBeeper (  )

if Robot stands on a black item he can pick one or more Beeper (max.

15 --> Error()); if not --> Error()

Definition at line 82 of file ur_Bertl.cpp.

void PutBeeper (  )

if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()

Definition at line 73 of file ur_Bertl.cpp.

int ReturnButtonPressed (  )

returns the int value of button pressed

Definition at line 282 of file ur_Bertl.cpp.

void RGBLed ( bool  red,
bool  green,
bool  blue 
)

RGB Led with red, green and blue component of the Color.

Reimplemented in Bertl.

Definition at line 140 of file ur_Bertl.cpp.

void TurnLedOff ( int16_t  led )

turns the specified one or more LEDs OFF; description and name in const.h, such as LED_FL1 = 0x01; front LED white

Definition at line 164 of file ur_Bertl.cpp.

void TurnLedOn ( int16_t  led )

turns the specified one or more LEDs ON; description and name in const.h, such as LED_FL1 = 0x01; front LED white

Definition at line 147 of file ur_Bertl.cpp.

void TurnLeft (  )

Robot turns left as much as the constant ANGLE.

Definition at line 93 of file ur_Bertl.cpp.

void TurnOff (  )

turnes the robot off

Definition at line 116 of file ur_Bertl.cpp.

bool WaitUntilButtonPressed (  )

wait until any button is pressed at the robot

Definition at line 221 of file ur_Bertl.cpp.


Field Documentation

volatile int _count [protected]

values of motor sensor

Definition at line 135 of file ur_Bertl.h.

InterruptIn _interrupt [protected]

interrupted used

Definition at line 134 of file ur_Bertl.h.

int beepersInBag [protected]

how many beepers does the robot have in his bag;
you can show it with: karel.NibbleLeds(karel.AnyBeeperInBag())

Definition at line 131 of file ur_Bertl.h.

int16_t btns [protected]

which button is pressed

Definition at line 133 of file ur_Bertl.h.

char cmd[3] [protected]

I2C command.

Definition at line 132 of file ur_Bertl.h.