![]() |
Laelaps
2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
|
RoboClaw communication class. More...
#include <RoboClaw.h>
Public Member Functions | |
RoboClawComm () | |
Default constructor. | |
RoboClawComm (std::string &strDevName, int nBaudRate, RoboClawChipSelect *pChipSelect=NULL) | |
Initialization constructor. More... | |
virtual | ~RoboClawComm () |
Destructor. | |
virtual int | open (std::string &strDevName, int nBaudRate, RoboClawChipSelect *pChipSelect=NULL) |
Open connection to motor controller(s). More... | |
virtual int | close () |
Close connection to motor controller. More... | |
virtual int | flushInput () |
Flush UART input FIFO. More... | |
virtual bool | isOpen () const |
Test if connection is open. More... | |
virtual void | enableDbg (bool bEnDis) |
Test if connection is open. More... | |
uint_t | getLastCmdCrc () |
Get last sent command's calculated 16-bit CRC. More... | |
uint_t | getLastRspCrc () |
Get last received response's appended 16-bit CRC. More... | |
virtual int | execCmd (byte_t cmd[], size_t lenCmd) |
Execute a command with no response. More... | |
virtual int | execCmdWithAckRsp (byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc) |
Execute a command with an acknowledgement response. More... | |
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. More... | |
virtual int | sendCmd (byte_t cmd[], size_t lenCmd, MsgFmt fmtCmd=MsgWithNoCrc) |
Send command over serial connection to motor controller. More... | |
virtual int | recvDataRsp (byte_t rsp[], size_t lenRsp) |
Receive data response over serial connection from motor controller. More... | |
virtual int | recvAck () |
Receive acknowledgement response over serial connection from motor controller. More... | |
int | pack16 (uint_t val, byte_t buf[]) |
Pack 16-bit unsigned value into buffer. More... | |
int | unpack16 (byte_t buf[], uint_t &val) |
Unpack 16-bit unsigned value from buffer. More... | |
int | pack16 (int val, byte_t buf[]) |
Pack 16-bit signed value into buffer. More... | |
int | unpack16 (byte_t buf[], int &val) |
Unpack 16-bit signed value from buffer. More... | |
int | pack32 (uint_t val, byte_t buf[]) |
Pack 32-bit unsigned value into buffer. More... | |
int | unpack32 (byte_t buf[], uint_t &val) |
Unpack 32-bit unsigned value from buffer. More... | |
int | pack32 (int val, byte_t buf[]) |
Pack 32-bit signed value into buffer. More... | |
int | unpack32 (byte_t buf[], int &val) |
Unpack 32-bit signed value from buffer. More... | |
virtual byte_t | checksum (byte_t buf[], size_t lenBuf, bool bAck=false) |
Calculate 7-bit checksum over buffer. More... | |
virtual uint_t | crc16 (uint_t crc, byte_t buf[], size_t lenBuf) |
Calculate 16-bit CRC over buffer. More... | |
Protected Attributes | |
std::string | m_strDevName |
serial device name | |
int | m_nBaudRate |
serial baud rate | |
int | m_fd |
opened file descriptor | |
RoboClawChipSelect * | m_pChipSelect |
motor ctlr select object | |
uint_t | m_uCrcCmd |
last sent command's CRC | |
uint_t | m_uCrcRsp |
last received response's CRC | |
bool | m_bDbgEnable |
do [not] enable debugging | |
RoboClaw communication class.
The RoboClaw class instances bind to this class.
Definition at line 487 of file RoboClaw.h.
RoboClawComm::RoboClawComm | ( | std::string & | strDevName, |
int | nBaudRate, | ||
RoboClawChipSelect * | pChipSelect = NULL |
||
) |
Initialization constructor.
strDevName | Serial device name. |
nBaudRate | Serial device baud rate. |
pChipSelect | (Derived) motor controller selection class object. |
Definition at line 217 of file RoboClaw.cxx.
|
virtual |
Calculate 7-bit checksum over buffer.
[in] | buf | Buffer holding command/response. |
lenBuf | Length of data in buffer (bytes). | |
bAck | If true, or-in request ack bit to checksum (commands only). |
Definition at line 517 of file RoboClaw.cxx.
|
virtual |
Close connection to motor controller.
Definition at line 258 of file RoboClaw.cxx.
Referenced by Laelaps.WatchDog.WatchDog::attach(), and Laelaps.WatchDog.WatchDog::open().
|
virtual |
Calculate 16-bit CRC over buffer.
crc | CRC starting seed value. | |
[in] | buf | Buffer. |
lenbuf | Length of data in buffer (bytes). |
Definition at line 538 of file RoboClaw.cxx.
Referenced by Laelaps.RoboClaw.RoboClaw::execCmdWithAckRsp(), Laelaps.RoboClaw.RoboClaw::execCmdWithDataRsp(), and Laelaps.RoboClaw.RoboClaw::readVersion().
|
inlinevirtual |
Test if connection is open.
bEnDis | Enable/disable debugging. |
Definition at line 555 of file RoboClaw.h.
|
virtual |
Execute a command with no response.
[in] | cmd | Packed command buffer. |
lenCmd | Length of command (bytes). |
Definition at line 281 of file RoboClaw.cxx.
|
virtual |
Execute a command with an acknowledgement response.
[in] | cmd | Packed command buffer. |
lenCmd | Length of command (bytes). | |
fmtCmd | Command format. Do [not] append command with a 16-bit CRC. If included, the command buffer must be of length ≥ lenCmd+2. |
Definition at line 297 of file RoboClaw.cxx.
Referenced by Laelaps.RoboClaw.RoboClaw::BackwardMixed(), Laelaps.RoboClaw.RoboClaw::DriveM1(), Laelaps.RoboClaw.RoboClaw::DriveM2(), Laelaps.RoboClaw.RoboClaw::DriveMixed(), Laelaps.RoboClaw.RoboClaw::ForwardMixed(), Laelaps.RoboClaw.RoboClaw::LeftMixed(), Laelaps.RoboClaw.RoboClaw::M1Backward(), Laelaps.RoboClaw.RoboClaw::M1Forward(), Laelaps.RoboClaw.RoboClaw::M2Backward(), Laelaps.RoboClaw.RoboClaw::M2Forward(), Laelaps.RoboClaw.RoboClaw::resetEncoderCnts(), Laelaps.RoboClaw.RoboClaw::RightMixed(), Laelaps.RoboClaw.RoboClaw::setLogicBatterySettings(), Laelaps.RoboClaw.RoboClaw::setM1Duty(), Laelaps.RoboClaw.RoboClaw::setM1DutyAccel(), Laelaps.RoboClaw.RoboClaw::setM1EncoderMode(), Laelaps.RoboClaw.RoboClaw::setM1MaxCurrentLimit(), Laelaps.RoboClaw.RoboClaw::setM1Pidq(), Laelaps.RoboClaw.RoboClaw::setM1PositionConstants(), Laelaps.RoboClaw.RoboClaw::setM1Speed(), Laelaps.RoboClaw.RoboClaw::setM1SpeedAccel(), Laelaps.RoboClaw.RoboClaw::setM1SpeedAccelDeccelPosition(), Laelaps.RoboClaw.RoboClaw::setM1SpeedAccelDistance(), Laelaps.RoboClaw.RoboClaw::setM1SpeedDistance(), Laelaps.RoboClaw.RoboClaw::setM2Duty(), Laelaps.RoboClaw.RoboClaw::setM2DutyAccel(), Laelaps.RoboClaw.RoboClaw::setM2EncoderMode(), Laelaps.RoboClaw.RoboClaw::setM2MaxCurrentLimit(), Laelaps.RoboClaw.RoboClaw::setM2Pidq(), Laelaps.RoboClaw.RoboClaw::setM2PositionConstants(), Laelaps.RoboClaw.RoboClaw::setM2Speed(), Laelaps.RoboClaw.RoboClaw::setM2SpeedAccel(), Laelaps.RoboClaw.RoboClaw::setM2SpeedAccelDeccelPosition(), Laelaps.RoboClaw.RoboClaw::setM2SpeedAccelDistance(), Laelaps.RoboClaw.RoboClaw::setM2SpeedDistance(), Laelaps.RoboClaw.RoboClaw::setMainBatterySettings(), Laelaps.RoboClaw.RoboClaw::setMaxMainBattery(), Laelaps.RoboClaw.RoboClaw::setMinMainBattery(), Laelaps.RoboClaw.RoboClaw::setMixedDuty(), Laelaps.RoboClaw.RoboClaw::setMixedDutyAccel(), Laelaps.RoboClaw.RoboClaw::setMixedSpeed(), Laelaps.RoboClaw.RoboClaw::setMixedSpeedAccel(), Laelaps.RoboClaw.RoboClaw::setMixedSpeedAccelDeccelPosition(), Laelaps.RoboClaw.RoboClaw::setMixedSpeedAccelDistance(), Laelaps.RoboClaw.RoboClaw::setMixedSpeedDistance(), Laelaps.RoboClaw.RoboClaw::setMixedSpeedIAccel(), Laelaps.RoboClaw.RoboClaw::setMixedSpeedIAccelDistance(), Laelaps.RoboClaw.RoboClaw::TurnMixed(), and Laelaps.RoboClaw.RoboClaw::writeSettings().
|
virtual |
Execute a command with an data response.
[in] | cmd | Packed command buffer. |
lenCmd | Length of command (bytes). | |
[out] | rsp | Response buffer. |
lenRsp | Expected length of packed response (bytes). | |
fmtCmd | Command format. Do [not] append command with a 16-bit CRC. If included, the command buffer must be of length ≥ lenCmd+2. | |
fmtRsp | Response format. Response has with a 16-bit CRC. If ignore, firmware bug. |
Definition at line 325 of file RoboClaw.cxx.
References motor::roboclaw::MsgWithCrc.
Referenced by Laelaps.RoboClaw.RoboClaw::readBufferCnts(), Laelaps.RoboClaw.RoboClaw::readCurrents(), Laelaps.RoboClaw.RoboClaw::readEncoderMode(), Laelaps.RoboClaw.RoboClaw::readLogicBattery(), Laelaps.RoboClaw.RoboClaw::readLogicBatterySettings(), Laelaps.RoboClaw.RoboClaw::readM1Encoder(), Laelaps.RoboClaw.RoboClaw::readM1instspeed(), Laelaps.RoboClaw.RoboClaw::readM1MaxCurrentLimit(), Laelaps.RoboClaw.RoboClaw::readM1Pidq(), Laelaps.RoboClaw.RoboClaw::readM1PositionConstants(), Laelaps.RoboClaw.RoboClaw::readM1Speed(), Laelaps.RoboClaw.RoboClaw::readM2Encoder(), Laelaps.RoboClaw.RoboClaw::readM2instspeed(), Laelaps.RoboClaw.RoboClaw::readM2MaxCurrentLimit(), Laelaps.RoboClaw.RoboClaw::readM2Pidq(), Laelaps.RoboClaw.RoboClaw::readM2PositionConstants(), Laelaps.RoboClaw.RoboClaw::readM2Speed(), Laelaps.RoboClaw.RoboClaw::readMainBattery(), Laelaps.RoboClaw.RoboClaw::readMainBatterySettings(), Laelaps.RoboClaw.RoboClaw::readStatus(), and Laelaps.RoboClaw.RoboClaw::readTemperature().
|
virtual |
Flush UART input FIFO.
Definition at line 276 of file RoboClaw.cxx.
|
inline |
Get last sent command's calculated 16-bit CRC.
Definition at line 565 of file RoboClaw.h.
|
inline |
Get last received response's appended 16-bit CRC.
Definition at line 575 of file RoboClaw.h.
References motor::roboclaw::MsgWithCrc, and motor::roboclaw::MsgWithNoCrc.
|
inlinevirtual |
Test if connection is open.
Definition at line 545 of file RoboClaw.h.
Referenced by Laelaps.WatchDog.WatchDog::cmdConfigDPin(), Laelaps.WatchDog.WatchDog::cmdEnableAuxPort5V(), Laelaps.WatchDog.WatchDog::cmdEnableAuxPortBatt(), Laelaps.WatchDog.WatchDog::cmdEnableMotorCtlrs(), Laelaps.WatchDog.WatchDog::cmdGetFwVersion(), Laelaps.WatchDog.WatchDog::cmdPetTheDog(), Laelaps.WatchDog.WatchDog::cmdReadAPin(), Laelaps.WatchDog.WatchDog::cmdReadDPin(), Laelaps.WatchDog.WatchDog::cmdReadEnables(), Laelaps.WatchDog.WatchDog::cmdReadVoltages(), Laelaps.WatchDog.WatchDog::cmdResetRgbLed(), Laelaps.WatchDog.WatchDog::cmdSetAlarms(), Laelaps.WatchDog.WatchDog::cmdSetBatterySoC(), Laelaps.WatchDog.WatchDog::cmdSetRgbLed(), Laelaps.WatchDog.WatchDog::cmdWriteDPin(), and laelaps::LaeKinematics::isOpen().
|
virtual |
Open connection to motor controller(s).
strDevName | Serial device name. |
nBaudRate | Serial device baud rate. |
pChipSelect | (Derived) motor controller selection class object. |
Definition at line 234 of file RoboClaw.cxx.
int RoboClawComm::pack16 | ( | uint_t | val, |
byte_t | buf[] | ||
) |
Pack 16-bit unsigned value into buffer.
Order is big-endian (MSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 463 of file RoboClaw.cxx.
|
inline |
Pack 16-bit signed value into buffer.
Order is big-endian (MSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 693 of file RoboClaw.h.
int RoboClawComm::pack32 | ( | uint_t | val, |
byte_t | buf[] | ||
) |
Pack 32-bit unsigned value into buffer.
Order is big-endian (MSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 486 of file RoboClaw.cxx.
|
inline |
Pack 32-bit signed value into buffer.
Order is big-endian (MSB first).
[in] | val | Value to pack. |
[out] | buf | Destination buffer. |
Definition at line 744 of file RoboClaw.h.
|
virtual |
Receive acknowledgement response over serial connection from motor controller.
Definition at line 436 of file RoboClaw.cxx.
References ROBOCLAW_DBG_BUF.
|
virtual |
Receive data response over serial connection from motor controller.
[out] | rsp | Response buffer. |
lenRsp | Expected length of packed response (bytes). |
Definition at line 411 of file RoboClaw.cxx.
References ROBOCLAW_DBG_BUF.
|
virtual |
Send command over serial connection to motor controller.
[in] | cmd | Packed command buffer. |
lenCmd | Length of command (bytes). | |
fmtCmd | Command format. Do [not] append command with a 16-bit CRC. If included, the command buffer must be of length ≥ lenCmd+2. |
Definition at line 380 of file RoboClaw.cxx.
References ROBOCLAW_DBG_BUF.
Referenced by Laelaps.Imu.Imu::unpackS32().
int RoboClawComm::unpack16 | ( | byte_t | buf[], |
uint_t & | val | ||
) |
Unpack 16-bit unsigned value from buffer.
Buffer is big-endian (MSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 470 of file RoboClaw.cxx.
int RoboClawComm::unpack16 | ( | byte_t | buf[], |
int & | val | ||
) |
Unpack 16-bit signed value from buffer.
Buffer is big-endian (MSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 476 of file RoboClaw.cxx.
int RoboClawComm::unpack32 | ( | byte_t | buf[], |
uint_t & | val | ||
) |
Unpack 32-bit unsigned value from buffer.
Buffer is big-endian (MSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 495 of file RoboClaw.cxx.
int RoboClawComm::unpack32 | ( | byte_t | buf[], |
int & | val | ||
) |
Unpack 32-bit signed value from buffer.
Buffer is big-endian (MSB first).
[in] | buf | Source buffer. |
[out] | val | Unpacked value. |
Definition at line 504 of file RoboClaw.cxx.