CastleRock™

The Essential Online Learning Platform

For ROBOTERRA Origin™ Kit

 

RoboTerra Framework Documentation (Beta 1.0.0)


EVENT

CastleRock™ implements an EVENT-driven framework to facilitate the algorithm design of your robot. It is intuitive to see that in order for your robot to take action, one can call many Command Functions in various abstract classes that CastleRock™ offers. But how does one make such decisions? Doesn’t my robot need to know something before making the next move? Well, the answer is in EVENT. All the information needed for your robot’s decision-making is stored in a series of chronological EVENTs. CastleRock™ automatically sends out one EVENT at a time. And it is you as the designer and programmer of your robot that decides whether to use the information of each EVENT and, if you do, how to handle it.  

Below are five EVENT functions that give you the access to the information of each EVENT. Notice that, unlike calling a Command Function, which typically triggers a new EVENT, calling any EVENT function does not trigger any EVENT.

 

EVENT APIs

bool EVENT.isType(eventType)

  • Check if EVENT 's type is eventType.

bool EVENT.isFrom(eventSource)

  • Check if EVENT 's source is eventSource.

int EVENT.getData()

  • Get EVENT data integer at index 0.

int EVENT.getData(1)

  • Get EVENT data integer at index 1.

RoboTerraEventType EVENT.type()

  • Get eventType of EVENT.

Example Usage In CastleRock™

In Step 3, Design the algorithm to handle each EVENT.

  • Check if this EVENT has a type of BUTTON_PRESS.

    • Sample Code:

      if(EVENT.isType(BUTTON_PRESS)){

          led.turnOn();
      

      }

  • Check if this EVENT is from the “button”.

    • Sample Code:

      if(EVENT.isFrom(button)){

          led.turnOn();
      

      }

  • Check if the “button” has been pressed twice.

    • Sample Code:

      if(EVENT.isType(BUTTON_PRESS)){

          if (EVENT.getData() == 2){
          }
      

      }

  • Check if RoboTerraServo current speed is 2.

    • Sample Code:

      if(EVENT.isType(SERVO_MOVE_BEGIN)){

          if (EVENT.getData(1) == 2){
          }
      

      }

  • Make design decisions for your robot under different types of EVENT it encounters.

    • Sample Code:

      switch (EVENT.type()) {

          case BUTTON_PRESS:
              // Your decision
              break;
          case LED_TURNON:
              // Your decision
              break;
      

      }


RoboTerraRoboCore Class

RoboTerraRoboCore is a C++ class specifically designed for RoboTerraRoboCore in THINK box of Origin™ Kit.

Two types EVENTs are related to RoboTerraRoboCore Class.

RoboTerraRoboCore EVENT

ROBOCORE_LAUNCH

  • When emitted: Right after initializeRoboTerraRobot() if RoboTerraRoboCore object declared
  • Event Source: RoboTerraRoboCore object
  • Event Type: ROBOCORE_LAUNCH
  • Event Data: Number of ports attached (0 - 18)

ROBOCORE_TERMINATE

  • When emitted: Command Function deactivate() is called
  • Event Source: RoboTerraRoboCore object
  • Event Type: ROBOCORE_TERMINATE
  • Event Data: Number of ports attached (0)

RoboTerraRoboCore Command Functions

void attach(objectName, portID)

  • Attach electronics (sensors or actuators) to a specific port on RoboCore and activate it.

void terminate()

  • Terminate RoboCore so that it will not process any EVENT unless RoboCore is reset.

Example Usage In CastleRock™

In Step 1, Name your RoboCore and all electronics attached to it. These name are considered as eventSource of EVENT.

  • RoboTerraRoboCore named “tom”.

    • Sample Code:

      RoboTerraRoboCore tom;

In Step 2, Initialize your robot by attaching electronics.

  • DIO_1 is the port ID where the “button” is attached to “tom”. A RoboTerraButton can be attached to any DIO port on RoboCore.

    • Sample Code:

      tom.attach(button, DIO_1);

In Step 3, With EVENT information, make decisions by calling Command Functions of each object to take action.

  • Terminate “tom” so that it will not process any EVENT unless “tom” is reset.

    • Sample Code:

      tom.terminate();


RoboTerraButton Class

RoboTerraButton is a C++ class specifically designed for RoboTerraButton in SENSE box of Origin™ Kit.

RoboTerraButton EVENT

ACTIVATE

  • When emitted: Command Function attach(objectName, portID) or activate() is called
  • Event Source: RoboTerraButton object
  • Event Type: ACTIVATE
  • Event Data: Number of active RoboTerraButton objects (0-9)

DEACTIVATE

  • When emitted: Command Function deactivate() is called
  • Event Source: RoboTerraButton object
  • Event Type: DEACTIVATE
  • Event Data: Number of active RoboTerraButton objects (0-9)

BUTTON_PRESS

  • When emitted: Press and hold an active RoboTerraButton
  • Event Source: RoboTerraButton object
  • Event Type: BUTTON_PRESS
  • Event Data: Number of times a RoboTerraButton pressed (0-32767)

BUTTON_RELEASE

  • When emitted: Release an active RoboTerraButton
  • Event Source: RoboTerraButton object
  • Event Type: BUTTON_RELEASE
  • Event Data: Number of times a RoboTerraButton released (0-32767)

RoboTerraButton Command Functions

void activate()

  • Activate RoboTerraButton so that EVENT related to RoboTerraButton can be detected.

void deactivate()

  • Deactivate RoboTerraButton so that EVENT related to RoboTerraButton can no longer be detected.

Example Usage In CastleRock™

In Step 1, Name your RoboCore and all electronics attached to it. These name are considered as eventSource of EVENT.

  • The “button” can be replaced with any name of your choice to specify the RoboTerraButton attached to RoboTerraRoboCore named “tom”.

    • Sample Code:

      RoboTerraRoboCore tom;

      RoboTerraButton button;

In Step 2, Initialize your robot by attaching electronics.

  • DIO_1 is the port ID where the “button” is attached to “tom”. A RoboTerraButton can be attached to any DIO port on RoboCore.

    • Sample Code:

      tom.attach(button,DIO_1);

In Step 3, Design the algorithm to handle each EVENT.

  • Check if this EVENT is from the “button”.

    • Sample Code:

      if (EVENT.isFrom(button)){

      }

  • Check if this EVENT has a type of BUTTON_PRESS.

    • Sample Code:

      if (EVENT.isType(BUTTON_PRESS)){

      }

  • Check if this EVENT has a type of BUTTON_RELEASE.

    • Sample Code:

      if (EVENT.isType(BUTTON_RELEASE)){

      }

  • Check if the “button” has been pressed twice.

    • Sample Code:

      if (EVENT.isType(BUTTON_PRESS)){

          if(EVENT.getData()==2){
          }
      

      }

  • Check if the “button” has been released twice.

    • Sample Code:

      if (EVENT.isType(BUTTON_RELEASE)){

          if(EVENT.getData()==2){
          }
      

      }

  • Activate the “button”.

    • Sample Code:

      button.activate();

  • Deactivate the “button”.

    • Sample Code:

      button.deactivate();


RoboTerraLightSensor Class

RoboTerraLightSensor is a C++ class that is specifically designed for RoboTerraLightSensor in SENSE box of Origin™ Kit.

Four types of EVENT are related to RoboTerraLightSensor Class. 

RoboTerraLightSensor EVENT

ACTIVATE

  • When emitted: Command Function attach(objectName, portID) or activate() is called
  • Event Source: RoboTerraLightSensor object
  • Event Type: ACTIVATE
  • Event Data: Number of active RoboTerraLightSensor objects (0-9)

DEACTIVATE

  • When emitted: Command Function deactivate() is called
  • Event Source: RoboTerraLightSensor object
  • Event Type: DEACTIVATE
  • Event Data: Number of active RoboTerraLightSensor objects (0-9)

DARK_ENTER

  • When emitted: Darkness sensed by RoboTerraLightSensor
  • Event Source: RoboTerraLightSensor object
  • Event Type: DARK_ENTER
  • Event Data: Number of times a RoboTerraLightSensor enters Dark (0-32767)

