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

Laelaps kinematics velocity action class. More...

#include <laeKin.h>

Inheritance diagram for laelaps::LaeKinActionTwist:
laelaps::LaeKinAction

Public Member Functions

 LaeKinActionTwist (LaeKinematics &kin)
 Default initialization constructor. More...
 
virtual ~LaeKinActionTwist ()
 Destructor.
 
int update (double fVelLinear, double fVelAngular)
 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

double m_fGoalVelLinear
 goal platform linear velocity
 
double m_fGoalVelAngular
 goal platform angular velocity
 
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 1108 of file laeKin.h.

Constructor & Destructor Documentation

LaeKinActionTwist::LaeKinActionTwist ( LaeKinematics kin)

Default initialization constructor.

Parameters
kinBound kinemeatics driver.

Definition at line 2023 of file laeKin.cxx.

References clear().

2025 {
2026  clear();
2027 }
move robot by twist values
Definition: laeKin.h:785
void clear()
Clear goal.
Definition: laeKin.cxx:2227
LaeKinAction(LaeKinematics &kin, ActionType eActionType=ActionTypeIdle)
Default intialization constructor.
Definition: laeKin.h:808

Member Function Documentation

int LaeKinActionTwist::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 2159 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::setGoalTwist().

2160 {
2161  int nCtlr;
2162  RoboClaw *pMotorCtlr;
2163  int rc = LAE_OK;
2164 
2165  // no execution required
2166  if( !isExecutionRequired() )
2167  {
2168  return LAE_OK;
2169  }
2170 
2172 
2173  // set motor speeds
2174  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
2175  {
2176  pMotorCtlr = m_kin.getMotorCtlr(nCtlr);
2177 
2178  //rc = pMotorCtlr->cmdQDrive2(m_speed[nCtlr][LaeMotorLeft],
2179  // m_speed[nCtlr][LaeMotorRight]);
2180 
2181  rc = pMotorCtlr->cmdQDriveWithAccel(
2182  m_speed[nCtlr][LaeMotorLeft], MoveAccel,
2183  m_speed[nCtlr][LaeMotorRight], MoveAccel);
2184 
2185  if( rc != OK )
2186  {
2187  rc = -LAE_ECODE_MOT_CTLR;
2188  break;
2189  }
2190  }
2191 
2193 
2194  return rc;
2195 }
RoboClaw 2 motor controller class.
Definition: RoboClaw.h:808
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
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
s32_t m_speed[LaeNumMotorCtlrs][LaeNumMotorsPerCtlr]
target motor speeds (qpps)
Definition: laeKin.h:1165
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinActionTwist::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 2053 of file laeKin.cxx.

References laelaps::LaeKinAction::ActionStateExecute, laelaps::LaeKinAction::ActionStateIdle, laelaps::LaeKinematics::getPlatform(), laelaps::LaeKinematics::getPowertrain(), laelaps::LaeKinAction::isPlanningRequired(), laelaps::LAE_OK, laelaps::LaeMotorLeft, laelaps::LaeNumMotorCtlrs, laelaps::LaeNumMotorsPerCtlr, laelaps::LaePowertrain::m_attr, laelaps::LaeKinAction::m_eActionState, m_fGoalVelAngular, m_fGoalVelLinear, laelaps::LaePowertrainAttr::m_fMetersPerPulse, laelaps::LaePlatform::m_fWheeltrack, laelaps::LaeKinAction::m_kin, m_speed, laelaps::LaePowertrainAttr::m_uMaxQpps, and laelaps::LaeKinAction::plan().

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

