dLife Home Page

dlife.robot.khepera2
Class Khepera2DifferentialDrive

java.lang.Object
  extended by java.util.Observable
      extended by dlife.robot.Device
          extended by dlife.robot.DifferentialDriveEffector
              extended by dlife.robot.khepera2.Khepera2DifferentialDrive

public class Khepera2DifferentialDrive
extends DifferentialDriveEffector

A class to control the motion of a Khepera2. This class also allows the configuration of the Khepera2's PID controller for speed control.

Version:
Jan 14, 2011
Author:
Grant Braught, Dickinson College

Field Summary
 
Fields inherited from class dlife.robot.DifferentialDriveEffector
vL, vR
 
Fields inherited from class dlife.robot.Device
DEFAULT_GUI_UPDATE_DELAY, DEFAULT_READ_DELAY, myRobot, readCount
 
Constructor Summary
Khepera2DifferentialDrive()
          Construct a Khepera2DifferentialDrive.
Khepera2DifferentialDrive(int Kp, int Ki, int Kd)
          Construct a Khepera2DifferentialDrive that uses the specified gains for the PID speed controller.
 
Method Summary
 void configureSpeedController(int Kp, int Ki, int Kd)
          Configure the Khepera2's speed PID controller using the specified gains.
 void readStateFromRobot()
          Updates the speeds of the wheels using information returned from the Khepera2.
 void setMotorPWM(double leftPWM, double rightPWM)
          Directly control the pulse width modulation (PWM) ratio of the left and right wheel motors.
protected  void setRobotWheelSpeeds(double left, double right)
          Set the speed of the robot wheels.
 void startUp()
          Invoke super.startUp and then configure the speed PID controller if the default values are not being used.
 
Methods inherited from class dlife.robot.DifferentialDriveEffector
createGUIObjects, freeze, getLeftWheelSpeed, getRightWheelSpeed, getRotation, getTranslation, move, rotate, setWheelSpeeds, shutDown, translate
 
Methods inherited from class dlife.robot.Device
getAutoRead, getGUI, getGUIUpdateDelay, getReadDelay, getRobot, getSensorReadCount, getSensorReadRate, setAutoRead, setGUIUpdateDelay, setReadDelay, setRobot, startAutoReadTimer, stopAutoReadTimer
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Khepera2DifferentialDrive

public Khepera2DifferentialDrive()
Construct a Khepera2DifferentialDrive. The Khepera's default gains will be used for the PID speed controller.


Khepera2DifferentialDrive

public Khepera2DifferentialDrive(int Kp,
                                 int Ki,
                                 int Kd)
Construct a Khepera2DifferentialDrive that uses the specified gains for the PID speed controller.

Parameters:
Kp - gain for proportional control in PID.
Ki - gain for integral control in PID.
Kd - gain for derivative control in PID.
Method Detail

startUp

public void startUp()
Invoke super.startUp and then configure the speed PID controller if the default values are not being used.

Overrides:
startUp in class Device

setRobotWheelSpeeds

protected void setRobotWheelSpeeds(double left,
                                   double right)
Set the speed of the robot wheels. Speeds will be given as a number between -1...1.

Specified by:
setRobotWheelSpeeds in class DifferentialDriveEffector
Parameters:
left - the left speed
right - the right speed
Throws:
RobotCommunicationException - if unable to communicate with the Khepera2.

configureSpeedController

public void configureSpeedController(int Kp,
                                     int Ki,
                                     int Kd)
Configure the Khepera2's speed PID controller using the specified gains.

Parameters:
Kp - gain for proportional control in PID.
Ki - gain for integral control in PID.
Kd - gain for derivative control in PID.

setMotorPWM

public void setMotorPWM(double leftPWM,
                        double rightPWM)
Directly control the pulse width modulation (PWM) ratio of the left and right wheel motors. The value for each motor is in the range [-1...1] indicating the fraction of the pulse cycle that the motor is on (0 = always off, 1 = always on). Positive values indicate forward motion and negative values indicate reverse motion. See the Khepera manuals for more information on the PWM control of the motors.

Parameters:
leftPWM - fraction of on time for left wheel motor.
rightPWM - fraction of on time for right wheel motor.

readStateFromRobot

public void readStateFromRobot()
Updates the speeds of the wheels using information returned from the Khepera2. Speeds are rescaled into a value between -1...1. Note: Actual wheel speeds are returned from the robot. If the robot is stalled against an obstacle, the wheel speeds will be 0,0. This is true for both the physical Khepera2 and the Khepera2Player robots.

Specified by:
readStateFromRobot in class Device

dLife Home Page