org.bluemelon.bluesense
Class MotorDevice

java.lang.Object
  extended by org.bluemelon.bluesense.Device
      extended by org.bluemelon.bluesense.MotorDevice

public class MotorDevice
extends Device

Interface to the dc motor module BM7005. The BM7005 can be used to control the speed of 2 dc motors.


Field Summary
static int BSMOTOR_P1
          Port value for pin 1
static int BSMOTOR_P2
          Port value for pin 2
static int MOTORCOUNT
          The number of motors that can be controlled
static int PROXY_ID
           
static java.lang.String PROXY_TITLE
           
static int[] SUPPORTS
           
 
Constructor Summary
MotorDevice(Master master, int deviceId)
          Creates a 'software' dc motor device proxy with a given id.
 
Method Summary
 int getCurrentSpeed(int port)
          Returns the current set speed of a specific motor.
 void getCurrentSpeeds(int[] speedArray)
          Fills an array with the current set speeds.
 int getPendingSpeed(int port)
          Returns the speed of a specific motor, which is currently underway to the device
 void getPendingSpeeds(int[] speeds)
          Fills an array with speeds which are currently underway to the device
 boolean getRequestSetSpeedsDone()
          Checks if the speed set request is finished
 long getTimeOutUs()
          Returns the current set time out delay.
 void requestGetSpeeds()
          Sends a request to retrieve the current set speeds
 void requestSetSpeed(int port, int speed)
          Requests the motor device to set one of its motors to a new speed
 void requestSetSpeeds(int relevantSpeeds, int[] speeds)
          Requests the motor device to set its motors to new speeds
 void setTimeOutUs(int timeOutUs)
          Sets the time out value which is used to check if a request was acknowledged in the set time.
 
Methods inherited from class org.bluemelon.bluesense.Device
addDeviceEventListener, detect, getFirmwareVersion, getId, getType, getTypeName, isAccessible, removeDeviceEventListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROXY_TITLE

public static final java.lang.String PROXY_TITLE

PROXY_ID

public static final int PROXY_ID

SUPPORTS

public static final int[] SUPPORTS

MOTORCOUNT

public static final int MOTORCOUNT
The number of motors that can be controlled


BSMOTOR_P1

public static final int BSMOTOR_P1
Port value for pin 1


BSMOTOR_P2

public static final int BSMOTOR_P2
Port value for pin 2

Constructor Detail

MotorDevice

public MotorDevice(Master master,
                   int deviceId)
Creates a 'software' dc motor device proxy with a given id. The device will inacessible until a physical device with the same id is detected.

Parameters:
master -
deviceId -
Method Detail

requestSetSpeeds

public void requestSetSpeeds(int relevantSpeeds,
                             int[] speeds)
Requests the motor device to set its motors to new speeds

Parameters:
relevantSpeeds - a bit mask indicating which motors to update
speeds - a pointer to an array of byte speeds with enough space for all motors. @see MOTORCOUNT Note that each speed is a value between -128 and 127. -128 to -1 represent a speed left, 0 stand still and 1 to 127 a speed right, the actual physical speed depends on the specifications of the connected motor.

requestSetSpeed

public void requestSetSpeed(int port,
                            int speed)
Requests the motor device to set one of its motors to a new speed

Parameters:
port - one of the port pin values. @see bsMotor_p1
speed - an uint8_t representing the new speed of the motor. Note that each speed is a value between -128 and 127. -128 to -1 represent a speed left, 0 stand still and 1 to 127 a speed right, the actual physical speed depends on the specifications of the connected motor.

requestGetSpeeds

public void requestGetSpeeds()
Sends a request to retrieve the current set speeds


getPendingSpeeds

public void getPendingSpeeds(int[] speeds)
Fills an array with speeds which are currently underway to the device

Parameters:
speeds - a pointer to an array of uint8_t speeds with enough space for all motors. @see BLUESENSE_MOTORCONTROLLER_MOTORCOUNT

getPendingSpeed

public int getPendingSpeed(int port)
Returns the speed of a specific motor, which is currently underway to the device

Parameters:
port - one of the port pin values. @see bsMotor_p1
Returns:
the speed to be set on the motor.

getRequestSetSpeedsDone

public boolean getRequestSetSpeedsDone()
Checks if the speed set request is finished

Returns:
1 if request finished, 0 if request still busy

getCurrentSpeed

public int getCurrentSpeed(int port)
Returns the current set speed of a specific motor.

Parameters:
port - one of the port pin values. @see bsMotor_p1
Returns:
the speed off the motor.

getCurrentSpeeds

public void getCurrentSpeeds(int[] speedArray)
Fills an array with the current set speeds.

Parameters:
speedArray - a pointer to an array of uint8_t speeds with enough space for all motors. @see BLUESENSE_MOTORCONTROLLER_MOTORCOUNT

getTimeOutUs

public long getTimeOutUs()
Returns the current set time out delay. The time out delay is used to check if a request was acknowledged in the set time. If an answer to a request is not received within the set time, the request is resent.

Returns:
the time out value in microseconds.

setTimeOutUs

public void setTimeOutUs(int timeOutUs)
Sets the time out value which is used to check if a request was acknowledged in the set time. If an answer to a request is not received within the set time, the request is resent.

Parameters:
timeOutUs - the value in microseconds which is the maximum duraion between a request and its answer.