Skip to content

Commit

Permalink
Rename ICartesianControl::movi to pose
Browse files Browse the repository at this point in the history
Closes #198.
  • Loading branch information
PeterBowman committed May 23, 2024
1 parent 9a3e621 commit 25a9c1a
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ bool BasicCartesianControl::presetStreamingCommand(int command)

switch (command)
{
case VOCAB_CC_MOVI:
case VOCAB_CC_POSE:
case VOCAB_CC_MOVI: // deprecated
return setControlModes(VOCAB_CM_POSITION_DIRECT);
case VOCAB_CC_TWIST:
return setControlModes(VOCAB_CM_VELOCITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class BasicCartesianControl : public yarp::dev::DeviceDriver,
bool wait(double timeout) override;
bool tool(const std::vector<double> & x) override;
bool act(int command) override;
void movi(const std::vector<double> & x) override;
void pose(const std::vector<double> & x) override;
void twist(const std::vector<double> & xdot) override;
void wrench(const std::vector<double> & w) override;
bool setParameter(int vocab, double value) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,10 @@ bool BasicCartesianControl::act(int command)

// -----------------------------------------------------------------------------

void BasicCartesianControl::movi(const std::vector<double> &x)
void BasicCartesianControl::pose(const std::vector<double> &x)
{
if (getCurrentState() != VOCAB_CC_NOT_CONTROLLING || streamingCommand != VOCAB_CC_MOVI
if (getCurrentState() != VOCAB_CC_NOT_CONTROLLING || streamingCommand != VOCAB_CC_POSE
|| streamingCommand != VOCAB_CC_MOVI // deprecated
|| !checkControlModes(VOCAB_CM_POSITION_DIRECT))
{
yCError(BCC) << "Streaming command not preset";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CartesianControlClient : public yarp::dev::DeviceDriver,
bool wait(double timeout) override;
bool tool(const std::vector<double> &x) override;
bool act(int command) override;
void movi(const std::vector<double> &x) override;
void pose(const std::vector<double> &x) override;
void twist(const std::vector<double> &xdot) override;
void wrench(const std::vector<double> &w) override;
bool setParameter(int vocab, double value) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ bool CartesianControlClient::act(int command)

// -----------------------------------------------------------------------------

void CartesianControlClient::twist(const std::vector<double> &xdot)
void CartesianControlClient::pose(const std::vector<double> &x)
{
handleStreamingConsumerCmd(VOCAB_CC_TWIST, xdot);
handleStreamingConsumerCmd(VOCAB_CC_POSE, x);
}

// -----------------------------------------------------------------------------

void CartesianControlClient::movi(const std::vector<double> &x)
void CartesianControlClient::twist(const std::vector<double> &xdot)
{
handleStreamingConsumerCmd(VOCAB_CC_MOVI, x);
handleStreamingConsumerCmd(VOCAB_CC_TWIST, xdot);
}

// -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void RpcResponder::makeUsage()

std::stringstream ss_cmd;
ss_cmd << "(config param) preset streaming command, available:";
ss_cmd << " [" << Vocab::decode(VOCAB_CC_MOVI) << "]";
ss_cmd << " [" << Vocab::decode(VOCAB_CC_POSE) << "]";
ss_cmd << " [" << Vocab::decode(VOCAB_CC_TWIST) << "]";
ss_cmd << " [" << Vocab::decode(VOCAB_CC_WRENCH) << "]";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ void StreamResponder::onRead(yarp::os::Bottle& b)

switch (b.get(0).asVocab32())
{
case VOCAB_CC_MOVI:
handleConsumerCmdMsg(b, &ICartesianControl::movi);
case VOCAB_CC_POSE:
case VOCAB_CC_MOVI: // deprecated
handleConsumerCmdMsg(b, &ICartesianControl::pose);
break;
case VOCAB_CC_TWIST:
handleConsumerCmdMsg(b, &ICartesianControl::twist);
Expand Down
19 changes: 16 additions & 3 deletions libraries/YarpPlugins/ICartesianControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ constexpr int VOCAB_CC_ACT = yarp::os::createVocab32('a','c','t'); ///< Act
*/

// Streaming commands
constexpr int VOCAB_CC_MOVI = yarp::os::createVocab32('m','o','v','i'); ///< Achieve pose (position control)
constexpr int VOCAB_CC_POSE = yarp::os::createVocab32('p','o','s','e'); ///< Achieve pose
#ifndef SWIG_PREPROCESSOR_SHOULD_SKIP_THIS
[[deprecated("use `VOCAB_CC_POSE` instead")]]
constexpr int VOCAB_CC_MOVI = yarp::os::createVocab32('m','o','v','i');
#endif
constexpr int VOCAB_CC_TWIST = yarp::os::createVocab32('t','w','s','t'); ///< Instantaneous velocity steps
constexpr int VOCAB_CC_WRENCH = yarp::os::createVocab32('w','r','n','c'); ///< Exert force

Expand Down Expand Up @@ -330,9 +334,18 @@ class ICartesianControl
* expected other than computing the inverse kinematics.
*
* @param x 6-element vector describing desired instantaneous pose in cartesian space;
* first three elements denote translation (meters), last three denote rotation (radians).
* first three elements denote translation (meters), last three denote rotation in scaled
* axis-angle representation (radians).
*/
virtual void movi(const std::vector<double> &x) = 0;
virtual void pose(const std::vector<double> &x) = 0;

#ifndef SWIG_PREPROCESSOR_SHOULD_SKIP_THIS
[[deprecated("use `pose` instead")]]
virtual void movi(const std::vector<double> &x)
{
pose(x);
}
#endif

/**
* @brief Instantaneous velocity steps
Expand Down
8 changes: 5 additions & 3 deletions programs/keyboardController/KeyboardController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ bool KeyboardController::configure(yarp::os::ResourceFinder & rf)

currentCartVels.resize(NUM_CART_COORDS, 0.0);

usingThread = rf.check("movi", "use MOVI command");
usingThread = rf.check("pose", "use POSE command");
usingThread = usingThread || rf.check("movi", "use POSE command"); // deprecated

int threadMs = rf.check("moviPeriodMs", yarp::os::Value(DEFAULT_THREAD_MS), "MOVI thread period [ms]").asInt32();
// `moviPeriodMs` is deprecated
int threadMs = rf.check("posePeriodMs", rf.check("moviPeriodMs", yarp::os::Value(DEFAULT_THREAD_MS)), "POSE thread period [ms]").asInt32();

if (usingThread)
{
Expand All @@ -239,7 +241,7 @@ bool KeyboardController::configure(yarp::os::ResourceFinder & rf)

if (!linTrajThread->start())
{
yCError(KC) << "Unable to start MOVI thread";
yCError(KC) << "Unable to start POSE thread";
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions programs/keyboardController/LinearTrajectoryThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool LinearTrajectoryThread::checkStreamingConfig()

bool LinearTrajectoryThread::configure(const std::vector<double> & vels)
{
if (usingStreamingCommandConfig && !iCartesianControl->setParameter(VOCAB_CC_CONFIG_STREAMING_CMD, VOCAB_CC_MOVI))
if (usingStreamingCommandConfig && !iCartesianControl->setParameter(VOCAB_CC_CONFIG_STREAMING_CMD, VOCAB_CC_POSE))
{
yCWarning(KC) << "Unable to preset streaming command";
return false;
Expand Down Expand Up @@ -110,7 +110,7 @@ void LinearTrajectoryThread::run()
deltaX = this->deltaX;
mtx.unlock();

iCartesianControl->movi(deltaX);
iCartesianControl->pose(deltaX);
}
else
{
Expand All @@ -119,6 +119,6 @@ void LinearTrajectoryThread::run()
mtx.unlock();

std::vector<double> position = KdlVectorConverter::frameToVector(H);
iCartesianControl->movi(position);
iCartesianControl->pose(position);
}
}
10 changes: 5 additions & 5 deletions programs/streamingDeviceController/LeapMotionSensorDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

using namespace roboticslab;

LeapMotionSensorDevice::LeapMotionSensorDevice(yarp::os::Searchable & config, bool usingMovi)
LeapMotionSensorDevice::LeapMotionSensorDevice(yarp::os::Searchable & config, bool usingPose)
: StreamingDevice(config),
iAnalogSensor(nullptr),
usingMovi(usingMovi),
usingPose(usingPose),
previousTimestamp(0.0),
hasActuator(false),
grab(false), pinch(false)
Expand Down Expand Up @@ -60,7 +60,7 @@ bool LeapMotionSensorDevice::initialize(bool usingStreamingPreset)
{
if (usingStreamingPreset)
{
int cmd = usingMovi ? VOCAB_CC_MOVI : VOCAB_CC_TWIST;
int cmd = usingPose ? VOCAB_CC_POSE : VOCAB_CC_TWIST;

if (!iCartesianControl->setParameter(VOCAB_CC_CONFIG_STREAMING_CMD, cmd))
{
Expand Down Expand Up @@ -211,9 +211,9 @@ int LeapMotionSensorDevice::getActuatorState()

void LeapMotionSensorDevice::sendMovementCommand(double timestamp)
{
if (usingMovi)
if (usingPose)
{
iCartesianControl->movi(data);
iCartesianControl->pose(data);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions programs/streamingDeviceController/LeapMotionSensorDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LeapMotionSensorDevice : public StreamingDevice
{
public:
//! Constructor
LeapMotionSensorDevice(yarp::os::Searchable & config, bool usingMovi);
LeapMotionSensorDevice(yarp::os::Searchable & config, bool usingPose);

bool acquireInterfaces() override;

Expand All @@ -42,7 +42,7 @@ class LeapMotionSensorDevice : public StreamingDevice
private:
yarp::dev::IAnalogSensor * iAnalogSensor;

bool usingMovi;
bool usingPose;

std::vector<double> initialTcpOffset;
std::vector<double> initialLeapOffset;
Expand Down
22 changes: 11 additions & 11 deletions programs/streamingDeviceController/SpnavSensorDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

using namespace roboticslab;

SpnavSensorDevice::SpnavSensorDevice(yarp::os::Searchable & config, bool usingMovi, double gain)
SpnavSensorDevice::SpnavSensorDevice(yarp::os::Searchable & config, bool usingPose, double gain)
: StreamingDevice(config),
iAnalogSensor(nullptr),
usingMovi(usingMovi),
usingPose(usingPose),
gain(gain),
buttonClose(false),
buttonOpen(false)
Expand All @@ -31,15 +31,15 @@ bool SpnavSensorDevice::acquireInterfaces()

bool SpnavSensorDevice::initialize(bool usingStreamingPreset)
{
if (usingMovi && gain <= 0.0)
if (usingPose && gain <= 0.0)
{
yCWarning(SDC) << "Invalid gain for movi command:" << gain;
yCWarning(SDC) << "Invalid gain for pose command:" << gain;
return false;
}

if (usingStreamingPreset)
{
int cmd = usingMovi ? VOCAB_CC_MOVI : VOCAB_CC_TWIST;
int cmd = usingPose ? VOCAB_CC_POSE : VOCAB_CC_TWIST;

if (!iCartesianControl->setParameter(VOCAB_CC_CONFIG_STREAMING_CMD, cmd))
{
Expand All @@ -54,7 +54,7 @@ bool SpnavSensorDevice::initialize(bool usingStreamingPreset)
return false;
}

if (usingMovi && !iCartesianControl->stat(currentX))
if (usingPose && !iCartesianControl->stat(currentX))
{
yCWarning(SDC) << "Unable to stat initial position, assuming zero";
currentX.resize(6, 0.0);
Expand Down Expand Up @@ -92,7 +92,7 @@ bool SpnavSensorDevice::acquireData()

bool SpnavSensorDevice::transformData(double scaling)
{
if (usingMovi)
if (usingPose)
{
for (int i = 0; i < 6; i++)
{
Expand Down Expand Up @@ -145,7 +145,7 @@ int SpnavSensorDevice::getActuatorState()

bool SpnavSensorDevice::hasValidMovementData() const
{
if (usingMovi)
if (usingPose)
{
for (int i = 0; i < 6; i++)
{
Expand All @@ -165,9 +165,9 @@ bool SpnavSensorDevice::hasValidMovementData() const

void SpnavSensorDevice::sendMovementCommand(double timestamp)
{
if (usingMovi)
if (usingPose)
{
iCartesianControl->movi(data);
iCartesianControl->pose(data);

for (int i = 0; i < 6; i++)
{
Expand All @@ -182,7 +182,7 @@ void SpnavSensorDevice::sendMovementCommand(double timestamp)

void SpnavSensorDevice::stopMotion()
{
if (!usingMovi)
if (!usingPose)
{
std::vector<double> zeros(6, 0.0);
iCartesianControl->twist(zeros);
Expand Down
2 changes: 1 addition & 1 deletion programs/streamingDeviceController/SpnavSensorDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SpnavSensorDevice : public StreamingDevice

std::vector<double> currentX;

bool usingMovi;
bool usingPose;
double gain;
bool buttonClose;
bool buttonOpen;
Expand Down
11 changes: 6 additions & 5 deletions programs/streamingDeviceController/StreamingDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ using namespace roboticslab;
StreamingDevice * StreamingDeviceFactory::makeDevice(const std::string & deviceName, yarp::os::Searchable & config)
{
auto & deviceConfig = config.findGroup(deviceName.c_str());
bool usingMovi = config.check("movi", "enable movi command");
bool usingPose = config.check("pose", "enable pose command");
usingPose = usingPose || config.check("movi", "enable pose command"); // deprecated

yCDebug(SDC) << "Device configuration:" << deviceConfig.toString();

// https://github.com/roboticslab-uc3m/kinematics-dynamics/issues/186
yCWarning(SDC) << "Using MOVI commands, beware NOT TO EXCEED JOINT LIMITS";
yCWarning(SDC) << "Using POSE commands, beware NOT TO EXCEED JOINT LIMITS";

if (deviceName == "SpaceNavigator")
{
double gain = config.check("gain", yarp::os::Value(0.0)).asFloat64();
return new SpnavSensorDevice(deviceConfig, usingMovi, gain);
return new SpnavSensorDevice(deviceConfig, usingPose, gain);
}
else if (deviceName == "LeapMotionSensor")
{
return new LeapMotionSensorDevice(deviceConfig, usingMovi);
return new LeapMotionSensorDevice(deviceConfig, usingPose);
}
else if (deviceName == "WiimoteSensor")
{
return new WiimoteSensorDevice(deviceConfig, usingMovi);
return new WiimoteSensorDevice(deviceConfig, usingPose);
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions programs/streamingDeviceController/WiimoteSensorDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

using namespace roboticslab;

WiimoteSensorDevice::WiimoteSensorDevice(yarp::os::Searchable & config, bool usingMovi)
WiimoteSensorDevice::WiimoteSensorDevice(yarp::os::Searchable & config, bool usingPose)
: StreamingDevice(config),
iAnalogSensor(nullptr),
mode(NONE),
usingMovi(usingMovi),
usingPose(usingPose),
step(0.0)
{
data.resize(3); // already called by base constructor
Expand All @@ -37,15 +37,15 @@ bool WiimoteSensorDevice::acquireInterfaces()

bool WiimoteSensorDevice::initialize(bool usingStreamingPreset)
{
if (usingMovi && step <= 0.0)
if (usingPose && step <= 0.0)
{
yCWarning(SDC) << "Invalid step:" << step;
return false;
}

if (usingStreamingPreset)
{
int cmd = usingMovi ? VOCAB_CC_MOVI : VOCAB_CC_TWIST;
int cmd = usingPose ? VOCAB_CC_POSE : VOCAB_CC_TWIST;

if (!iCartesianControl->setParameter(VOCAB_CC_CONFIG_STREAMING_CMD, cmd))
{
Expand Down Expand Up @@ -149,9 +149,9 @@ void WiimoteSensorDevice::sendMovementCommand(double timestamp)
return;
}

if (usingMovi)
if (usingPose)
{
iCartesianControl->movi(xdot);
iCartesianControl->pose(xdot);
}
else
{
Expand All @@ -161,7 +161,7 @@ void WiimoteSensorDevice::sendMovementCommand(double timestamp)

void WiimoteSensorDevice::stopMotion()
{
if (!usingMovi)
if (!usingPose)
{
std::vector<double> zeros(6, 0.0);
iCartesianControl->twist(zeros);
Expand Down
Loading

0 comments on commit 25a9c1a

Please sign in to comment.