Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
motor::roboclaw::RoboClaw Class Reference

RoboClaw 2 motor controller class. More...

#include <RoboClaw.h>

Public Member Functions

 RoboClaw (RoboClawComm &comm, const byte_t address=AddrDft, const std::string &strNameId="RoboClaw")
 Initialization constructor. More...
 
virtual ~RoboClaw ()
 Destructor.
 
virtual bool probe (byte_t address)
 Probe address of motor controller. More...
 
RoboClawCommgetComm ()
 Get RoboClaw's bound communication object. More...
 
bool isOpen () const
 Test if connection is open. More...
 
byte_t getAddress () const
 Get the controller address associated with this class instance. More...
 
void setAddress (byte_t address)
 Set class instance address. More...
 
std::string getNameId () const
 Get class instance name identifier. More...
 
void setNameId (const std::string &strNameId)
 Set class instance name identifier. More...
 
virtual byte_t getMotorDir (int motor) const
 Get the direction of motor rotation. More...
 
virtual void setMotorDir (int motor, int motorDir)
 set the direction of motor rotation. More...
 
void getMainBattCutoffRange (double &minmin, double &maxmax) const
 Get the RoboClaw's main battery minimum and maximum voltage cutoff settable range. More...
 
void getLogicCutoffRange (double &minmin, double &maxmax) const
 Get the RoboClaw's logic minimum and maximum voltage cutoff settable range. More...
 
virtual int cmdReadFwVersion (std::string &strFwVer)
 Read the RoboClaw's firmware version. More...
 
virtual int cmdReadMainBattVoltage (double &volts)
 Read the RoboClaw's main battery input voltage. More...
 
virtual int cmdReadMainBattCutoffs (double &min, double &max)
 Read the RoboClaw's main battery minimum and maximum voltage cutoff settings. More...
 
virtual int cmdSetMainBattCutoffs (const double min, const double max)
 Set the RoboClaw's main battery minimum and maximum voltage cutoff settings. More...
 
virtual int cmdReadLogicVoltage (double &volts)
 Read the RoboClaw's LB-/LB+ terminals input voltage powered by and optional logic dedicated battery. More...
 
virtual int cmdReadLogicCutoffs (double &min, double &max)
 Read the RoboClaw's optional logic dedicated battery minimum and maximum voltage cutoff settings. The battery is connected to the LB-/LB+ terminals. More...
 
virtual int cmdSetLogicCutoffs (const double min, const double max)
 Set the RoboClaw's optional logic dedicated battery minimum and maximum voltage cutoff settings. The battery is connected to the LB-/LB+ terminals. More...
 
virtual int cmdReadVelocityPidConst (int motor, u32_t &Kp, u32_t &Ki, u32_t &Kd, u32_t &qpps)
 Read motor's velocity PID constants. More...
 
virtual int cmdSetVelocityPidConst (int motor, const u32_t Kp, const u32_t Ki, const u32_t Kd, const u32_t qpps)
 Set motor's velocity PID constants. More...
 
virtual int cmdReadMotorCurrentDraw (double &amps1, double &amps2)
 Read the motors ampere draw. More...
 
virtual int cmdReadMotorMaxCurrentLimit (int motor, double &maxAmps)
 Read a motor's maximum current limit. More...
 
virtual int cmdSetMotorMaxCurrentLimit (int motor, const double maxAmps)
 Set a motor's maximum current limit. More...
 
virtual int cmdReadBoardTemperature (double &temp)
 Read RoboClaw board's temperature. More...
 
virtual int cmdReadStatus (uint_t &status)
 Read RoboClaw board's status bits. More...
 
virtual int cmdReadCmdBufLengths (uint_t &len1, uint_t &len2)
 Read RoboClaw board's temperature. More...
 
virtual int cmdReadEncoderMode (byte_t &mode1, byte_t &mode2)
 Read encoder mode. More...
 
virtual int cmdSetEncoderMode (int motor, byte_t mode)
 Set a motor's encoder mode. More...
 
virtual int cmdSetEncoderMode2 (byte_t mode1, byte_t mode2)
 Set both motors' encoder mode. More...
 
virtual int cmdResetQEncoders ()
 Reset both motors' encoders. More...
 
virtual int cmdReadQEncoder (int motor, s64_t &encoder)
 Read motor's encoder. More...
 
virtual int cmdDutyDrive2 (double duty1, double duty2)
 Drive both motors at the given duty cycle. More...
 
virtual int cmdReadQSpeed (int motor, s32_t &speed)
 Read motor's speed. More...
 
virtual int cmdQDrive (int motor, s32_t speed)
 Drive a motor at the given speed. More...
 
virtual int cmdQDrive2 (s32_t speed1, s32_t speed2)
 Drive both motors at the given speeds. More...
 
virtual int cmdQDriveWithAccel (int motor, s32_t speed, u32_t accel)
 Drive a motor at the given speed and with the given acceleration. More...
 
virtual int cmdQDriveWithAccel (s32_t speed1, u32_t accel1, s32_t speed2, u32_t accel2)
 Drive both motors at the given speeds and with the given accelerations. More...
 
virtual int cmdQDriveForDist (int motor, s32_t speed, u32_t dist, bool bQueue=true)
 Drive a motor at the given speed for a given distance. More...
 
virtual int cmdQDriveForDist (s32_t speed1, u32_t dist1, s32_t speed2, u32_t dist2, bool bQueue=true)
 Drive both motors at the given speeds for a given distances. More...
 
virtual int cmdQDriveWithAccelForDist (int motor, s32_t speed, u32_t accel, u32_t dist, bool bQueue=true)
 Drive a motor at the given speed with the given acceleration for the given distance. More...
 
virtual int cmdQDriveWithAccelForDist (s32_t speed1, u32_t accel1, u32_t dist1, s32_t speed2, u32_t accel2, u32_t dist2, bool bQueue=true)
 Drive both motors at the given speeds with the given accelerations for the given distances. More...
 
virtual int cmdQDriveWithProfileToPos (int motor, s32_t speed, u32_t accel, u32_t deccel, s32_t pos, bool bQueue=true)
 Drive a motor at the given speed with the given acceleration/ decceleration profile to the given absolute position. More...
 
virtual int cmdQDriveWithProfileToPos (s32_t speed1, u32_t accel1, u32_t deccel1, s32_t pos1, s32_t speed2, u32_t accel2, u32_t deccel2, s32_t pos2, bool bQueue=true)
 Drive both motors at the given speeds with the given acceleration/decceleration profile to the given absolute position. More...
 
virtual int cmdQStop ()
 Stop both motors. More...
 
virtual int cmdSDrive (int motor, int speed)
 Drive a motor at the given speed. More...
 
virtual int cmdSDrive2 (int speed1, int speed2)
 Drive both motors at the given speeds. More...
 
virtual int cmdStop (int motor)
 Stop a motor. More...
 
virtual int cmdStopWithDecel (int motor, u32_t decel)
 Stop a motor with the given maximum decelerations. More...
 
virtual int cmdStop ()
 Stop all motors. More...
 
virtual int cmdStopWithDecel (u32_t decel)
 Stop both motors with the given maximum decelerations. More...
 
virtual int cmdEStop ()
 Emergency stop all motors. More...
 
virtual int cmdWriteSettingsToEEPROM ()
 Write all settings to EEPROM. More...
 

Protected Member Functions

virtual bool isValidMotor (int motor) const
 Test if motor index is a valid index. More...
 

Static Protected Member Functions

static int abs (int a)
 Integer absolute value. More...
 
static int cap (int a, int min, int max)
 Cap value within limits [min, max]. More...
 
static double fcap (double a, double min, double max)
 Cap FPN value within limits [min, max]. More...
 

Protected Attributes

RoboClawCommm_comm
 bound communication object
 
byte_t m_address
 assigned controller address
 
std::string m_strNameId
 controller name identifier
 
int m_nMotorDir [NumMotors]
 motor rotation direction sense
 
s64_t m_nEncPrev [NumMotors]
 encoder prevous values
 
s64_t m_nEncoder [NumMotors]
 64-bit encoder shadow values
 

Detailed Description

RoboClaw 2 motor controller class.

RoboClaw by Ion Motion Control.

Definition at line 808 of file RoboClaw.h.

Constructor & Destructor Documentation

RoboClaw::RoboClaw ( RoboClawComm comm,
const byte_t  address = AddrDft,
const std::string &  strNameId = "RoboClaw" 
)

Initialization constructor.

Parameters
commBound controller communication object.
addressMotor controller address.
strNameIdMotor controller name identifier.

Definition at line 567 of file RoboClaw.cxx.

570 {
571  if( m_comm.isOpen() )
572  {
573  cmdStop();
574  }
575 }
576 
577 bool RoboClaw::probe(byte_t address)
578 {
virtual int cmdStop()
Stop all motors.
Definition: RoboClaw.cxx:1717
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual bool probe(byte_t address)
Probe address of motor controller.
Definition: RoboClaw.cxx:588
virtual bool isOpen() const
Test if connection is open.
Definition: RoboClaw.h:545

Member Function Documentation

static int motor::roboclaw::RoboClaw::abs ( int  a)
inlinestaticprotected

Integer absolute value.

Parameters
aInteger value.
Returns
|a|

Definition at line 1683 of file RoboClaw.h.

1684  {
1685  return a>=0? a: -a;
1686  }
static int motor::roboclaw::RoboClaw::cap ( int  a,
int  min,
int  max 
)
inlinestaticprotected

Cap value within limits [min, max].

Parameters
aValue.
minMinimum.
maxMaximum.
Returns
a: min ≤ a ≤ max

Definition at line 1697 of file RoboClaw.h.

1698  {
1699  return a<min? min: a>max? max: a;
1700  }
int RoboClaw::cmdDutyDrive2 ( double  duty1,
double  duty2 
)
virtual

Drive both motors at the given duty cycle.

Motor quadrature encoders are ignored.

Command Numbers: 34

Parameters
duty1Motor1 normalized duty cycle [-1.0, 1.0]. Sign indicates direction.
duty2Motor2 normalized duty cycle [-1.0, 1.0]. Sign indicates direction.

Definition at line 1297 of file RoboClaw.cxx.

References ROBOCLAW_TRY_MOTOR.

Referenced by laelaps::LaeKinActionDutyCycle::execute(), and laelaps::LaeKinActionDutyCycle::terminate().

1313 {
1314  byte_t cmd[CmdMaxBufLen];
1315  byte_t rsp[RspMaxBufLen];
1316  size_t n = 0;
int RoboClaw::cmdEStop ( )
virtual

Emergency stop all motors.

Command Numbers: 37

Definition at line 1729 of file RoboClaw.cxx.

References motor::roboclaw::CmdWriteEEPROM.

int RoboClaw::cmdQDrive ( int  motor,
s32_t  speed 
)
virtual

Drive a motor at the given speed.

Movement is controlled using quadrature encoders.

Command Numbers: 35, 36

Parameters
motorMotor index Motor1(0) or Motor2(1).
speedMotor speed in quad pulses per second. Sign indicates direction.

Definition at line 1356 of file RoboClaw.cxx.

References motor::roboclaw::CmdDriveQ.

1361  : cmd = ", motor, speed);
1362 
1363  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1364 }
1365 
1366 // Command 37
1367 int RoboClaw::cmdQDrive2(s32_t speed1, s32_t speed2)
1368 {
1369  byte_t cmd[CmdMaxBufLen];
1370  size_t k, n = 0;
1371 
1372  speed1 *= m_nMotorDir[Motor1];
1373  speed2 *= m_nMotorDir[Motor2];
1374 
1375  cmd[n++] = m_address;
int RoboClaw::cmdQDrive2 ( s32_t  speed1,
s32_t  speed2 
)
virtual

Drive both motors at the given speeds.

Movement is controlled using quadrature encoders.

Command Numbers: 37

Parameters
speed1Motor1 speed in quad pulses per second. Sign indicates direction.
speed2Motor2 speed in quad pulses per second. Sign indicates direction.

Definition at line 1378 of file RoboClaw.cxx.

References motor::roboclaw::CmdDriveQAccelMot1, motor::roboclaw::CmdDriveQAccelMot2, and ROBOCLAW_TRY_MOTOR.

1389 {
1390  byte_t cmd[CmdMaxBufLen];
1391  size_t k, n = 0;
1392 
1394 
1395  speed *= m_nMotorDir[motor];
1396 
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
#define ROBOCLAW_TRY_MOTOR(motor)
Test for valid motor index.
Definition: RoboClaw.cxx:78
Definition: RoboClaw.h:64
int RoboClaw::cmdQDriveForDist ( int  motor,
s32_t  speed,
u32_t  dist,
bool  bQueue = true 
)
virtual

Drive a motor at the given speed for a given distance.

Movement is controlled using quadrature encoders.

This is a buffered command. Commands execute immediatly if no commands are already in the motor drive queue or if the queue paramter is false. Otherwise, the command is placed at end of the command buffer execution queue.

Command Numbers: 41, 42

Parameters
motorMotor index Motor1(0) or Motor2(1).
speedMotor speed in quad pulses per second. Sign indicates direction.
distDistance from current position (quad pulses).
bQueueDo [not] queue the command. If false, the motor drive queue is flushed and any existing command is preempted by this command.

Definition at line 1449 of file RoboClaw.cxx.

1456  : ParamCmdBufPreempt;
1457 
1458  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1459 }
1460 
1461 // Command 43
1462 int RoboClaw::cmdQDriveForDist(s32_t speed1, u32_t dist1,
1463  s32_t speed2, u32_t dist2,
1464  bool bQueue)
1465 {
1466  byte_t cmd[CmdMaxBufLen];
1467  size_t k, n = 0;
1468 
1469  speed1 *= m_nMotorDir[Motor1];
1470  speed2 *= m_nMotorDir[Motor2];
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdQDriveForDist(int motor, s32_t speed, u32_t dist, bool bQueue=true)
Drive a motor at the given speed for a given distance.
Definition: RoboClaw.cxx:1449
int RoboClaw::cmdQDriveForDist ( s32_t  speed1,
u32_t  dist1,
s32_t  speed2,
u32_t  dist2,
bool  bQueue = true 
)
virtual

Drive both motors at the given speeds for a given distances.

Movement is controlled using quadrature encoders.

This is a buffered command. Commands execute immediatly if no commands are already in the motor drive queue or if the queue paramter is false. Otherwise, the command is placed at end of the command buffer execution queue.

Command Numbers: 43

Parameters
speed1Motor1 speed in quad pulses per second. Sign indicates direction.
dist1Motor1 distance from current position (quad pulses).
speed2Motor2 speed in quad pulses per second. Sign indicates direction.
dist2Motor2 distance from current position (quad pulses).
bQueueDo [not] queue the command. If false, the motor drive queue is flushed and any existing command is preempted by this command.

Definition at line 1473 of file RoboClaw.cxx.

References motor::roboclaw::CmdBufDriveQDist, and ROBOCLAW_TRY_MOTOR.

1487  : ParamCmdBufPreempt;
1488 
1489  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1490 }
1491 
1492 // Command 44, 45
1494  s32_t speed,
1495  u32_t accel,
1496  u32_t dist,
1497  bool bQueue)
1498 {
1499  byte_t cmd[CmdMaxBufLen];
1500  size_t k, n = 0;
1501 
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdQDriveWithAccelForDist(int motor, s32_t speed, u32_t accel, u32_t dist, bool bQueue=true)
Drive a motor at the given speed with the given acceleration for the given distance.
Definition: RoboClaw.cxx:1504
Definition: RoboClaw.h:64
int RoboClaw::cmdQDriveWithAccel ( int  motor,
s32_t  speed,
u32_t  accel 
)
virtual

Drive a motor at the given speed and with the given acceleration.

Movement is controlled using quadrature encoders.

Command Numbers: 38, 39

Parameters
motorMotor index Motor1(0) or Motor2(1).
speedMotor speed in quad pulses per second. Sign indicates direction.
accelAcceleration (qpps/s).

Definition at line 1399 of file RoboClaw.cxx.

References motor::roboclaw::CmdDriveQAccel2.

Referenced by laelaps::LaeKinActionVelocity::execute(), and laelaps::LaeKinActionTwist::execute().

1412 {
1413  byte_t cmd[CmdMaxBufLen];
1414  size_t k, n = 0;
1415 
1416  speed1 *= m_nMotorDir[Motor1];
1417  speed2 *= m_nMotorDir[Motor2];
1418 
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
int RoboClaw::cmdQDriveWithAccel ( s32_t  speed1,
u32_t  accel1,
s32_t  speed2,
u32_t  accel2 
)
virtual

Drive both motors at the given speeds and with the given accelerations.

Movement is controlled using quadrature encoders.

Command Numbers: 50

Parameters
speed1Motor1 speed in quad pulses per second. Sign indicates direction.
accel1Motor1 acceleration (qpps/s).
speed2Motor2 speed in quad pulses per second. Sign indicates direction.
accel2Motor2 acceleration (qpps/s).

Definition at line 1421 of file RoboClaw.cxx.

References motor::roboclaw::CmdBufDriveQDistMot1, motor::roboclaw::CmdBufDriveQDistMot2, and ROBOCLAW_TRY_MOTOR.

1439 {
1440  byte_t cmd[CmdMaxBufLen];
1441  size_t k, n = 0;
1442 
1444 
1445  speed *= m_nMotorDir[motor];
1446 
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
#define ROBOCLAW_TRY_MOTOR(motor)
Test for valid motor index.
Definition: RoboClaw.cxx:78
Definition: RoboClaw.h:64
int RoboClaw::cmdQDriveWithAccelForDist ( int  motor,
s32_t  speed,
u32_t  accel,
u32_t  dist,
bool  bQueue = true 
)
virtual

Drive a motor at the given speed with the given acceleration for the given distance.

Movement is controlled using quadrature encoders.

This is a buffered command. Commands execute immediatly if no commands are already in the motor drive queue or if the queue paramter is false. Otherwise, the command is placed at end of the command buffer execution queue.

Command Numbers: 44, 45

Parameters
motorMotor index Motor1(0) or Motor2(1).
speedSpeed in quad pulses per second. Sign indicates direction.
accelAcceleration (qpps/s).
distDistance from current position (quad pulses).
bQueueDo [not] queue the command. If false, the motor drive queue is flushed and any existing command is preempted by this command.

Definition at line 1504 of file RoboClaw.cxx.

References motor::roboclaw::CmdBufDriveQAccelDistMot1, and motor::roboclaw::CmdBufDriveQAccelDistMot2.

1507  :
1509 
1510  k = m_comm.pack32((uint_t)accel, cmd+n);
1511  n += k;
1512 
1513  k = m_comm.pack32((int)speed, cmd+n);
1514  n += k;
1515 
1516  k = m_comm.pack32((uint_t)dist, cmd+n);
1517  n += k;
1518 
1519  cmd[n++] = bQueue? ParamCmdBufQueue: ParamCmdBufPreempt;
1520 
1521  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1522 }
1523 
1524 // Command 51
1525 int RoboClaw::cmdQDriveWithAccelForDist(s32_t speed1,
1526  u32_t accel1,
1527  u32_t dist1,
1528  s32_t speed2,
1529  u32_t accel2,
1530  u32_t dist2,
1531  bool bQueue)
1532 {
1533  byte_t cmd[CmdMaxBufLen];
buffered drive motor 2 to dist at qpps with accel.
Definition: RoboClaw.h:171
int pack32(uint_t val, byte_t buf[])
Pack 32-bit unsigned value into buffer.
Definition: RoboClaw.cxx:486
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdQDriveWithAccelForDist(int motor, s32_t speed, u32_t accel, u32_t dist, bool bQueue=true)
Drive a motor at the given speed with the given acceleration for the given distance.
Definition: RoboClaw.cxx:1504
int RoboClaw::cmdQDriveWithAccelForDist ( s32_t  speed1,
u32_t  accel1,
u32_t  dist1,
s32_t  speed2,
u32_t  accel2,
u32_t  dist2,
bool  bQueue = true 
)
virtual

Drive both motors at the given speeds with the given accelerations for the given distances.

Movement is controlled using quadrature encoders.

This is a buffered command. Commands execute immediatly if no commands are already in the motor drive queue or if the queue paramter is false. Otherwise, the command is placed at end of the command buffer execution queue.

Command Numbers: 51

Parameters
speed1Motor1 peed in quad pulses per second. Sign indicates direction.
accel1Motor1 acceleration (qpps/s).
dist1Motor1 distance from current position (quad pulses).
speed2Motor2 peed in quad pulses per second. Sign indicates direction.
accel2Motor2 acceleration (qpps/s).
dist2Motor2 distance from current position (quad pulses).
bQueueDo [not] queue the command. If false, the motor drive queue is flushed and any existing command is preempted by this command.

Definition at line 1536 of file RoboClaw.cxx.

References ROBOCLAW_TRY_MOTOR.

1560  : ParamCmdBufPreempt;
1561 
1562  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1563 }
1564 
1565 // Command 65, 66
1567  s32_t speed,
1568  u32_t accel,
1569  u32_t deccel,
1570  s32_t pos,
1571  bool bQueue)
1572 {
1573  byte_t cmd[CmdMaxBufLen];
1574  size_t k, n = 0;
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdQDriveWithProfileToPos(int motor, s32_t speed, u32_t accel, u32_t deccel, s32_t pos, bool bQueue=true)
Drive a motor at the given speed with the given acceleration/ decceleration profile to the given abso...
Definition: RoboClaw.cxx:1577
Definition: RoboClaw.h:64
int RoboClaw::cmdQDriveWithProfileToPos ( int  motor,
s32_t  speed,
u32_t  accel,
u32_t  deccel,
s32_t  pos,
bool  bQueue = true 
)
virtual

Drive a motor at the given speed with the given acceleration/ decceleration profile to the given absolute position.

Movement is controlled using quadrature encoders.

This is a buffered command. Commands execute immediatly if no commands are already in the motor drive queue or if the queue paramter is false. Otherwise, the command is placed at end of the command buffer execution queue.

Command Numbers: 65, 66

Parameters
motorMotor index Motor1(0) or Motor2(1).
speedSpeed in quad pulses per second. Sign indicates direction.
accelAcceleration (qpps/s).
deccelDecceleration (qpps/s).
posGoal absolute position (quad pulses).
bQueueDo [not] queue the command. If false, the motor drive queue is flushed and any existing command is preempted by this command.

Definition at line 1577 of file RoboClaw.cxx.

References motor::roboclaw::CmdBufDriveQProfPosMot1, and motor::roboclaw::CmdBufDriveQProfPosMot2.

1581  :
1583 
1584  k = m_comm.pack32((uint_t)accel, cmd+n);
1585  n += k;
1586 
1587  k = m_comm.pack32((int)speed, cmd+n);
1588  n += k;
1589 
1590  k = m_comm.pack32((uint_t)deccel, cmd+n);
1591  n += k;
1592 
1593  k = m_comm.pack32((int)pos, cmd+n);
1594  n += k;
1595 
1596  cmd[n++] = bQueue? ParamCmdBufQueue: ParamCmdBufPreempt;
1597 
1598  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1599 }
1600 
1601 // Command 67
1602 int RoboClaw::cmdQDriveWithProfileToPos(s32_t speed1,
1603  u32_t accel1,
1604  u32_t deccel1,
1605  s32_t pos1,
1606  s32_t speed2,
1607  u32_t accel2,
1608  u32_t deccel2,
1609  s32_t pos2,
1610  bool bQueue)
int pack32(uint_t val, byte_t buf[])
Pack 32-bit unsigned value into buffer.
Definition: RoboClaw.cxx:486
drive motor 2 with signed qpps, accel, deccel and position
Definition: RoboClaw.h:198
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdQDriveWithProfileToPos(int motor, s32_t speed, u32_t accel, u32_t deccel, s32_t pos, bool bQueue=true)
Drive a motor at the given speed with the given acceleration/ decceleration profile to the given abso...
Definition: RoboClaw.cxx:1577
int RoboClaw::cmdQDriveWithProfileToPos ( s32_t  speed1,
u32_t  accel1,
u32_t  deccel1,
s32_t  pos1,
s32_t  speed2,
u32_t  accel2,
u32_t  deccel2,
s32_t  pos2,
bool  bQueue = true 
)
virtual

Drive both motors at the given speeds with the given acceleration/decceleration profile to the given absolute position.

Movement is controlled using quadrature encoders.

This is a buffered command. Commands execute immediatly if no commands are already in the motor drive queue or if the queue paramter is false. Otherwise, the command is placed at end of the command buffer execution queue.

Command Numbers: 67

Parameters
speed1Motor1 speed in quad pulses per second. Sign indicates direction.
accel1Motor1 acceleration (qpps/s).
deccel1Motor1 decceleration (qpps/s).
pos1Motor1 goal absolute position (quad pulses).
speed2Motor2 speed in quad pulses per second. Sign indicates direction.
accel2Motor2 acceleration (qpps/s).
deccel2Motor2 decceleration (qpps/s).
pos2Motor2 goal absolute position (quad pulses).
bQueueDo [not] queue the command. If false, the motor drive queue is flushed and any existing command is preempted by this command.

Definition at line 1613 of file RoboClaw.cxx.

References laelaps::cap(), motor::roboclaw::CmdBufDriveQProfPos, and ROBOCLAW_TRY_MOTOR.

1645  : ParamCmdBufPreempt;
1646 
1647  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1648 }
1649 
1650 // Command 0, 1, 4, 5
1651 int RoboClaw::cmdSDrive(int motor, int speed)
1652 {
1653  byte_t cmd[CmdMaxBufLen];
1654  size_t n = 0;
1655 
1656  ROBOCLAW_TRY_MOTOR(motor);
1657 
1658  speed = RoboClaw::cap(speed, MotorSpeedMaxBackward, MotorSpeedMaxForward);
1659  speed *= m_nMotorDir[motor];
virtual int cmdSDrive(int motor, int speed)
Drive a motor at the given speed.
Definition: RoboClaw.cxx:1662
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
static int cap(int a, int min, int max)
Cap value within limits [min, max].
Definition: RoboClaw.h:1697
#define ROBOCLAW_TRY_MOTOR(motor)
Test for valid motor index.
Definition: RoboClaw.cxx:78
Definition: RoboClaw.h:64
virtual int motor::roboclaw::RoboClaw::cmdQStop ( )
inlinevirtual

Stop both motors.

Movement is controlled using quadrature encoders, with 0 being stop.

Command Numbers: 37

Definition at line 1543 of file RoboClaw.h.

1544  {
1545  return cmdQDrive2(0, 0);
1546  }
virtual int cmdQDrive2(s32_t speed1, s32_t speed2)
Drive both motors at the given speeds.
Definition: RoboClaw.cxx:1378
int RoboClaw::cmdReadBoardTemperature ( double &  temp)
virtual

Read RoboClaw board's temperature.

Command Numbers: 82

Parameters
[out]tempBoard temperature (C)

Definition at line 1034 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadStatus.

1035  {
1036  m_comm.unpack16(rsp, val);
1037  temp = (double)val * ParamTempScale;
1038  }
1039 
1040  return rc;
1041 }
1042 
1043 // Command 90
1044 int RoboClaw::cmdReadStatus(uint_t &status)
1045 {
1046  byte_t cmd[CmdMaxBufLen];
1047  byte_t rsp[RspMaxBufLen];
1048  size_t n = 0;
1049  uint_t val;
1050  int rc;
1051 
1052  cmd[n++] = m_address;
int unpack16(byte_t buf[], uint_t &val)
Unpack 16-bit unsigned value from buffer.
Definition: RoboClaw.cxx:470
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
virtual int cmdReadStatus(uint_t &status)
Read RoboClaw board&#39;s status bits.
Definition: RoboClaw.cxx:1055
int RoboClaw::cmdReadCmdBufLengths ( uint_t &  len1,
uint_t &  len2 
)
virtual

Read RoboClaw board's temperature.

Command Numbers: 47

Parameters
[out]len1Motor1 command buffer length.
[out]len2Motor2 command buffer length.

Definition at line 1075 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadEncoderMode.

1076  {
1077  len1 = (uint_t)rsp[0];
1078  len2 = (uint_t)rsp[1];
1079  }
1080 
1081  return rc;
1082 }
1083 
1084 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1085 // Encoder Commands
1086 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1087 
1088 // Command 91
1089 int RoboClaw::cmdReadEncoderMode(byte_t &mode1, byte_t &mode2)
1090 {
1091  byte_t cmd[CmdMaxBufLen];
1092  byte_t rsp[RspMaxBufLen];
1093  size_t n = 0;
virtual int cmdReadEncoderMode(byte_t &mode1, byte_t &mode2)
Read encoder mode.
Definition: RoboClaw.cxx:1100
int RoboClaw::cmdReadEncoderMode ( byte_t &  mode1,
byte_t &  mode2 
)
virtual

Read encoder mode.

Command Numbers: 91

Parameters
[out]mode1Motor1 encoder mode.
[out]mode2Motor2 encoder mode.

Definition at line 1100 of file RoboClaw.cxx.

References motor::roboclaw::CmdSetEncoderModeMot1, motor::roboclaw::CmdSetEncoderModeMot2, and ROBOCLAW_TRY_MOTOR.

1101  {
1102  mode1 = rsp[0];
1103  mode2 = rsp[1];
1104  //LOGDIAG3("Motor controller 0x%02x: mode1=0x%02x, mode2=0x%02x.",
1105  // m_address, mode1, mode2);
1106  }
1107 
1108  return rc;
1109 }
1110 
1111 // Command 92, 93
1112 int RoboClaw::cmdSetEncoderMode(int motor, byte_t mode)
1113 {
1114  byte_t cmd[CmdMaxBufLen];
1115  byte_t mask = ParamEncModeRCAnalogBit | ParamEncModeQuadAbsBit;
1116  size_t n = 0;
1117 
1118  ROBOCLAW_TRY_MOTOR(motor);
1119 
1120  cmd[n++] = m_address;
virtual int cmdSetEncoderMode(int motor, byte_t mode)
Set a motor&#39;s encoder mode.
Definition: RoboClaw.cxx:1123
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
#define ROBOCLAW_TRY_MOTOR(motor)
Test for valid motor index.
Definition: RoboClaw.cxx:78
Definition: RoboClaw.h:64
int RoboClaw::cmdReadFwVersion ( std::string &  strFwVer)
virtual

Read the RoboClaw's firmware version.

Command Numbers: 21

Parameters
[out]strFwVerRead version string.

Definition at line 608 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadMainBattVolt.

610  {
611  return RC_ERROR;
612  }
613 
614  n = m_comm.recvDataRsp(rsp, ParamVerLen);
615 
616  if( n > ParamVerLenMin )
617  {
618  //
619  // Validate CRC
620  //
621  uCrcCmd = m_comm.getLastCmdCrc();
622  uCrcRsp = m_comm.getLastRspCrc();
623  uCrcCalc = m_comm.crc16(uCrcCmd, rsp, n-2);
624 
625  if( uCrcRsp != uCrcCalc )
626  {
627  LOGERROR("Motor controller 0x%02x: "
628  "Command %u response CRC-16 mismatch: "
629  "Expected 0x%04x, received 0x%04x.",
630  cmd[FieldPosAddr], cmd[FieldPosCmd],
631  uCrcCalc, uCrcRsp);
632  return RC_ERROR;
633  }
634 
635  rsp[n-ParamVerLenMin] = 0; // take off trailing junk
636  strFwVer = (char *)rsp; // convert to string
637 
638  LOGDIAG3("%s.", strFwVer.c_str());
639 
640  return OK;
641  }
642  else
643  {
644  LOGERROR("Motor controller 0x%02x: "
645  "Failed to receive firmware version.",
646  m_address);
647  return RC_ERROR;
648  }
649 }
650 
651 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
652 // Main Battery Voltage Commands
653 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
654 
655 // Command 24
656 int RoboClaw::cmdReadMainBattVoltage(double &volts)
657 {
658  byte_t cmd[CmdMaxBufLen];
659  byte_t rsp[RspMaxBufLen];
660  size_t n = 0;
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
virtual uint_t crc16(uint_t crc, byte_t buf[], size_t lenBuf)
Calculate 16-bit CRC over buffer.
Definition: RoboClaw.cxx:538
virtual int recvDataRsp(byte_t rsp[], size_t lenRsp)
Receive data response over serial connection from motor controller.
Definition: RoboClaw.cxx:411
virtual int cmdReadMainBattVoltage(double &volts)
Read the RoboClaw&#39;s main battery input voltage.
Definition: RoboClaw.cxx:667
uint_t getLastCmdCrc()
Get last sent command&#39;s calculated 16-bit CRC.
Definition: RoboClaw.h:565
uint_t getLastRspCrc()
Get last received response&#39;s appended 16-bit CRC.
Definition: RoboClaw.h:575
int RoboClaw::cmdReadLogicCutoffs ( double &  min,
double &  max 
)
virtual

Read the RoboClaw's optional logic dedicated battery minimum and maximum voltage cutoff settings. The battery is connected to the LB-/LB+ terminals.

Command Numbers: 60

Parameters
[out]minMinimum voltage (V).
[out]maxMaximum voltage (V).

Definition at line 900 of file RoboClaw.cxx.

References laelaps::fcap(), and ROBOCLAW_DBG.

901  {
902  n = m_comm.unpack16(rsp, valMin);
903  n += m_comm.unpack16(rsp+n, valMax);
904 
905  ROBOCLAW_DBG(cmd[FieldPosAddr], cmd[FieldPosCmd],
906  "Logic Cutoffs [%u, %u]\n", valMin, valMax);
907 
908  min = (double)valMin * ParamVoltScale;
909  max = (double)valMax * ParamVoltScale;
910  }
911 
912  return rc;
913 }
914 
915 // Command 58
916 int RoboClaw::cmdSetLogicCutoffs(const double min, const double max)
917 {
918  byte_t cmd[CmdMaxBufLen];
919  size_t k, n = 0;
920  double fMin, fMax;
921  uint_t valMin, valMax;
922  int rc;
923 
924  fMin = min / ParamVoltScale;
int unpack16(byte_t buf[], uint_t &val)
Unpack 16-bit unsigned value from buffer.
Definition: RoboClaw.cxx:470
virtual int cmdSetLogicCutoffs(const double min, const double max)
Set the RoboClaw&#39;s optional logic dedicated battery minimum and maximum voltage cutoff settings...
Definition: RoboClaw.cxx:927
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
#define ROBOCLAW_DBG(addr, cmdNum, fmt,...)
Debug print disabled.
Definition: RoboClaw.cxx:155
int RoboClaw::cmdReadLogicVoltage ( double &  volts)
virtual

Read the RoboClaw's LB-/LB+ terminals input voltage powered by and optional logic dedicated battery.

Command Numbers: 25

Parameters
[out]voltsVoltage (V).

Definition at line 873 of file RoboClaw.cxx.

874  {
875  m_comm.unpack16(rsp, val);
876  volts = (double)val * ParamVoltScale;
877  }
878 
879  return rc;
880 }
881 
882 void RoboClaw::getLogicCutoffRange(double &minmin, double &maxmax) const
883 {
884  minmin = ParamVoltLogicMin;
885  maxmax = ParamVoltMax;
886 }
887 
888 // Command 60
889 int RoboClaw::cmdReadLogicCutoffs(double &min, double &max)
890 {
891  byte_t cmd[CmdMaxBufLen];
int unpack16(byte_t buf[], uint_t &val)
Unpack 16-bit unsigned value from buffer.
Definition: RoboClaw.cxx:470
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
void getLogicCutoffRange(double &minmin, double &maxmax) const
Get the RoboClaw&#39;s logic minimum and maximum voltage cutoff settable range.
Definition: RoboClaw.cxx:893
virtual int cmdReadLogicCutoffs(double &min, double &max)
Read the RoboClaw&#39;s optional logic dedicated battery minimum and maximum voltage cutoff settings...
Definition: RoboClaw.cxx:900
int RoboClaw::cmdReadMainBattCutoffs ( double &  min,
double &  max 
)
virtual

Read the RoboClaw's main battery minimum and maximum voltage cutoff settings.

Command Numbers: 59

Parameters
[out]minMinimum voltage (V).
[out]maxMaximum voltage (V).

Definition at line 694 of file RoboClaw.cxx.

References laelaps::fcap(), and ROBOCLAW_DBG.

695  {
696  n = m_comm.unpack16(rsp, valMin);
697  n += m_comm.unpack16(rsp+n, valMax);
698 
699  ROBOCLAW_DBG(cmd[FieldPosAddr], cmd[FieldPosCmd],
700  "MainBatt Cutoffs [%u, %u]\n", valMin, valMax);
701 
702  min = (double)valMin * ParamVoltScale;
703  max = (double)valMax * ParamVoltScale;
704  }
705 
706  return rc;
707 }
708 
709 // Command 57
710 int RoboClaw::cmdSetMainBattCutoffs(const double min, const double max)
711 {
712  byte_t cmd[CmdMaxBufLen];
713  size_t k, n = 0;
714  double fMin, fMax;
715  uint_t valMin, valMax;
716  int rc;
717 
718  fMin = min / ParamVoltScale;
int unpack16(byte_t buf[], uint_t &val)
Unpack 16-bit unsigned value from buffer.
Definition: RoboClaw.cxx:470
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdSetMainBattCutoffs(const double min, const double max)
Set the RoboClaw&#39;s main battery minimum and maximum voltage cutoff settings.
Definition: RoboClaw.cxx:721
#define ROBOCLAW_DBG(addr, cmdNum, fmt,...)
Debug print disabled.
Definition: RoboClaw.cxx:155
int RoboClaw::cmdReadMainBattVoltage ( double &  volts)
virtual

Read the RoboClaw's main battery input voltage.

Command Numbers: 24

Parameters
[out]voltsVoltage (V).

Definition at line 667 of file RoboClaw.cxx.

668  {
669  m_comm.unpack16(rsp, val);
670  volts = (double)val * ParamVoltScale;
671  }
672 
673  return rc;
674 }
675 
676 void RoboClaw::getMainBattCutoffRange(double &minmin, double &maxmax) const
677 {
678  minmin = ParamVoltMainMin;
679  maxmax = ParamVoltMax;
680 }
681 
682 // Command 59
683 int RoboClaw::cmdReadMainBattCutoffs(double &min, double &max)
684 {
685  byte_t cmd[CmdMaxBufLen];
int unpack16(byte_t buf[], uint_t &val)
Unpack 16-bit unsigned value from buffer.
Definition: RoboClaw.cxx:470
virtual int cmdReadMainBattCutoffs(double &min, double &max)
Read the RoboClaw&#39;s main battery minimum and maximum voltage cutoff settings.
Definition: RoboClaw.cxx:694
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
void getMainBattCutoffRange(double &minmin, double &maxmax) const
Get the RoboClaw&#39;s main battery minimum and maximum voltage cutoff settable range.
Definition: RoboClaw.cxx:687
int RoboClaw::cmdReadMotorCurrentDraw ( double &  amps1,
double &  amps2 
)
virtual

Read the motors ampere draw.

Command Numbers: 49

Parameters
[out]amps1Motor1 current draw (amperes)
[out]amps2Motor2 current draw (amperes)

Definition at line 761 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadMaxCurrentMot1, and motor::roboclaw::CmdReadMaxCurrentMot2.

762  {
763  n = 0;
764 
765  k = m_comm.unpack16(rsp, val1);
766  n += k;
767 
768  k = m_comm.unpack16(rsp+n, val2);
769  n += k;
770 
771  amps1 = (double)val1 * ParamAmpScale;
772  amps2 = (double)val2 * ParamAmpScale;
773  }
774 
775  return rc;
776 }
777 
778 // Command 135, 136
779 //
780 // Note: RoboClaw User Manual v5 error. Each value is 32 bits.
781 //
782 int RoboClaw::cmdReadMotorMaxCurrentLimit(int motor, double &maxAmps)
783 {
784  byte_t cmd[CmdMaxBufLen];
785  byte_t rsp[RspMaxBufLen];
786  size_t k, n = 0;
787  uint_t val1, val2;
int unpack16(byte_t buf[], uint_t &val)
Unpack 16-bit unsigned value from buffer.
Definition: RoboClaw.cxx:470
virtual int cmdReadMotorMaxCurrentLimit(int motor, double &maxAmps)
Read a motor&#39;s maximum current limit.
Definition: RoboClaw.cxx:793
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
Definition: RoboClaw.h:64
int RoboClaw::cmdReadMotorMaxCurrentLimit ( int  motor,
double &  maxAmps 
)
virtual

Read a motor's maximum current limit.

Command Numbers: 136, 137

Parameters
motorMotor index Motor1(0) or Motor2(1).
[out]maxAmpsMotor maximum current limit (amperes)

Definition at line 793 of file RoboClaw.cxx.

799  {
800  n = 0;
801 
802  k = m_comm.unpack32(rsp, val1);
803  n += k;
804 
805  k = m_comm.unpack32(rsp+n, val2);
806  n += k;
807 
808  maxAmps = (double)val1 * ParamAmpScale;
809  minAmps = (double)val2 * ParamAmpScale;
810  }
811 
812  m_comm.enableDbg(false);
813 
814  return rc;
815 }
816 
817 // Command 133, 134
818 //
819 // Note: RoboClaw User Manual v5 error. Each value is 32 bits.
820 //
821 int RoboClaw::cmdSetMotorMaxCurrentLimit(int motor, const double maxAmps)
822 {
823  byte_t cmd[CmdMaxBufLen];
824  byte_t rsp[RspMaxBufLen];
825  size_t k, n = 0;
826  double fMax;
int unpack32(byte_t buf[], uint_t &val)
Unpack 32-bit unsigned value from buffer.
Definition: RoboClaw.cxx:495
virtual int cmdSetMotorMaxCurrentLimit(int motor, const double maxAmps)
Set a motor&#39;s maximum current limit.
Definition: RoboClaw.cxx:832
virtual void enableDbg(bool bEnDis)
Test if connection is open.
Definition: RoboClaw.h:555
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
Definition: RoboClaw.h:64
int RoboClaw::cmdReadQEncoder ( int  motor,
s64_t &  encoder 
)
virtual

Read motor's encoder.

Command Numbers: 16, 17

Parameters
motorMotor index Motor1(0) or Motor2(1).
[out]encoderUnsigned encoder value (quad pulses).
[out]statusStatus bits indicating sign, and over/under flow.

Definition at line 1174 of file RoboClaw.cxx.

References motor::roboclaw::CmdDriveDuty, motor::roboclaw::CmdReadEncoderMot1, and motor::roboclaw::CmdReadEncoderMot2.

1181 
1182  if( (rc = m_comm.execCmdWithDataRsp(cmd, n, rsp, 7)) == OK )
1183  {
1184  ROBOCLAW_DBG_MSG(cmd[FieldPosAddr], cmd[FieldPosCmd], rsp, 7,
1185  "cmdReadQEncoder(motor=%d): rsp = ", motor);
1186 
1187  //
1188  // Get 32-bit unsigned encoder value plus its associated status.
1189  //
1190  // Note: This 2-tuple should be atomically kept insync by the firmware but
1191  // this is not always the case. During a sharp velocity change
1192  // (e.g. stopping) the velocity pid will rightly try to back drive.
1193  // The status byte will indicate the _desired_ direction, not the
1194  // actual.
1195  //
1196  n = m_comm.unpack32(rsp, enc32);
1197  status = rsp[n];
1198 
1199  enc64 = (s64_t)enc32;
1200 
1201  //
1202  // Debug left_front encoder to reverse engineer and test encoder algorithm.
1203  //
1204  //if( m_address == 0x80 && motor == Motor1 && m_nEncPrev[motor] != enc64 )
1205  //{
1206  // fprintf(stderr, "DBG %lld 0x%02x\n", enc64, status);
1207  //}
1208 
1209  //
1210  // Track underflow/overflow for now. Not too sure if any action or special
1211  // calculations are needed.
1212  //
1213  // Note: Condition is cleared after reading.
1214  //
1215  if( status & ParamEncStatusUnderFlow )
1216  {
1217  LOGDIAG2("Motor controller 0x%02x: Motor %d: Encoder underflow: "
1218  "Encoder32=%u.",
1219  m_address, motor, enc32);
1220  }
1221  if( status & ParamEncStatusOverFlow )
1222  {
1223  LOGDIAG2("Motor controller 0x%02x: Motor %d: Encoder overflow: "
1224  "Encoder32=%u",
1225  m_address, motor, enc32);
1226  }
1227 
1228  //
1229  // Moving backwards. There are two cases:
1230  // Case 1: no wrap: example: previous 1500, current: 1000
1231  // Case 2: wrap: example: previous 15, current: 4294967200
1232  //
1233  if( status & ParamEncStatusDirBackward )
1234  {
1235  if( enc64 <= m_nEncPrev[motor] ) // no wrap
1236  {
1237  delta = enc64 - m_nEncPrev[motor];
1238  }
1239  else // wrap
1240  {
1241  delta = enc64 - ParamEncQuadMax - m_nEncPrev[motor];
1242  if( iabs(delta) > MaxEncDelta ) // not really backwards
1243  {
1244  delta = enc64 - m_nEncPrev[motor];
1245  }
1246  }
1247  }
1248 
1249  //
1250  // Moving forwards. There are two cases:
1251  // Case 1: no wrap: example: previous 1000, current: 1500
1252  // Case 2: wrap: example: previous 4294967200, current: 15
1253  //
1254  else
1255  {
1256  if( enc64 >= m_nEncPrev[motor] ) // no wrap
1257  {
1258  delta = enc64 - m_nEncPrev[motor];
1259  }
1260  else // wrap
1261  {
1262  delta = enc64 + ParamEncQuadMax - m_nEncPrev[motor];
1263  if( iabs(delta) > MaxEncDelta ) // not really forwards
1264  {
1265  delta = enc64 - m_nEncPrev[motor];
1266  }
1267  }
1268  }
1269 
1270  //
1271  // Update accumulated value and save current as new previous.
1272  //
1273  m_nEncoder[motor] += (m_nMotorDir[motor] * delta);
1274  m_nEncPrev[motor] = enc64;
1275  encoder = m_nEncoder[motor];
1276  }
1277 
1278  return rc;
1279 }
1280 
1281 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1282 // Duty Cycle Commands
1283 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1284 
1285 // Command 34
1286 int RoboClaw::cmdDutyDrive2(double duty1, double duty2)
1287 {
1288  byte_t cmd[CmdMaxBufLen];
1289  int speed1, speed2;
1290  size_t k, n = 0;
#define ROBOCLAW_DBG_MSG(addr, cmdNum, buf, len, fmt,...)
Debug print message disabled.
Definition: RoboClaw.cxx:160
int unpack32(byte_t buf[], uint_t &val)
Unpack 32-bit unsigned value from buffer.
Definition: RoboClaw.cxx:495
s64_t m_nEncPrev[NumMotors]
encoder prevous values
Definition: RoboClaw.h:1661
s64_t m_nEncoder[NumMotors]
64-bit encoder shadow values
Definition: RoboClaw.h:1662
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
virtual int cmdDutyDrive2(double duty1, double duty2)
Drive both motors at the given duty cycle.
Definition: RoboClaw.cxx:1297
virtual int execCmdWithDataRsp(byte_t cmd[], size_t lenCmd, byte_t rsp[], size_t lenRsp, MsgFmt fmtCmd=MsgWithNoCrc, MsgFmt fmtRsp=MsgWithCrc)
Execute a command with an data response.
Definition: RoboClaw.cxx:325
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
s64_t iabs(s64_t a)
Integer absolute value.
Definition: RoboClaw.cxx:176
Definition: RoboClaw.h:64
read motor 2 encoder
Definition: RoboClaw.h:142
int RoboClaw::cmdReadQSpeed ( int  motor,
s32_t &  speed 
)
virtual

Read motor's speed.

Command Numbers: 18, 19

Parameters
motorMotor index Motor1(0) or Motor2(1).
[out]speedSigned speed value (qpps).

Definition at line 1323 of file RoboClaw.cxx.

References motor::roboclaw::CmdDriveQMot1, motor::roboclaw::CmdDriveQMot2, motor::roboclaw::CmdReadSpeedMot1, motor::roboclaw::CmdReadSpeedMot2, ROBOCLAW_DBG_MSG, and ROBOCLAW_TRY_MOTOR.

1324  : CmdReadSpeedMot2;
1325 
1326  if( (rc = m_comm.execCmdWithDataRsp(cmd, n, rsp, 7)) == OK )
1327  {
1328  ROBOCLAW_DBG_MSG(cmd[FieldPosAddr], cmd[FieldPosCmd], rsp, 7,
1329  "cmdReadQSpeed(motor=%d): rsp = ", motor);
1330 
1331  n = m_comm.unpack32(rsp, val);
1332  status = rsp[n];
1333  speed = (s32_t)val;
1334 
1335  if( status & ParamEncStatusDirBackward )
1336  {
1337  speed = -speed;
1338  }
1339  }
1340 
1341  return rc;
1342 }
1343 
1344 // Command 35, 36
1345 int RoboClaw::cmdQDrive(int motor, s32_t speed)
1346 {
1347  byte_t cmd[CmdMaxBufLen];
1348  size_t k, n = 0;
1349 
1350  ROBOCLAW_TRY_MOTOR(motor);
1351 
1352  speed *= m_nMotorDir[motor];
1353 
#define ROBOCLAW_DBG_MSG(addr, cmdNum, buf, len, fmt,...)
Debug print message disabled.
Definition: RoboClaw.cxx:160
int unpack32(byte_t buf[], uint_t &val)
Unpack 32-bit unsigned value from buffer.
Definition: RoboClaw.cxx:495
virtual int cmdQDrive(int motor, s32_t speed)
Drive a motor at the given speed.
Definition: RoboClaw.cxx:1356
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
virtual int execCmdWithDataRsp(byte_t cmd[], size_t lenCmd, byte_t rsp[], size_t lenRsp, MsgFmt fmtCmd=MsgWithNoCrc, MsgFmt fmtRsp=MsgWithCrc)
Execute a command with an data response.
Definition: RoboClaw.cxx:325
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
#define ROBOCLAW_TRY_MOTOR(motor)
Test for valid motor index.
Definition: RoboClaw.cxx:78
read motor 2 speed (qpps)
Definition: RoboClaw.h:144
Definition: RoboClaw.h:64
int RoboClaw::cmdReadStatus ( uint_t &  status)
virtual

Read RoboClaw board's status bits.

Command Numbers: 90

Parameters
[out]statusBoard status bits.

Definition at line 1055 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadBufLen.

1056  {
1057  m_comm.unpack16(rsp, status);
1058  }
1059 
1060  return rc;
1061 }
1062 
1063 // Command 47
1064 int RoboClaw::cmdReadCmdBufLengths(uint_t &len1, uint_t &len2)
1065 {
1066  byte_t cmd[CmdMaxBufLen];
1067  byte_t rsp[RspMaxBufLen];
1068  size_t n = 0;
1069  uint_t val;
1070  int rc;
1071 
1072  cmd[n++] = m_address;
int unpack16(byte_t buf[], uint_t &val)
Unpack 16-bit unsigned value from buffer.
Definition: RoboClaw.cxx:470
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
virtual int cmdReadCmdBufLengths(uint_t &len1, uint_t &len2)
Read RoboClaw board&#39;s temperature.
Definition: RoboClaw.cxx:1075
int RoboClaw::cmdReadVelocityPidConst ( int  motor,
u32_t &  Kp,
u32_t &  Ki,
u32_t &  Kd,
u32_t &  qpps 
)
virtual

Read motor's velocity PID constants.

Command Numbers: 55, 56

Parameters
motorMotor index Motor1(0) or Motor2(1).
[out]KpVelocity PID proportional constant.
[out]KiVelocity PID intergral constant.
[out]KdVelocity PID derivative constant.
[out]qppsMaximum speed of motor.

Definition at line 958 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadVelPidMot1, motor::roboclaw::CmdReadVelPidMot2, and ROBOCLAW_DBG.

960 
961  if( (rc = m_comm.execCmdWithDataRsp(cmd, n, rsp, 18)) == OK )
962  {
963  n = 0;
964 
965  k = m_comm.unpack32(rsp, Kp);
966  n += k;
967 
968  k = m_comm.unpack32(rsp+n, Ki);
969  n += k;
970 
971  k = m_comm.unpack32(rsp+n, Kd);
972  n += k;
973 
974  k = m_comm.unpack32(rsp+n, qpps);
975  n += k;
976 
977  ROBOCLAW_DBG(cmd[FieldPosAddr], cmd[FieldPosCmd],
978  "VelPid: motor=%d, P=0x%08x, I=0x%08x, D=0x%08x, Q=%u\n",
979  motor, Kp, Ki, Kd, qpps);
980  }
981 
982  return rc;
983 }
984 
985 // Command 28,29
987  const u32_t Kp,
988  const u32_t Ki,
989  const u32_t Kd,
990  const u32_t qpps)
991 {
992  byte_t cmd[CmdMaxBufLen];
993  byte_t rsp[RspMaxBufLen];
994  size_t k, n = 0;
read motor 2 velocity PID constants
Definition: RoboClaw.h:187
int unpack32(byte_t buf[], uint_t &val)
Unpack 32-bit unsigned value from buffer.
Definition: RoboClaw.cxx:495
virtual int execCmdWithDataRsp(byte_t cmd[], size_t lenCmd, byte_t rsp[], size_t lenRsp, MsgFmt fmtCmd=MsgWithNoCrc, MsgFmt fmtRsp=MsgWithCrc)
Execute a command with an data response.
Definition: RoboClaw.cxx:325
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdSetVelocityPidConst(int motor, const u32_t Kp, const u32_t Ki, const u32_t Kd, const u32_t qpps)
Set motor&#39;s velocity PID constants.
Definition: RoboClaw.cxx:997
#define ROBOCLAW_DBG(addr, cmdNum, fmt,...)
Debug print disabled.
Definition: RoboClaw.cxx:155
Definition: RoboClaw.h:64
int RoboClaw::cmdResetQEncoders ( )
virtual

Reset both motors' encoders.

Command Numbers: 20

Definition at line 1152 of file RoboClaw.cxx.

1153  {
1154  m_nEncPrev[i] = 0;
1155  m_nEncoder[i] = 0;
1156  }
1157  }
1158 
1159  return rc;
1160 }
1161 
1162 // Command 16, 17
1163 int RoboClaw::cmdReadQEncoder(int motor, s64_t &encoder)
1164 {
1165  static s64_t MaxEncDelta = 2048; // maximum encoder delta on wrap
1166 
1167  byte_t cmd[CmdMaxBufLen];
1168  byte_t rsp[RspMaxBufLen];
1169  size_t n = 0;
1170  uint_t enc32; // 32-bit encoder value (quad pulses).
1171  byte_t status; // status bits indicating sign, and over/under flow
s64_t m_nEncPrev[NumMotors]
encoder prevous values
Definition: RoboClaw.h:1661
s64_t m_nEncoder[NumMotors]
64-bit encoder shadow values
Definition: RoboClaw.h:1662
virtual int cmdReadQEncoder(int motor, s64_t &encoder)
Read motor&#39;s encoder.
Definition: RoboClaw.cxx:1174
Definition: RoboClaw.h:64
int RoboClaw::cmdSDrive ( int  motor,
int  speed 
)
virtual

Drive a motor at the given speed.

Speeds are scaled from [-max, max] with 0 being stop.

Command Numbers: 0, 1, 4, 5

Parameters
motorMotor index Motor1(0) or Motor2(1).
speedScaled speed [MotorSpeedMaxBackward(-127),MotorSpeedMaxForward(127)]. Sign indicates direction.

Definition at line 1662 of file RoboClaw.cxx.

References motor::roboclaw::CmdDriveBackwardMot1, motor::roboclaw::CmdDriveBackwardMot2, motor::roboclaw::CmdDriveForwardMot1, motor::roboclaw::CmdDriveForwardMot2, and motor::roboclaw::MsgWithCrc.

1662  {
1663  cmd[n++] = m_address;
1664  cmd[n++] = motor == Motor1? CmdDriveForwardMot1: CmdDriveForwardMot2;
1665  cmd[n++] = (byte_t)speed;
1666  }
1667  else
1668  {
1669  cmd[n++] = m_address;
1670  cmd[n++] = motor == Motor1? CmdDriveBackwardMot1: CmdDriveBackwardMot2;
1671  cmd[n++] = (byte_t)(-speed);
1672  }
1673 
1674  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1675 }
1676 
1677 // Command 0, 1, 4, 5
1678 int RoboClaw::cmdSDrive2(int speed1, int speed2)
1679 {
1680  int rc;
1681 
1682  if( (rc = cmdSDrive(Motor1, speed1)) == OK )
1683  {
1684  rc = cmdSDrive(Motor2, speed2);
1685  }
1686  return rc;
drive motor 2 backward
Definition: RoboClaw.h:128
drive motor 1 forward
Definition: RoboClaw.h:127
drive motor 1 forward
Definition: RoboClaw.h:123
virtual int cmdSDrive(int motor, int speed)
Drive a motor at the given speed.
Definition: RoboClaw.cxx:1662
drive motor 1 backward
Definition: RoboClaw.h:124
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
virtual int cmdSDrive2(int speed1, int speed2)
Drive both motors at the given speeds.
Definition: RoboClaw.cxx:1689
Definition: RoboClaw.h:64
int RoboClaw::cmdSDrive2 ( int  speed1,
int  speed2 
)
virtual

Drive both motors at the given speeds.

Compatibility command. Speeds are scaled from [-max, max] with < 0, 0, > 0 being backwards, stop, and forwards, respectively.

Command Numbers: 0, 1, 4, 5

Parameters
speed1Motor1 scaled speed [MotorSpeedMaxBackward(-127),MotorSpeedMaxForward(127)]. Sign indicates direction.
speed2Motor2 scaled speed [MotorSpeedMaxBackward(-127),MotorSpeedMaxForward(127)]. Sign indicates direction.

Definition at line 1689 of file RoboClaw.cxx.

1695 {
1696  return cmdQDrive(motor, 0);
1697 }
1698 
virtual int cmdQDrive(int motor, s32_t speed)
Drive a motor at the given speed.
Definition: RoboClaw.cxx:1356
Definition: RoboClaw.h:64
int RoboClaw::cmdSetEncoderMode ( int  motor,
byte_t  mode 
)
virtual

Set a motor's encoder mode.

The new values are set in volatile memory only. To save to non-volatile memory, issue a write settings to EEPROM command.

Command Numbers: 92, 93

Parameters
motorMotor index Motor1(0) or Motor2(1).
modeMotor encoder mode.

Definition at line 1123 of file RoboClaw.cxx.

1129 {
1130  int rc;
1131 
1132  if( (rc = cmdSetEncoderMode(Motor1, mode1)) == OK )
1133  {
1134  rc = cmdSetEncoderMode(Motor2, mode2);
1135  }
1136 
virtual int cmdSetEncoderMode(int motor, byte_t mode)
Set a motor&#39;s encoder mode.
Definition: RoboClaw.cxx:1123
int RoboClaw::cmdSetEncoderMode2 ( byte_t  mode1,
byte_t  mode2 
)
virtual

Set both motors' encoder mode.

The new values are set in volatile memory only. To save to non-volatile memory, issue a write settings to EEPROM command.

Command Numbers: 92, 93

Parameters
mode1Motor1 encoder mode.
mode2Motor2 encoder mode.

Definition at line 1139 of file RoboClaw.cxx.

References motor::roboclaw::CmdResetEncoderCntrs, and motor::roboclaw::MsgWithCrc.

1142 {
1143  byte_t cmd[CmdMaxBufLen];
1144  size_t n = 0;
1145  int rc;
1146 
1147  cmd[n++] = m_address;
1148  cmd[n++] = CmdResetEncoderCntrs;
1149 
reset encoder (quadrature )counters
Definition: RoboClaw.h:145
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
int RoboClaw::cmdSetLogicCutoffs ( const double  min,
const double  max 
)
virtual

Set the RoboClaw's optional logic dedicated battery minimum and maximum voltage cutoff settings. The battery is connected to the LB-/LB+ terminals.

Note: The minimum value is always set to 0 (6.0V) on power-up. RDK: The documention is conflicted here. 3.0V or 6.0V?

The new values are set in volatile memory only. To save to non-volatile memory, issue a write settings to EEPROM command.

Command Numbers: 58

Parameters
[in]minMinimum voltage (V).
[in]maxMaximum voltage (V).

Definition at line 927 of file RoboClaw.cxx.

References motor::roboclaw::CmdSetLogicCutoffs.

952 {
int RoboClaw::cmdSetMainBattCutoffs ( const double  min,
const double  max 
)
virtual

Set the RoboClaw's main battery minimum and maximum voltage cutoff settings.

Note: The minimum value is always set to 0 (6.0V) on power-up.

The new values are set in volatile memory only. To save to non-volatile memory, issue a write settings to EEPROM command.

Command Numbers: 57

Parameters
[in]minMinimum voltage (V).
[in]maxMaximum voltage (V).

Definition at line 721 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadMotorDraw, and motor::roboclaw::CmdSetMainBattCutoffs.

751 {
int RoboClaw::cmdSetMotorMaxCurrentLimit ( int  motor,
const double  maxAmps 
)
virtual

Set a motor's maximum current limit.

Command Numbers: 134, 135

Parameters
motorMotor index Motor1(0) or Motor2(1).
maxAmpsMotor maximum current limit (amperes)

Definition at line 832 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadLogicVolt, motor::roboclaw::CmdSetMaxCurrentMot1, and motor::roboclaw::CmdSetMaxCurrentMot2.

843 
844  //
845  // pack values
846  //
847  k = m_comm.pack32(valMax, cmd+n);
848  n += k;
849 
850  k = m_comm.pack32(valMin, cmd+n);
851  n += k;
852 
853  // execute
854  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
855 }
856 
857 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
858 // Logic Battery Voltage Commands
859 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
860 
861 // Command 25
862 int RoboClaw::cmdReadLogicVoltage(double &volts)
863 {
864  byte_t cmd[CmdMaxBufLen];
865  byte_t rsp[RspMaxBufLen];
866  size_t n = 0;
int pack32(uint_t val, byte_t buf[])
Pack 32-bit unsigned value into buffer.
Definition: RoboClaw.cxx:486
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
virtual int cmdReadLogicVoltage(double &volts)
Read the RoboClaw&#39;s LB-/LB+ terminals input voltage powered by and optional logic dedicated battery...
Definition: RoboClaw.cxx:873
set motor 2 maximum current limit
Definition: RoboClaw.h:218
int RoboClaw::cmdSetVelocityPidConst ( int  motor,
const u32_t  Kp,
const u32_t  Ki,
const u32_t  Kd,
const u32_t  qpps 
)
virtual

Set motor's velocity PID constants.

The new values are set in volatile memory only. To save to non-volatile memory, issue a write settings to EEPROM command.

Command Numbers: 28, 29

Parameters
motorMotor index Motor1(0) or Motor2(1).
[in]KpVelocity PID proportional constant.
[in]KiVelocity PID intergral constant.
[in]KdVelocity PID derivative constant.
[in]qppsMaximum speed of motor.

Definition at line 997 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadTemp, motor::roboclaw::CmdSetVelPidMot1, and motor::roboclaw::CmdSetVelPidMot2.

1000  : CmdSetVelPidMot2;
1001 
1002  // order is strangly D,P,I,QPPS
1003  k = m_comm.pack32(Kd, cmd+n);
1004  n += k;
1005 
1006  k = m_comm.pack32(Kp, cmd+n);
1007  n += k;
1008 
1009  k = m_comm.pack32(Ki, cmd+n);
1010  n += k;
1011 
1012  k = m_comm.pack32(qpps, cmd+n);
1013  n += k;
1014 
1015  return m_comm.execCmdWithAckRsp(cmd, n, MsgWithCrc);
1016 }
1017 
1018 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1019 // Health and Status Commands
1020 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1021 
1022 // Command 82
1023 int RoboClaw::cmdReadBoardTemperature(double &temp)
1024 {
1025  byte_t cmd[CmdMaxBufLen];
1026  byte_t rsp[RspMaxBufLen];
1027  size_t n = 0;
int pack32(uint_t val, byte_t buf[])
Pack 32-bit unsigned value into buffer.
Definition: RoboClaw.cxx:486
set motor 2 velocity PID constants
Definition: RoboClaw.h:154
virtual int execCmdWithAckRsp(byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc)
Execute a command with an acknowledgement response.
Definition: RoboClaw.cxx:297
virtual int cmdReadBoardTemperature(double &temp)
Read RoboClaw board&#39;s temperature.
Definition: RoboClaw.cxx:1034
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
int RoboClaw::cmdStop ( int  motor)
virtual

Stop a motor.

Compatibility command.

Command Numbers: 35, 36

Parameters
motorMotor index Motor1(0) or Motor2(1).

Definition at line 1705 of file RoboClaw.cxx.

1707 {
1708  return cmdQDrive2(0, 0);
virtual int cmdQDrive2(s32_t speed1, s32_t speed2)
Drive both motors at the given speeds.
Definition: RoboClaw.cxx:1378
int RoboClaw::cmdStop ( )
virtual

Stop all motors.

Compatibility command.

Command Numbers: 37

Definition at line 1717 of file RoboClaw.cxx.

1719 {
1720  return cmdStop();
virtual int cmdStop()
Stop all motors.
Definition: RoboClaw.cxx:1717
int RoboClaw::cmdStopWithDecel ( int  motor,
u32_t  decel 
)
virtual

Stop a motor with the given maximum decelerations.

Stopping is controlled using velocity PID and quadrature encoders.

Compatibility command.

Command Numbers: 38, 39

Parameters
motorMotor index Motor1(0) or Motor2(1).
decelDeceleration (qpps/s).

Definition at line 1711 of file RoboClaw.cxx.

Referenced by laelaps::LaeKinActionVelocity::terminate(), and laelaps::LaeKinActionTwist::terminate().

1713 {
1714  return cmdQDriveWithAccel(0, decel, 0, decel);
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
int RoboClaw::cmdStopWithDecel ( u32_t  decel)
virtual

Stop both motors with the given maximum decelerations.

Stopping is controlled using velocity PID and quadrature encoders.

Compatibility command.

Command Numbers: 50

Parameters
decelDeceleration (qpps/s).

Definition at line 1723 of file RoboClaw.cxx.

int RoboClaw::cmdWriteSettingsToEEPROM ( )
virtual

Write all settings to EEPROM.

Command Numbers: 94

Definition at line 1745 of file RoboClaw.cxx.

1753  {
1754  usleep(100000); // 0.1 second to give controller time to write to nvm
1755  }
1756 
1757  return rc;
1758 }
1759 
static double motor::roboclaw::RoboClaw::fcap ( double  a,
double  min,
double  max 
)
inlinestaticprotected

Cap FPN value within limits [min, max].

Parameters
aValue.
minMinimum.
maxMaximum.
Returns
a: min ≤ a ≤ max

Definition at line 1711 of file RoboClaw.h.

1712  {
1713  return a<min? min: a>max? max: a;
1714  }
byte_t motor::roboclaw::RoboClaw::getAddress ( ) const
inline

Get the controller address associated with this class instance.

Returns
Returns address.

Definition at line 872 of file RoboClaw.h.

873  {
874  return m_address;
875  }
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
RoboClawComm& motor::roboclaw::RoboClaw::getComm ( )
inline

Get RoboClaw's bound communication object.

Returns
Returns object.

Definition at line 852 of file RoboClaw.h.

853  {
854  return m_comm;
855  }
RoboClawComm & m_comm
bound communication object
Definition: RoboClaw.h:1657
void RoboClaw::getLogicCutoffRange ( double &  minmin,
double &  maxmax 
) const

Get the RoboClaw's logic minimum and maximum voltage cutoff settable range.

Parameters
[out]minminMinimum minimum voltage (V).
[out]maxmaxMaximum maximum voltage (V).

Definition at line 893 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadLogicCutoffs.

901  {
void RoboClaw::getMainBattCutoffRange ( double &  minmin,
double &  maxmax 
) const

Get the RoboClaw's main battery minimum and maximum voltage cutoff settable range.

Parameters
[out]minminMinimum minimum voltage (V).
[out]maxmaxMaximum maximum voltage (V).

Definition at line 687 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadMainBattCutoffs.

695  {
virtual byte_t motor::roboclaw::RoboClaw::getMotorDir ( int  motor) const
inlinevirtual

Get the direction of motor rotation.

The motor direction is a software construct to apply a normal or reverse the sense of forward/backward rotation.

Parameters
motorMotor index Motor1(0) or Motor2(1).
Returns
Returns motor direction MotorDirNormal(1) or MotorDirReverse(-1).

Definition at line 921 of file RoboClaw.h.

922  {
923  if( isValidMotor(motor) )
924  {
925  return m_nMotorDir[motor];
926  }
927  else
928  {
929  return MotorDirNormal;
930  }
931  }
virtual bool isValidMotor(int motor) const
Test if motor index is a valid index.
Definition: RoboClaw.h:1671
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
static const int MotorDirNormal
normal
Definition: RoboClaw.h:422
Definition: RoboClaw.h:64
std::string motor::roboclaw::RoboClaw::getNameId ( ) const
inline

Get class instance name identifier.

Returns
Returns string id.

Definition at line 895 of file RoboClaw.h.

896  {
897  return m_strNameId;
898  }
std::string m_strNameId
controller name identifier
Definition: RoboClaw.h:1659
virtual bool motor::roboclaw::RoboClaw::isValidMotor ( int  motor) const
inlineprotectedvirtual

Test if motor index is a valid index.

Parameters
motorMotor index Motor1(0) or Motor2(1).
Returns
Returns true or false.

Definition at line 1671 of file RoboClaw.h.

1672  {
1673  return (motor >= Motor1) && (motor < NumMotors);
1674  }
static const int NumMotors
number of motors/controller
Definition: RoboClaw.h:416
Definition: RoboClaw.h:64
bool RoboClaw::probe ( byte_t  address)
virtual

Probe address of motor controller.

A weakness of the RoboClaw controller firmware is that there is no way to fetch its assigned address. The probe function uses a read-only command to determine, by proxy, whether the address is the controller's address. A false outcome is assumed if no response is received.

Parameters
addressMotor controller address to test.
Returns
Returns true if the motor controller has this address, false otherwise.

Definition at line 588 of file RoboClaw.cxx.

References motor::roboclaw::CmdReadFwVersion.

598 {
599  byte_t cmd[CmdMaxBufLen];
600  byte_t rsp[RspMaxBufLen];
601  uint_t uCrcCmd;
void motor::roboclaw::RoboClaw::setAddress ( byte_t  address)
inline

Set class instance address.

Note
The address may not match the controller's address. It is up to the higher-level code to determine that.
Parameters
addressMotor controller address.

Definition at line 885 of file RoboClaw.h.

886  {
887  m_address = address;
888  }
byte_t m_address
assigned controller address
Definition: RoboClaw.h:1658
virtual void motor::roboclaw::RoboClaw::setMotorDir ( int  motor,
int  motorDir 
)
inlinevirtual

set the direction of motor rotation.

The motor direction is a software construct to apply a normal or reverse the sense of forward/backward rotation.

Parameters
motorMotor index Motor1(0) or Motor2(1).
motorDirMotor direction MotorDirNormal(1) or MotorDirReverse(-1).

Definition at line 943 of file RoboClaw.h.

944  {
945  if( isValidMotor(motor) )
946  {
949  }
950  }
virtual bool isValidMotor(int motor) const
Test if motor index is a valid index.
Definition: RoboClaw.h:1671
int m_nMotorDir[NumMotors]
motor rotation direction sense
Definition: RoboClaw.h:1660
static const int MotorDirReverse
reverse (forward=backward, etc)
Definition: RoboClaw.h:423
static const int MotorDirNormal
normal
Definition: RoboClaw.h:422
Definition: RoboClaw.h:64
void motor::roboclaw::RoboClaw::setNameId ( const std::string &  strNameId)
inline

Set class instance name identifier.

Parameters
strNameIdMotor controller name identifier.

Definition at line 905 of file RoboClaw.h.

906  {
907  m_strNameId = strNameId;
908  }
std::string m_strNameId
controller name identifier
Definition: RoboClaw.h:1659

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