DARK_LEAVE

  • When emitted: Darkness not sensed by RoboTerraLightSensor
  • Event Source: RoboTerraLightSensor object
  • Event Type: DARK_LEAVE
  • Event Data: Number of times a RoboTerraLightSensor leaves Dark (0-32767)

RoboTerraLightSensor Command Functions

void activate()

  • Activate RoboTerraLightSensor so that EVENT related to RoboTerraLightSensor can be detected.

void deactivate()

  • Deactivate RoboTerraLightSensor so that EVENT related to RoboTerraLightSensor can no longer be detected.

Example Usage In CastleRock™

In Step 1, Name your RoboCore and all electronics attached to it. These name are considered as eventSource of EVENT.

  • The “eye” can be replaced with any name of your choice to specify the RoboTerraLightSensor attached to RoboTerraRoboCore named “tom”.

    • Sample Code:

      RoboTerraRoboCore tom;

      RoboTerraLightSensor eye;

In Step 2, Initialize your robot by attaching electronics.

  • DIO_1 is the port ID where the “eye” is attached to “tom”. A RoboTerraLightSensor can be attached to any DIO port on RoboCore.

    • Sample Code:

      tom.attach(eye, DIO_1);

In Step 3, Design the algorithm to handle each EVENT.

  • Check if this EVENT is from the “eye”.

    • Sample Code:

      if (EVENT.isFrom(eye)){

      }

  • Check if this EVENT has a type of DARK_ENTER.

    • Sample Code:

      if(EVENT.isType(DARK_ENTER)){

      }

  • Check if this EVENT has a type of DARK_LEAVE.

    • Sample Code:

      if(EVENT.isType(DARK_LEAVE)){

      }

  • Check if the “eye” has entered Dark twice.

    • Sample Code:

      if (EVENT.isType(DARK_ENTER)){

          if (EVENT.getData() == 2){
          }
      

      }

  • Check if the “eye” has left Dark twice.

    • Sample Code:

      if (EVENT.isType(DARK_LEAVE)){

          if (EVENT.getData() == 2){
          }
      

      }

In Step 3, With EVENT information, make decisions by calling Command Functions of each object to take action.

  • Activate the “eye”.

    • Sample Code:

      eye.activate();

  • Deactivate the “eye”.

    • Sample Code:

      eye.deactivate();


RoboTerraSoundSensor Class

RoboTerraSoundSensor is a C++ class that is specifically designed for RoboTerraSoundSensor in SENSE box of Origin™ Kit.

Four types of EVENT are related to RoboTerraSoundSensor Class. 

RoboTerraSoundSensor EVENT

ACTIVATE

  • When emitted: Command Function attach(objectName, portID) or activate() is called
  • Event Source: RoboTerraSoundSensor object
  • Event Type: ACTIVATE
  • Event Data: Number of active RoboTerraSoundSensor objects (0-9)

DEACTIVATE

  • When emitted: Command Function deactivate() is called
  • Event Source: RoboTerraSoundSensor object
  • Event Type: DEACTIVATE
  • Event Data: Number of active RoboTerraSoundSensor objects (0-9)

SOUND_BEGIN

  • When emitted: Sound no longer sensed by RoboTerraSoundSensor
  • Event Source: RoboTerraSoundSensor object
  • Event Type: SOUND_BEGIN
  • Event Data: Number of times a RoboterraSoundSensor detects the beginning of sound (0-32767)

SOUND_END

  • When emitted: Sound not sensed by RoboTerraLightSensor
  • Event Source: RoboTerraSoundSensor object
  • Event Type: SOUND_END
  • Event Data: Number of times a RoboterraSoundSensor detects the end of sound (0-32767)

RoboTerraSoundSensor Command Functions

void activate()

  • Activate RoboTerraSoundSensor so that EVENT related to RoboTerraSoundSensor can be detected.

void deactivate()

  • Deactivate RoboTerraSoundSensor so that EVENT related to RoboTerraSoundSensor can no longer be detected.

Example Usage In CastleRock™

In Step 1, Name your RoboCore and all electronics attached to it. These name are considered as eventSource of EVENT.

  • The “ear” can be replaced with any name of your choice to specify the RoboTerraSoundSensor attached to RoboTerraRoboCore named “tom”.

    • Sample Code:

      RoboTerraRoboCore tom;

      RoboTerraSoundSensor ear;

In Step 2, Initialize your robot by attaching electronics.

  • DIO_1 is the port ID where the “ear” is attached to “tom”. A RoboTerraSoundSensor can be attached to any DIO port on RoboCore.

    • Sample Code:

      tom.attach(ear, DIO_1);

In Step 3, Design the algorithm to handle each EVENT.

  • Check if this EVENT is from the "ear".

    • Sample Code:

      if (EVENT.isFrom(ear)){

      }

  • Check if this EVENT has a type of SOUND_BEGIN.

    • Sample Code:

      if(EVENT.isType(SOUND_BEGIN)){

      }

  • Check if this EVENT has a type of SOUND_END.

    • Sample Code:

      if(EVENT.isType(SOUND_END)){

      }

  • Check if the "ear" has detected sound begins twice.

    • Sample Code:

      if (EVENT.isType(SOUND_BEGIN)){

          if (EVENT.getData() == 2){
          }
      

      }

  • Check if the “ear” has detected sound end twice.

    • Sample Code:

      if (EVENT.isType(SOUND_END)){

          if (EVENT.getData() == 2){
          }
      

      }

In Step 3, With EVENT information, make decisions by calling Command Functions of each object to take action.

  • Activate the “ear”.

    • Sample Code:

      ear.activate();

  • Deactivate the “ear”.

    • Sample Code:

      ear.deactivate();


RoboTerraTapeSensor Class

RoboTerraTapeSensor is a C++ class that is specifically designed for RoboTerraTapeSensor in SENSE box of Origin™ Kit.

Four types of EVENT are related to RoboTerraTapeSensor Class. 

RoboTerraTapeSensor EVENT

ACTIVATE

  • When emitted: Command Function attach(objectName, portID) or activate() is called
  • Event Source: RoboTerraTapeSensor object
  • Event Type: ACTIVATE
  • Event Data: Number of active RoboTerraTapeSensor objects (0-9)

DEACTIVATE

  • When emitted: Command Function deactivate() is called
  • Event Source: RoboTerraTapeSensor object
  • Event Type: DEACTIVATE
  • Event Data: Number of active RoboTerraTapeSensor objects (0-9)

BLACK_TAPE_ENTER

  • When emitted: Black Tape sensed by RoboTerraTapeSensor
  • Event Source: RoboTerraTapeSensor object
  • Event Type: BLACK_TAPE_ENTER
  • Event Data: Number of times a RoboTerraTapeSensor enters black tape (0-32767)

BLACK_TAPE_LEAVE

  • When emitted: Black Tape not sensed by RoboTerraTapeSensor
  • Event Source: RoboTerraTapeSensor object
  • Event Type: BLACK_TAPE_LEAVE
  • Event Data: Number of times a RoboTerraTapeSensor leaves black tape (0-32767)

RoboTerraTapeSensor Command Functions

void activate()

  • Activate RoboTerraTapeSensor so that EVENT related to RoboTerraTapeSensor can be detected.

void deactivate()

  • Deactivate RoboTerraTapeSensor so that EVENT related to RoboTerraTapeSensor can no longer be detected.

Example Usage In CastleRock™

In Step 1, Name your RoboCore and all electronics attached to it. These name are considered as eventSource of EVENT.

  • The “foot” can be replaced with any name of your choice to specify the RoboTerraTapeSensor attached to RoboTerraRoboCore named “tom”.

    • Sample Code:

      RoboTerraRoboCore tom;

      RoboTerraTapeSensor foot;

In Step 2, Initialize your robot by attaching electronics.

  • DIO_1 is the port ID where the “foot” is attached to “tom”. A RoboTerraTapeSensor can be attached to any DIO port on RoboCore.

    • Sample Code:

      tom.attach(foot, DIO_1);

In Step 3, Design the algorithm to handle each EVENT.

  • Check if this EVENT is from the "foot".

    • Sample Code:

      if (EVENT.isFrom(foot)){

      }

  • Check if this EVENT has a type of BLACK_TAPE_ENTER.

    • Sample Code:

      if(EVENT.isType(BLACK_TAPE_ENTER)){

      }

  • Check if this EVENT has a type of BLACK_TAPE_LEAVE.

    • Sample Code:

      if(EVENT.isType(BLACK_TAPE_LEAVE)){

      }

  • Check if the “foot” has entered black tape twice.

    • Sample Code:

      if (EVENT.isType(BLACK_TAPE_ENTER)){

          if (EVENT.getData() == 2){
          }
      

      }

  • Check if the “eye” has left black tape twice.

    • Sample Code:

      if (EVENT.isType(BLACK_TAPE_LEAVE)){

          if (EVENT.getData() == 2){
          }
      

      }

In Step 3, With EVENT information, make decisions by calling Command Functions of each object to take action.

  • Activate the “foot”.

    • Sample Code:

      foot.activate();

  • Deactivate the “foot”.

    • Sample Code:

      foot.deactivate();


RoboTerraServo Class

RoboTerraServo is a C++ class specifically designed for RoboTerraServo in ACT box of Origin™ Kit.

All the Command Functions in this class will trigger EVENT.

Five types of EVENT are related to RoboTerraServo Class.

RoboTerraServo EVENT

ACTIVATE

  • When emitted: Command Function attach(objectName, portID) or activate() is called
  • Event Source: RoboTerraServo object
  • Event Type: ACTIVATE
  • Event Data:
    • EVENT.getData(): Number of active RoboTerraServo objects (0-4)
    • EVENT.getData(1): No significance (0)

DEACTIVATE

  • When emitted: Command Function deactivate() is called
  • Event Source: RoboTerraServo object
  • Event Type: DEACTIVATE
  • Event Data:
    • EVENT.getData(): Number of active RoboTerraServo objects (0-4)
    • EVENT.getData(1): No significance (0)

SERVO_MOVE_BEGIN

  • When emitted: Calling rotate(degree, speed) or resume()
  • Event Source: RoboTerraServo object
  • Event Type: SERVO_MOVE_BEGIN
  • Event Data:
    • EVENT.getData(): Degree of angle a RoboTerraServo is going to rotate to (0-180)
    • EVENT.getData(1): Current Speed of a RoboTerraServo (1 - 10)

SERVO_INCREASE_END

  • When emitted: Target angle reached or call pause() when angle increasing (counterclockwise)
  • Event Source: RoboTerraServo object
  • Event Type: SERVO_INCREASE_END
  • Event Data:
    • EVENT.getData(): Degree of angle a RoboTerraServo currently stays at (0-180)
    • EVENT.getData(1): Current Speed of a RoboTerraServo (0)

SERVO_DECREASE_END

  • When emitted: Target angle reached or call pause() when angle decreasing (clockwise)
  • Event Source: RoboTerraServo object
  • Event Type: SERVO_DECREASE_END
  • Event Data:
    • EVENT.getData(): Degree of angle a RoboTerraServo currently stays at (0-180)
    • EVENT.getData(1): Current Speed of a RoboTerraServo (0)

RoboTerraServo Command Functions

void activate()

  • Activate RoboTerraServo so that Command Functions related to RoboTerraServo would take action once called.

void deactivate()

  • Deactivate RoboTerraServo so that Command Functions related to RoboTerraServo would not take action once called.

void rotate(int degree, int speed)

  • Rotate RoboTerraServo to a specified target angle at a specified speed.

void pause()

  • Pause RoboTerraServo during its rotation motion.

void resume()

  • Resume RoboTerraServo to reach the specified target angle before it is paused.

Example Usage In CastleRock™

In Step 1, Name your RoboCore and all electronics attached to it. These name are considered as eventSource of EVENT.

  • The “leg” can be replaced with any name of your choice to specify the RoboTerraServo attached to RoboTerraRoboCore named “tom”.

    • Sample Code:

      RoboTerraRoboCore tom;

      RoboTerraServo leg;