2054 {
2055  int nCtlr; // motor controller id
2056  int nMotor; // motor index
2057  LaePowertrain *pTrain; // working powertrain
2058  int nSpeed; // motor speed (qpps)
2059 
2060  if( !isPlanningRequired() )
2061  {
2062  return LAE_OK;
2063  }
2064 
2066 
2067  double halftrack = m_kin.getPlatform().m_fWheeltrack / 2.0; // radius
2068  double velAngLin = m_fGoalVelAngular * halftrack; // anglur to linear
2069  double ppm; // quad pulses/meter
2070  double ppsLin; // quad pulses/second for linear component
2071  double ppsAng; // quad pulses/second for angular component
2072  double ppsAbsMax = 0.0; // absolute max qqps
2073  double ppsRatedMinMax = 10e10; // lowest max rated powertrain qpps
2074  double pps[LaeNumMotorCtlrs][LaeNumMotorsPerCtlr]; // goal qpps
2075 
2076  //
2077  // Iterate through motors and convert twist to speeds.
2078  //
2079  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
2080  {
2081  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
2082  {
2083  if( (pTrain = m_kin.getPowertrain(nCtlr, nMotor)) == NULL )
2084  {
2085  continue;
2086  }
2087 
2088  ppm = 1.0 / pTrain->m_attr.m_fMetersPerPulse;
2089 
2090  ppsLin = m_fGoalVelLinear * ppm;
2091  ppsAng = velAngLin * ppm;
2092 
2093  if( nMotor == LaeMotorLeft )
2094  {
2095  pps[nCtlr][nMotor] = ppsLin - ppsAng;
2096  }
2097  else
2098  {
2099  pps[nCtlr][nMotor] = ppsLin + ppsAng;
2100  }
2101 
2102  // powetrain with the highest absolute speed
2103  if( fabs(pps[nCtlr][nMotor]) > ppsAbsMax )
2104  {
2105  ppsAbsMax = fabs(pps[nCtlr][nMotor]);
2106  }
2107 
2108  // powertrain with the lowest maximum speed
2109  if( (double)pTrain->m_attr.m_uMaxQpps < ppsRatedMinMax )
2110  {
2111  ppsRatedMinMax = (double)pTrain->m_attr.m_uMaxQpps;
2112  }
2113  }
2114  }
2115 
2116  //
2117  // Derate speed to work within the specs of the lowest motor capabilites.
2118  //
2119  if( ppsAbsMax > ppsRatedMinMax )
2120  {
2121  double derate = ppsRatedMinMax / ppsAbsMax;
2122 
2123  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
2124  {
2125  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
2126  {
2127  pps[nCtlr][nMotor] *= derate;
2128  }
2129  }
2130  }
2131 
2132  //
2133  // Now set the target motor speeds.
2134  //
2135  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
2136  {
2137  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
2138  {
2139  nSpeed = (int)pps[nCtlr][nMotor];
2140 
2141  //
2142  // New speed
2143  //
2144  if( m_speed[nCtlr][nMotor] != nSpeed )
2145  {
2146  m_speed[nCtlr][nMotor] = nSpeed;
2148  }
2149  }
2150  }
2151 
2152  // planned, but no execution required
2154  {
2156  }
2157 }
double m_fWheeltrack
wheeltrack (m)
Definition: laePlatform.h:146
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
LaeKinematics & m_kin
bound kinematics driver
Definition: laeKin.h:948
double m_fGoalVelLinear
goal platform linear velocity
Definition: laeKin.h:1163
virtual bool isPlanningRequired()
Test if action requires (re)planning.
Definition: laeKin.h:899
static const int LaeMotorLeft
left motors
Definition: laeMotor.h:128
ActionState m_eActionState
action state.
Definition: laeKin.h:950
LaePowertrainAttr m_attr
semi-fixed attribute data
uint_t m_uMaxQpps
maximum quadrature pulses/second rps
Definition: laePowertrain.h:90
double m_fMetersPerPulse
tire meters per encoder pulse
Definition: laePowertrain.h:99
double m_fGoalVelAngular
goal platform angular velocity
Definition: laeKin.h:1164
LaePlatform & getPlatform()
Get robot platform kinodynamics.
Definition: laeKin.h:226
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
Powertrain data class.
s32_t m_speed[LaeNumMotorCtlrs][LaeNumMotorsPerCtlr]
target motor speeds (qpps)
Definition: laeKin.h:1165
virtual int plan()
Plan next execution.
Definition: laeKin.h:854
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 LaeKinActionTwist::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 2197 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().

2198 {
2199  LaeMapVelocity::iterator iter;
2200  int nCtlr;
2201  RoboClaw *pMotorCtlr;
2202 
2203  // already terminated
2204  if( hasTerminated() )
2205  {
2206  return LAE_OK;
2207  }
2208 
2209  //
2210  // Stop all motors.
2211  //
2212  // Note: Do not call m_kin.stop() here, since it calls this function.
2213  //
2214  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
2215  {
2216  pMotorCtlr = m_kin.getMotorCtlr(nCtlr);
2217  pMotorCtlr->cmdStopWithDecel(StopDecel);
2218  }
2219 
2220  clear();
2221 
2223 
2224  return LAE_OK;
2225 }
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:2227
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 LaeKinActionTwist::update ( double  fVelLinear,
double  fVelAngular 
)

Update with new velocities.

Parameters
fVelLinearLinear velocity (meters/second).
fVelAngularAngular velocity (radians/second).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 2029 of file laeKin.cxx.

References laelaps::LaeKinAction::ActionStateIdle, laelaps::LaeKinAction::ActionStatePlan, laelaps::LaeKinAction::ActionStateUpdate, laelaps::LAE_OK, laelaps::LaeKinAction::m_eActionState, m_fGoalVelAngular, m_fGoalVelLinear, and laelaps::radToDeg().

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

2030 {
2031  // set state to update
2033 
2034  if( (fVelLinear != m_fGoalVelLinear) || (fVelAngular != m_fGoalVelAngular) )
2035  {
2036  m_fGoalVelLinear = fVelLinear;
2037  m_fGoalVelAngular = fVelAngular;
2039 
2040  LOGDIAG3("Robot linear velocity = %lf m/s, angular velocity = %lf deg/s.",
2042  }
2043 
2044  // updated, but no planning and execution required
2045  else
2046  {
2048  }
2049 
2050  return LAE_OK;
2051 }
double m_fGoalVelLinear
goal platform linear velocity
Definition: laeKin.h:1163
double radToDeg(double r)
Convert radians to degrees.
Definition: laeUtils.h:136
ActionState m_eActionState
action state.
Definition: laeKin.h:950
double m_fGoalVelAngular
goal platform angular velocity
Definition: laeKin.h:1164
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: