Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps::LaeKinActionDutyCycle Class Reference

Laelaps kinematics duty cycle action class. More...

#include <laeKin.h>

Inheritance diagram for laelaps::LaeKinActionDutyCycle:
laelaps::LaeKinAction

Public Member Functions

 LaeKinActionDutyCycle (LaeKinematics &kin)
 Default initialization constructor. More...
 
virtual ~LaeKinActionDutyCycle ()
 Destructor.
 
int update (const LaeMapDutyCycle &dutycycle)
 Update with new velocities. More...
 
virtual int execute ()
 Execution new velocities. More...
 
virtual int terminate ()
 Terminate action. More...
 
- Public Member Functions inherited from laelaps::LaeKinAction
 LaeKinAction (LaeKinematics &kin, ActionType eActionType=ActionTypeIdle)
 Default intialization constructor. More...
 
virtual ~LaeKinAction ()
 Destructor.
 
virtual int plan ()
 Plan next execution. More...
 
virtual bool isIdle ()
 Test if action is idle. More...
 
virtual bool isPlanningRequired ()
 Test if action requires (re)planning. More...
 
virtual bool isExecutionRequired () const
 Test if more action requires (more) execution. More...
 
virtual bool hasTerminated () const
 Test if action has been terminated. More...
 
virtual ActionType getActionType () const
 Get the action type for this class. More...
 
virtual ActionState getActionState () const
 Get the action state. More...
 

Protected Member Functions

void clear ()
 Clear goal.
 

Protected Attributes

LaeMapDutyCycle m_mapGoalDutyCycle
 map of goal duty cycles
 
- Protected Attributes inherited from laelaps::LaeKinAction
LaeKinematicsm_kin
 bound kinematics driver
 
ActionType m_eActionType
 action type enum
 
ActionState m_eActionState
 action state.
 

Additional Inherited Members

- Public Types inherited from laelaps::LaeKinAction
enum  ActionType {
  ActionTypeIdle,
  ActionTypeVelocity,
  ActionTypeDutyCycle,
  ActionTypeTwist,
  ActionTypeNavForDist,
  ActionTypeNavToPos
}
 Supported kinematic extended actions. More...
 
enum  ActionState {
  ActionStateIdle,
  ActionStateUpdate,
  ActionStatePlan,
  ActionStateExecute,
  ActionStateTerminated
}
 Action states. More...
 
- Static Public Member Functions inherited from laelaps::LaeKinAction
static LaeKinActionnewAction (LaeKinematics &kin, const ActionType eActionType)
 Archetype constructor to create action type instance. More...
 
static LaeKinActionreplaceAction (LaeKinematics &kin, LaeKinAction *pAction, const ActionType eNewActionType)
 Archetype constructor to replace action type instance. More...
 

Detailed Description

Laelaps kinematics duty cycle action class.

A velocity action only sets the duty cycles of a (sub)set of the powertrain motors. Powertrains not specified are kept at their current duty cycles.

Definition at line 1042 of file laeKin.h.

Constructor & Destructor Documentation

LaeKinActionDutyCycle::LaeKinActionDutyCycle ( LaeKinematics kin)

Default initialization constructor.

Parameters
kinBound kinemeatics driver.

Definition at line 1872 of file laeKin.cxx.

1874 {
1875 }
move by motor duty cycles
Definition: laeKin.h:784
LaeKinAction(LaeKinematics &kin, ActionType eActionType=ActionTypeIdle)
Default intialization constructor.
Definition: laeKin.h:808

Member Function Documentation

int LaeKinActionDutyCycle::execute ( )
virtual

Execution new velocities.

All motors with new velocities are written with new speeds.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from laelaps::LaeKinAction.

Definition at line 1920 of file laeKin.cxx.

References laelaps::LaeKinAction::ActionStateIdle, motor::roboclaw::RoboClaw::cmdDutyDrive2(), laelaps::LaeKinAction::execute(), laelaps::LaeKinematics::getMotorCtlr(), laelaps::LaePowertrain::getName(), laelaps::LaeKinematics::getPowertrain(), laelaps::LaeKinAction::isExecutionRequired(), laelaps::LAE_ECODE_MOT_CTLR, laelaps::LAE_OK, laelaps::LaeNumMotorCtlrs, laelaps::LaeNumMotorsPerCtlr, laelaps::LaeKinAction::m_eActionState, laelaps::LaeKinAction::m_kin, and m_mapGoalDutyCycle.

Referenced by laelaps::LaeKinematics::setGoalDutyCycles().