In Step 2, Initialize your robot by attaching electronics.

  • SERVO_A is the port ID where the “leg” is attached to “tom”. A RoboTerraServo can be attached to any SERVO port on RoboCore.

    • Sample Code:

      tom.attach(leg, SERVO_A);

In Step 3, Design the algorithm to handle each EVENT.

  • Check if this EVENT is from the "leg".

    • Sample Code:

      if (EVENT.isFrom(leg)){

      }

  • Check if this EVENT has a type of SERVO_MOVE_BEGIN.

    • Sample Code:

      if(EVENT.isType(SERVO_MOVE_BEGIN)){

      }

  • Check if this EVENT has a type of SERVO_INCREASE_END.

    • Sample Code:

      if(EVENT.isType(SERVO_INCREASE_END)){

      }

  • Check if this EVENT has a type of SERVO_DECREASE_END.

    • Sample Code:

      if(EVENT.isType(SERVO_DECREASE_END)){

      }

  • Check if RoboTerraServo is going to rotate to 90 degree.

    • Sample Code:

      if (EVENT.isType(SERVO_MOVE_BEGIN)){

          if (EVENT.getData() == 90){
          }
      

      }

  • Check if RoboTerraServo current speed is 2.

    • Sample Code:

      if (EVENT.isType(SERVO_MOVE_BEGIN)){

          if (EVENT.getData(1) == 2){
          }
      

      }

In Step 3, With EVENT information, make decisions by calling Command Functions of each object to take action.

  • Activate the “leg”.

    • Sample Code:

      leg.activate();

  • Deactivate the “leg”.

    • Sample Code:

      leg.deactivate();

  • Rotate “leg” to 90 degree with speed of 3.

    • Sample Code:

      leg.rotate(90,3);

  • Pause the motion of “leg”.

    • Sample Code:

      leg.pause();


RoboTerraLED Class

RoboTerraLED is a C++ class specifically designed for RoboTerraLED in ACT box of Origin™ Kit.

RoboTerraLED EVENT

ACTIVATE

  • When emitted: Command Function attach(objectName, portID) or activate() is called
  • Event Source: RoboTerraLED object
  • Event Type: ACTIVATE
  • Event Data: Number of active RoboTerraLED objects (0-9)

DEACTIVATE

  • When emitted: Command Function deactivate() is called
  • Event Source: RoboTerraLED object
  • Event Type: DEACTIVATE
  • Event Data: Number of active RoboTerraLED objects (0-9)

LED_TURNON

  • When emitted: Calling turnOn() when it is not on or toggle() when it is off
  • Event Source: RoboTerraLED object
  • Event Type: LED_TURNON
  • Event Data: Number of RoboTerraLEDs that is on (0-9)

LED_TURNOFF

  • When emitted: Calling turnOff()when it is not off or toggle() when it is on
  • Event Source: RoboTerraLED object
  • Event Type: LED_TURNOFF
  • Event Data: Number of RoboTerraLEDs that is on (0-9)

SLOWBLINK_BEGIN

  • When emitted: Calling slowBlink(int num) or slowBlink()
  • Event Source: RoboTerraLED object
  • Event Type: SLOWBLINK_BEGIN
  • Event Data: Number of times a RoboTerraLED is going to blink (1-32767) / Unlimited times (0)

FASTBLINK_BEGIN

  • When emitted: Calling fastBlink(int num) or fastBlink()
  • Event Source: RoboTerraLED object
  • Event Type: FASTBLINK_BEGIN
  • Event Data: Number of times a RoboTerraLED is going to blink (1-32767) / Unlimited times (0)

BLINK_END

  • When emitted: Finite blinks finished or calling turnOn() or turnOff() or stopBlink() when blinking
  • Event Source: RoboTerraLED object
  • Event Type: BLINK_END
  • Event Data: Number of times a RoboTerraLED has actually blinked (0-32767)

RoboTerraLED Command Functions

void activate()

  • Activate RoboTerraLED so that Command Functions related to RoboTerraLED would take action once called.

void deactivate()

  • Deactivate RoboTerraLED so that Command Functions related to RoboTerraLED would not take action once called.

void turnOn()

  • Turn on RoboTerraLED or stop a blinking one and make it stay on.

void turnOff()

  • Turn off RoboTerraLED or stop a blinking one and make it stay off.

void slowBlink(int times)

  • Make RoboTerraLED blink slowly (once per second) for a specified number of times.

void slowBlink()

  • Make RoboTerraLED blink slowly (once per second) for an unlimited number of times or switch from fastBlink() to slowBlink().

void fastBlink(int times)

  • Make RoboTerraLED blink fast (once per quarter second) for a specified number of times.

void fastBlink()

  • Make RoboTerraLED blink fast (once per quarter second) for an unlimited number of times or switch from slowBlink() to fastBlink().

void toggle()

  • Turn on RoboTerraLED if it is already off or turn off RoboTerraLED if it is already on.

void stopBlink()

  • Stop RoboTerraLED from blinking and restore its state (either on or off) before blinking.

Example Usage In CastleRock™

In Step 1, Name your RoboCore and all electronics attached to it. These name are considered as eventSource of EVENT.

  • The “red” can be replaced with any name of your choice to specify the RoboTerraLED attached to RoboTerraRoboCore named “tom”.

    • Sample Code:

      RoboTerraRoboCore tom;

      RoboTerraLED red;

In Step 2, Initialize your robot by attaching electronics.

  • DIO_1 is the port ID where the “red” is attached to “tom”. A RoboTerraLED can be attached to any DIO port on RoboCore.

    • Sample Code:

      tom.attach(red, DIO_1);

In Step 3, Design the algorithm to handle each EVENT.

  • Check if this EVENT is from the “red”.

    • Sample Code:

      if (EVENT.isFrom(red)){

      }

  • Check if this EVENT has a type of LED_TURNON.

    • Sample Code:

      if(EVENT.isType(LED_TURNON)){

      }

  • Check if this EVENT has a type of LED_TURNOFF.

    • Sample Code:

      if(EVENT.isType(LED_TURNOFF)){

      }

  • Check if this EVENT has a type of SLOWBLINK_BEGIN.

    • Sample Code:

      if(EVENT.isType(SLOWBLINK_BEGIN)){

      }

  • Check if this EVENT has a type of FASTBLINK_BEGIN.

    • Sample Code:

      if(EVENT.isType(FASTBLINK_BEGIN)){

      }

  • Check if this EVENT has a type of BLINK_END.

    • Sample Code:

      if(EVENT.isType(BLINK_END)){

      }

  • Check if only two RoboTerraLEDs have been turned on.

    • Sample Code:

      if (EVENT.isType(LED_TURNON)){

          if (EVENT.getData() == 2){
          }
      

      }

  • Check if RoboTerraLED is going to blink slowly twice.

    • Sample Code:

      if (EVENT.isType(SLOWBLINK_BEGIN)){

          if (EVENT.getData() == 2){
          }
      

      }

  • Check if RoboTerraLED is going to blink fast twice.

    • Sample Code:

      if (EVENT.isType(FASTBLINK_BEGIN)){

          if (EVENT.getData() == 2){
          }
      

      }

  • Check if RoboTerraLED has blinked twice.

    • Sample Code:

      if (EVENT.isType(BLINK_END)){

          if (EVENT.getData() == 2){
          }
      

      }

In Step 3, With EVENT information, make decisions by calling Command Functions of each object to take action.

  • Activate the “red”.

    • Sample Code:

      red.activate();

  • Deactivate the “red”.

    • Sample Code:

      red.deactivate();

  • Turn on RoboTerraLED.

    • Sample Code:

      red.turnOn();

  • Turn off RoboTerraLED.

    • Sample Code:

      red.turnOff();

  • Make RoboTerraLED blink slowly (once per second) for 3 times.

    • Sample Code:

      red.slowBlink(3);

  • Make RoboTerraLED blink slowly (once per second) for an unlimited number of times.

    • Sample Code:

      red.slowBlink();

  • Make RoboTerraLED blink fast (once per quarter second) for 10 times.

    • Sample Code:

      red.fastBlink(10);

  • Make RoboTerraLED blink fast (once per quarter second) for an unlimited number of times.

    • Sample Code:

      red.fastBlink();