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

Laelaps kinematics velocity action class. More...

#include <laeKin.h>

Inheritance diagram for laelaps::LaeKinActionVelocity:
laelaps::LaeKinAction

Public Member Functions

 LaeKinActionVelocity (LaeKinematics &kin)
 Default initialization constructor. More...
 
virtual ~LaeKinActionVelocity ()
 Destructor.
 
int update (const LaeMapVelocity &velocity)
 Update with new velocities. More...
 
virtual int plan ()
 Plan next execution. 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 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

LaeMapVelocity m_mapGoalVel
 map of goal velocities
 
s32_t m_speed [LaeNumMotorCtlrs][LaeNumMotorsPerCtlr]
 target motor speeds (qpps)
 
- 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 velocity action class.

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

Definition at line 966 of file laeKin.h.

Constructor & Destructor Documentation

LaeKinActionVelocity::LaeKinActionVelocity ( LaeKinematics kin)

Default initialization constructor.

Parameters
kinBound kinemeatics driver.

Definition at line 1677 of file laeKin.cxx.

References clear().

1679 {
1680  clear();
1681 }
void clear()
Clear goal.
Definition: laeKin.cxx:1854
move by angular velocities
Definition: laeKin.h:783
LaeKinAction(LaeKinematics &kin, ActionType eActionType=ActionTypeIdle)
Default intialization constructor.
Definition: laeKin.h:808

Member Function Documentation

int LaeKinActionVelocity::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 1785 of file laeKin.cxx.

References laelaps::LaeKinAction::ActionStateIdle, motor::roboclaw::RoboClaw::cmdQDriveWithAccel(), laelaps::LaeKinAction::execute(), laelaps::LaeKinematics::getMotorCtlr(), laelaps::LaeKinAction::isExecutionRequired(), laelaps::LAE_ECODE_MOT_CTLR, laelaps::LAE_OK, laelaps::LaeMotorLeft, laelaps::LaeMotorRight, laelaps::LaeNumMotorCtlrs, laelaps::LaeKinAction::m_eActionState, laelaps::LaeKinAction::m_kin, and m_speed.

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

1786 {
1787  int nCtlr;
1788  RoboClaw *pMotorCtlr;
1789  int rc = LAE_OK;
1790 
1791  // no execution required
1792  if( !isExecutionRequired() )
1793  {
1794  return LAE_OK;
1795  }
1796 
1798 
1799  // set motor speeds
1800  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1801  {
1802  pMotorCtlr = m_kin.getMotorCtlr(nCtlr);
1803 
1804  //rc = pMotorCtlr->cmdQDrive2(m_speed[nCtlr][LaeMotorLeft],
1805  // m_speed[nCtlr][LaeMotorRight]);
1806 
1807  rc = pMotorCtlr->cmdQDriveWithAccel(
1808  m_speed[nCtlr][LaeMotorLeft], MoveAccel,
1809  m_speed[nCtlr][LaeMotorRight], MoveAccel);
1810 
1811  if( rc != OK )
1812  {
1813  rc = -LAE_ECODE_MOT_CTLR;
1814  break;
1815  }
1816  }
1817 
1819 
1820  return rc;
1821 }
RoboClaw 2 motor controller class.
Definition: RoboClaw.h:808
LaeKinematics & m_kin
bound kinematics driver
Definition: laeKin.h:948
s32_t m_speed[LaeNumMotorCtlrs][LaeNumMotorsPerCtlr]
target motor speeds (qpps)
Definition: laeKin.h:1021
virtual bool isExecutionRequired() const
Test if more action requires (more) execution.
Definition: laeKin.h:909
motor::roboclaw::RoboClaw * getMotorCtlr(const int nMotorCtlrId)
Get pointer to motor controller by name (key).
Definition: laeKin.cxx:918
static const int LaeMotorLeft
left motors
Definition: laeMotor.h:128
ActionState m_eActionState
action state.
Definition: laeKin.h:950
virtual int cmdQDriveWithAccel(int motor, s32_t speed, u32_t accel)
Drive a motor at the given speed and with the given acceleration.
Definition: RoboClaw.cxx:1399
static const int LAE_ECODE_MOT_CTLR
motor controller error
Definition: laelaps.h:97
virtual int execute()
Execution [sub]action.
Definition: laeKin.h:866
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
static const int LaeMotorRight
right motors
Definition: laeMotor.h:129
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinActionVelocity::plan ( )
virtual

Plan next execution.

If new velocities, the motor quad pulse per second are calculated.

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

Reimplemented from laelaps::LaeKinAction.

Definition at line 1727 of file laeKin.cxx.

References laelaps::LaeKinAction::ActionStateExecute, laelaps::LaeKinAction::ActionStateIdle, laelaps::LaePowertrain::getName(), laelaps::LaeKinematics::getPowertrain(), laelaps::LaeKinAction::isPlanningRequired(), laelaps::LAE_OK, laelaps::LaeNumMotorCtlrs, laelaps::LaeNumMotorsPerCtlr, laelaps::LaePowertrain::m_attr, laelaps::LaeKinAction::m_eActionState, laelaps::LaePowertrainAttr::m_fWheelRadsPerPulse, laelaps::LaeKinAction::m_kin, m_mapGoalVel, laelaps::LaePowertrainState::m_nSpeed, m_speed, laelaps::LaePowertrain::m_state, and laelaps::LaeKinAction::plan().

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

1728 {
1729  int nCtlr; // motor controller id
1730  int nMotor; // motor index
1731  LaePowertrain *pTrain; // working powertrain
1732  LaeMapVelocity::iterator goal; // working goal
1733  int nSpeed; // motor speed (qpps)
1734 
1735  if( !isPlanningRequired() )
1736  {
1737  return LAE_OK;
1738  }
1739 
1741 
1742  //
1743  // Iterate through motors and convert velocities to speeds.
1744  //
1745  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1746  {
1747  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
1748  {
1749  if( (pTrain = m_kin.getPowertrain(nCtlr, nMotor)) == NULL )
1750  {
1751  continue;
1752  }
1753 
1754  goal = m_mapGoalVel.find(pTrain->getName());
1755 
1756  // converted goal velocity speed is target speed
1757  if( goal != m_mapGoalVel.end() )
1758  {
1759  nSpeed = goal->second / pTrain->m_attr.m_fWheelRadsPerPulse;
1760  }
1761  // current speed is target speed
1762  else
1763  {
1764  nSpeed = pTrain->m_state.m_nSpeed;
1765  }
1766 
1767  //
1768  // New speed
1769  //
1770  if( m_speed[nCtlr][nMotor] != nSpeed )
1771  {
1772  m_speed[nCtlr][nMotor] = nSpeed;
1774  }
1775  }
1776  }
1777 
1778  // planned, but no execution required
1780  {
1782  }
1783 }
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
LaeKinematics & m_kin
bound kinematics driver
Definition: laeKin.h:948
s32_t m_speed[LaeNumMotorCtlrs][LaeNumMotorsPerCtlr]
target motor speeds (qpps)
Definition: laeKin.h:1021
virtual bool isPlanningRequired()
Test if action requires (re)planning.
Definition: laeKin.h:899
ActionState m_eActionState
action state.
Definition: laeKin.h:950
LaePowertrainAttr m_attr
semi-fixed attribute data
std::string getName() const
Get this powertrain unique name (key).
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
double m_fWheelRadsPerPulse
output shaft radians per encoder pulse
Definition: laePowertrain.h:92
LaeMapVelocity m_mapGoalVel
map of goal velocities
Definition: laeKin.h:1020
LaePowertrainState m_state
dynamic state data
Powertrain data class.
virtual int plan()
Plan next execution.
Definition: laeKin.h:854
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
int m_nSpeed
raw speed (qpps)
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinActionVelocity::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 1823 of file laeKin.cxx.

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

1824 {
1825  LaeMapVelocity::iterator iter;
1826  int nCtlr;
1827  RoboClaw *pMotorCtlr;
1828 
1829  // already terminated
1830  if( hasTerminated() )
1831  {
1832  return LAE_OK;
1833  }
1834 
1835  //
1836  // Stop all motors.
1837  //
1838  // Note: Do not call m_kin.stop() here, since it calls this function.
1839  //
1840  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1841  {
1842  pMotorCtlr = m_kin.getMotorCtlr(nCtlr);
1843  //pMotorCtlr->cmdQStop();
1844  pMotorCtlr->cmdStopWithDecel(StopDecel);
1845  }
1846 
1847  clear();
1848 
1850 
1851  return LAE_OK;
1852 }
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
motor::roboclaw::RoboClaw * getMotorCtlr(const int nMotorCtlrId)
Get pointer to motor controller by name (key).
Definition: laeKin.cxx:918
void clear()
Clear goal.
Definition: laeKin.cxx:1854
virtual int cmdStopWithDecel(int motor, u32_t decel)
Stop a motor with the given maximum decelerations.
Definition: RoboClaw.cxx:1711
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 LaeKinActionVelocity::update ( const LaeMapVelocity velocity)

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 1683 of file laeKin.cxx.

References laelaps::LaeKinAction::ActionStateIdle, laelaps::LaeKinAction::ActionStatePlan, laelaps::LaeKinAction::ActionStateUpdate, laelaps::LAE_OK, laelaps::LaeKinAction::m_eActionState, and m_mapGoalVel.

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

1684 {
1685  LaeMapVelocity::const_iterator iter;
1686  LaeMapVelocity::iterator pos;
1687 
1688  // set state to update
1690 
1691  //
1692  // Iterate through key,velocity map.
1693  //
1694  for(iter = velocity.begin(); iter != velocity.end(); ++iter)
1695  {
1696  pos = m_mapGoalVel.find(iter->first);
1697 
1698  // velocity on a new action powertrain
1699  if( pos == m_mapGoalVel.end() )
1700  {
1701  m_mapGoalVel[iter->first] = iter->second;
1703  }
1704 
1705  // different velocity on an existing action powertrain
1706  else if( pos->second != iter->second )
1707  {
1708  pos->second = iter->second;
1710  }
1711 
1712  // else same velocity
1713 
1714  LOGDIAG3("Wheel %12s velocity = %lf rads/s.",
1715  iter->first.c_str(), iter->second);
1716  }
1717 
1718  // updated, but no planning and execution required
1720  {
1722  }
1723 
1724  return LAE_OK;
1725 }
ActionState m_eActionState
action state.
Definition: laeKin.h:950
LaeMapVelocity m_mapGoalVel
map of goal velocities
Definition: laeKin.h:1020
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: