1. AdMoVeo in Processing

Together with the IDuino firmware (an Arduino sketch uploaded to the Arduino board), this class allows you to control the AdMoVeo robot from Processing: Controlling all the actuators (LED's, motors, buzzer etc) and receiving input events from all the sensors (distance sensors, light sensors, sound sensors and line readers etc).

1.1. AdMoVeo

1.1.1. Constructor

AdMoVeo(PApplet parent, String name)

Create a proxy to an AdMoVeo robot running the IDuino firmware. it uses a default baud rate of 57600 to communicate with the robot.

parent

the Processing sketch creating this AdMoVeo robot (i.e. "this").

name

the name of the serial device associated with the AdMoVeo robot.

1.1.2. Access to devices

1.1.2.1. Arduino
Arduino getArduino()

Gets the Arduino object used by this AdMoVeo robot.

Returns
the Arduino object.

1.1.2.2. Sensors
AnalogSensor getFrontDistanceSensor()
Gets the reference to the front distance sensor of the robot.
Returns
the reference to the front distance sensor.
AnalogSensor getLeftDistanceSensor()
Gets the reference to the left distance sensor of the robot.
Returns
the reference to the left distance sensor.
AnalogSensor getRightDistanceSensor()
Gets the reference to the right distance sensor of the robot.
Returns
the reference to the right distance sensor.
AnalogSensor getLeftLightSensor()
Gets the reference to the left light sensor of the robot.
Returns
the reference to the left light sensor.
AnalogSensor getRightLightSensor()
Gets the reference to the right light sensor of the robot.
Returns
the reference to the right light sensor.
AnalogSensor getLeftLineSensor()
Gets the reference to the left line sensor of the robot.
Returns
the reference to the left line sensor.
AnalogSensor getRightLineSensor()
Gets the reference to the right line sensor of the robot.
Returns
the reference to the right line sensor.
AnalogSensor getLeftSoundSensor()
Gets the reference to the left sound sensor of the robot.
Returns
the reference to the left sound sensor.
AnalogSensor getRightSoundSensor()
Gets the reference to the right sound sensor of the robot.
Returns
the reference to the right sound sensor.

1.1.2.3. Actuators
AnalogActuator getBuzzer()
Gets the reference to the buzzer of the robot.
Returns
the reference to the buzzer.
AnalogActuator getBlueLed()
Gets the reference to the blue LED of the robot.
Returns
the reference to the blue LED.
AnalogActuator getGreenLed()
Gets the reference to the green LED of the robot.
Returns
the reference to the green LED.
AnalogActuator getRedLed()
Gets the reference to the red LED of the robot.
Returns
the reference to the red LED.
Motor getLeftMotor()
Gets the reference to the left motor of the robot.
Returns
the reference to the left motor.
Motor getRightMotor()
Gets the reference to the right motor of the robot.
Returns
the reference to the right motor.

1.2. Actuators

All the actuators on AdMoVeo are analog (PMW) actuators. it can be powered by a value from 0-255, where 0 turns it off, and 255 gives the maxium power to the actuator. All the actuators (LED's, Buzzer and Motors) support the following control interfaces:

off()
Switches the actuator off. it has the same effect as setPower(0).
on()
Switches the actuator on. Switching it back on will give the power was set before it was switched off.
isOn()
Returns a boolean value to indicate whether it was switched on.
setPower(int power)
Sets the power level of the actuator.
power
the power level, between 0 and 255.
getPower()
Returns the power level it was set to.

1.2.1. Motors

Motors are special actuators, for its direction controls in addition to on(), off() and setPower():

forward()
Sets the motor to move forward.
backward()
Sets the motor to move backward.
reverse()
reverse the direction of the motor.
isForward()
Returns a boolean value to indicate whether it was set to move forward.

1.3. Sensors

1.4. Input event handling

Implementation of the push mode of event handling. To use this in Processing:

  1. A sensor must be enabled first using enable(). This is usually done in setup() in your Processing code.
  2. In Processing, define the following functions to be called to receive the input events when input is available.
  3. inputAvailable(Sensor sensor, int oldValue, int newValue)
    receives sensor input events in Processing.
    sensor
    from which sensor the input events is received.
    oldValue
    the old value before the change.
    newValue
    the new value after the change.
    The range of oldValue and newValue depends on the type of the sensor. For a digital sensor, either 0 or 1. For an analog sensor, from 0 to 1023.

    See also: InputEventHandling.

1.5. Task scheduling

execute(String task, int priority)
schedule a task to be executed in a dedicated thread.
task
the name of the callback function (to be defined in the Processing code);
priority

the priority of the task. either AdMoVeo.NOW, or AdMoVeo.LATER. Tasks with the priority AdMoVeo.LATER will not be executed until all the AdMoVeo.NOW tasks are executed.

execute(String task)

schedule a task to be executed in a dedicated thread, with a priority of AdMoVeo.LATER.

task
the name of the callback function;
scheduled callback task

in Processing code, the function should be defined as void <nameOftheFunction>(SensorStatus s). Such a function should always defined with a parameter with a type of "SensorStatus". This parameter carries a snapshot of the sensor values at the time the task was scheduled. You may "get" the sensor values from the SensorStatus with the sensor as the parameter. The sensor value should be usually greater than or equal to 0. If the value got is -1, it means at the moment of task being scheduled, the value has never changed yet.

1.6. Example

   1 import processing.serial.*;
   2 import nl.tue.id.creapro.admoveo.*;
   3 
   4 AdMoVeo admoveo;
   5 int bgcolor = 255;
   6 
   7 void setup()
   8 {
   9   admoveo = new AdMoVeo(this, "COM5"); 
  10   admoveo.getLeftDistanceSensor().enable();
  11 }
  12 
  13 void draw()
  14 {
  15   background(0,0,bgcolor);
  16 }
  17 
  18 void inputAvailable(Sensor sensor, int oldValue, int newValue){
  19     if(sensor == admoveo.getLeftDistanceSensor()){
  20         admoveo.execute("changeBlueLed", AdMoVeo.NOW);
  21     }
  22 }
  23 
  24 void changeBlueLed(SensorStatus s){
  25   bgcolor = s.get(admoveo.getLeftDistanceSensor())/4;
  26   admoveo.getBlueLed().setPower(bgcolor);
  27 }

CreaPro: AdMoVeoInProcessing (last edited 2008-11-24 12:17:39 by JunHu)