1921 {
1922  int nCtlr; // motor controller id
1923  int nMotor; // motor index
1924  LaePowertrain *pTrain; // working powertrain
1925  LaeMapDutyCycle::iterator goal; // working goal
1926  double fDuty[LaeNumMotorsPerCtlr]; // working duty cycles
1927  bool bDoExec; // do [not] exec
1928  RoboClaw *pMotorCtlr; // motor controller
1929  int rc; // return code
1930 
1931  // no execution required
1932  if( !isExecutionRequired() )
1933  {
1934  return LAE_OK;
1935  }
1936 
1938 
1939  //
1940  // Iterate through motors and executre new duty cycle commands.
1941  //
1942  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1943  {
1944  bDoExec = false;
1945 
1946  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
1947  {
1948  if( (pTrain = m_kin.getPowertrain(nCtlr, nMotor)) == NULL )
1949  {
1950  continue;
1951  }
1952 
1953  goal = m_mapGoalDutyCycle.find(pTrain->getName());
1954 
1955  if( goal != m_mapGoalDutyCycle.end() )
1956  {
1957  fDuty[nMotor] = goal->second;
1958  bDoExec = true;
1959  }
1960  else
1961  {
1962  fDuty[nMotor] = 0.0;
1963  }
1964  }
1965 
1966  if( bDoExec )
1967  {
1968  pMotorCtlr = m_kin.getMotorCtlr(nCtlr);
1969 
1970  rc = pMotorCtlr->cmdDutyDrive2(fDuty[0], fDuty[1]);
1971 
1972  if( rc != OK )
1973  {
1974  rc = -LAE_ECODE_MOT_CTLR;
1975  break;
1976  }
1977  }
1978  }
1979 
1981 
1982  return rc;
1983 }
RoboClaw 2 motor controller class.
Definition: RoboClaw.h:808
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
LaeKinematics & m_kin
bound kinematics driver
Definition: laeKin.h:948
virtual bool isExecutionRequired() const
Test if more action requires (more) execution.
Definition: laeKin.h:909
virtual int cmdDutyDrive2(double duty1, double duty2)
Drive both motors at the given duty cycle.
Definition: RoboClaw.cxx:1297
motor::roboclaw::RoboClaw * getMotorCtlr(const int nMotorCtlrId)
Get pointer to motor controller by name (key).
Definition: laeKin.cxx:918
ActionState m_eActionState
action state.
Definition: laeKin.h:950
static const int LAE_ECODE_MOT_CTLR
motor controller error
Definition: laelaps.h:97
std::string getName() const
Get this powertrain unique name (key).
virtual int execute()
Execution [sub]action.
Definition: laeKin.h:866
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
LaeMapDutyCycle m_mapGoalDutyCycle
map of goal duty cycles
Definition: laeKin.h:1087
Powertrain data class.
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinActionDutyCycle::terminate ( )
virtual

Terminate action.

All motors are stopped.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented from laelaps::LaeKinAction.

Definition at line 1985 of file laeKin.cxx.

References clear(), motor::roboclaw::RoboClaw::cmdDutyDrive2(), laelaps::LaeKinematics::getMotorCtlr(), laelaps::LaeKinAction::hasTerminated(), laelaps::LAE_OK, laelaps::LaeNumMotorCtlrs, laelaps::LaeKinAction::m_kin, and laelaps::LaeKinAction::terminate().

1986 {
1987  LaeMapDutyCycle::iterator iter;
1988  int nCtlr;
1989  RoboClaw *pMotorCtlr;
1990 
1991  // already terminated
1992  if( hasTerminated() )
1993  {
1994  return LAE_OK;
1995  }
1996 
1997  //
1998  // Coast all motors.
1999  //
2000  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
2001  {
2002  pMotorCtlr = m_kin.getMotorCtlr(nCtlr);
2003  pMotorCtlr->cmdDutyDrive2(0.0, 0.0);
2004  }
2005 
2006  clear();
2007 
2009 
2010  return LAE_OK;
2011 }
RoboClaw 2 motor controller class.
Definition: RoboClaw.h:808
LaeKinematics & m_kin
bound kinematics driver
Definition: laeKin.h:948
virtual bool hasTerminated() const
Test if action has been terminated.
Definition: laeKin.h:922
void clear()
Clear goal.
Definition: laeKin.cxx:2013
virtual int cmdDutyDrive2(double duty1, double duty2)
Drive both motors at the given duty cycle.
Definition: RoboClaw.cxx:1297
motor::roboclaw::RoboClaw * getMotorCtlr(const int nMotorCtlrId)
Get pointer to motor controller by name (key).
Definition: laeKin.cxx:918
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int terminate()
Terminate action.
Definition: laeKin.h:878
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinActionDutyCycle::update ( const LaeMapDutyCycle dutycycle)

Update with new velocities.

Parameters
velocityMap of powertrain velocities.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1877 of file laeKin.cxx.

References laelaps::LaeKinAction::ActionStateExecute, laelaps::LaeKinAction::ActionStateIdle, laelaps::LaeKinAction::ActionStateUpdate, laelaps::LAE_OK, laelaps::LaeKinAction::m_eActionState, and m_mapGoalDutyCycle.

Referenced by laelaps::LaeKinematics::setGoalDutyCycles().

1878 {
1879  LaeMapDutyCycle::const_iterator iter;
1880  LaeMapDutyCycle::iterator pos;
1881 
1882  // set state to update
1884 
1885  //
1886  // Iterate through key,duty map.
1887  //
1888  for(iter = duty.begin(); iter != duty.end(); ++iter)
1889  {
1890  pos = m_mapGoalDutyCycle.find(iter->first);
1891 
1892  // duty on a new action powertrain
1893  if( pos == m_mapGoalDutyCycle.end() )
1894  {
1895  m_mapGoalDutyCycle[iter->first] = iter->second;
1897  }
1898 
1899  // different duty on an existing action powertrain
1900  else if( pos->second != iter->second )
1901  {
1902  pos->second = iter->second;
1904  }
1905 
1906  // else same duty
1907 
1908  LOGDIAG3("Motor %12s duty = %5.3lf.", iter->first.c_str(), iter->second);
1909  }
1910 
1911  // no planning and execution required
1913  {
1915  }
1916 
1917  return LAE_OK;
1918 }
ActionState m_eActionState
action state.
Definition: laeKin.h:950
LaeMapDutyCycle m_mapGoalDutyCycle
map of goal duty cycles
Definition: laeKin.h:1087
update action specific data
Definition: laeKin.h:796
static const int LAE_OK
not an error, success
Definition: laelaps.h:71

The documentation for this class was generated from the following files: