Skip to content

Commit

Permalink
Add actuator control vocabs, fill missing documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Sep 9, 2017
1 parent 35c9f5b commit 7bf9927
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AmorCartesianControl : public yarp::dev::DeviceDriver, public ICartesianCo

virtual bool tool(const std::vector<double> &x);

virtual bool act(int commandCode);
virtual bool act(int command);

virtual void fwd(const std::vector<double> &rot, double step);

Expand Down
48 changes: 22 additions & 26 deletions libraries/TeoYarp/AmorCartesianControl/ICartesianControlImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <cmath>

#include <yarp/os/Vocab.h>

#include "KinematicRepresentation.hpp"

// ------------------- ICartesianControl Related ------------------------------------
Expand Down Expand Up @@ -219,35 +221,29 @@ bool roboticslab::AmorCartesianControl::tool(const std::vector<double> &x)

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

bool roboticslab::AmorCartesianControl::act(int commandCode)
bool roboticslab::AmorCartesianControl::act(int command)
{
if (commandCode == 1)
{
if (amor_close_hand(handle) != AMOR_SUCCESS)
{
CD_ERROR("%s\n", amor_error());
return false;
}
}
else if (commandCode == 2)
{
if (amor_open_hand(handle) != AMOR_SUCCESS)
{
CD_ERROR("%s\n", amor_error());
return false;
}
}
else if (commandCode == 3)
{
if (amor_stop_hand(handle) != AMOR_SUCCESS)
{
CD_ERROR("%s\n", amor_error());
return false;
}
AMOR_RESULT (*amor_command)(AMOR_HANDLE);

switch (command)
{
case VOCAB_CC_ACTUATOR_CLOSE_GRIPPER:
amor_command = amor_close_hand;
break;
case VOCAB_CC_ACTUATOR_OPEN_GRIPPER:
amor_command = amor_open_hand;
break;
case VOCAB_CC_ACTUATOR_STOP_GRIPPER:
amor_command = amor_stop_hand;
break;
default:
CD_ERROR("Unrecognized command with code %d (%s).\n", command, yarp::os::Vocab::decode(command));
return false;
}
else

if (amor_command(handle) != AMOR_SUCCESS)
{
CD_ERROR("Unrecognized command code: %d.\n", commandCode);
CD_ERROR("%s\n", amor_error());
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class BasicCartesianControl : public yarp::dev::DeviceDriver, public ICartesianC

virtual bool tool(const std::vector<double> &x);

virtual bool act(int commandCode);
virtual bool act(int command);

virtual void fwd(const std::vector<double> &rot, double step);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ bool roboticslab::BasicCartesianControl::tool(const std::vector<double> &x)

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

bool roboticslab::BasicCartesianControl::act(int commandCode)
bool roboticslab::BasicCartesianControl::act(int command)
{
CD_ERROR("Not implemented.\n");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CartesianControlClient : public yarp::dev::DeviceDriver, public ICartesian

virtual bool tool(const std::vector<double> &x);

virtual bool act(int commandCode);
virtual bool act(int command);

virtual void fwd(const std::vector<double> &rot, double step);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ bool roboticslab::CartesianControlClient::tool(const std::vector<double> &x)

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

bool roboticslab::CartesianControlClient::act(int commandCode)
bool roboticslab::CartesianControlClient::act(int command)
{
yarp::os::Bottle cmd, response;

cmd.addVocab(VOCAB_CC_ACT);
cmd.addInt(commandCode);
cmd.addInt(command);

rpcClient.write(cmd,response);

Expand Down
32 changes: 29 additions & 3 deletions libraries/TeoYarp/ICartesianControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define VOCAB_CC_FORC VOCAB4('f','o','r','c') ///< Force control
#define VOCAB_CC_STOP VOCAB4('s','t','o','p') ///< Stop control
#define VOCAB_CC_TOOL VOCAB4('t','o','o','l') ///< Change tool
#define VOCAB_CC_ACT VOCAB3('a','c','t')
#define VOCAB_CC_ACT VOCAB3('a','c','t') ///< Actuate tool

/** @} */

Expand Down Expand Up @@ -71,6 +71,24 @@

/** @} */

/**
* @anchor ICartesianControl_actuator_vocabs
* @name Actuator control vocabs
*
* Used by roboticslab::ICartesianControl::act to control the actuator.
*
* @{
*/

// Actuator control
#define VOCAB_CC_ACTUATOR_NONE VOCAB3('a','c','n') ///< No actuator or no action
#define VOCAB_CC_ACTUATOR_CLOSE_GRIPPER VOCAB4('a','c','c','g') ///< Close gripper
#define VOCAB_CC_ACTUATOR_OPEN_GRIPPER VOCAB4('a','c','o','g') ///< Open gripper
#define VOCAB_CC_ACTUATOR_STOP_GRIPPER VOCAB4('a','c','s','g') ///< Stop gripper
#define VOCAB_CC_ACTUATOR_GENERIC VOCAB3('a','c','g') ///< Generic actuator

/** @} */

namespace roboticslab
{

Expand Down Expand Up @@ -221,8 +239,16 @@ class ICartesianControl
*/
virtual bool tool(const std::vector<double> &x) = 0;

/** actuate tool */
virtual bool act(int commandCode) = 0;
/**
* @brief Actuate tool
*
* Send control command to actuate the robot's tool, if available.
*
* @param command One of available @ref ICartesianControl_actuator_vocabs "actuator vocabs".
*
* @return true on success, false otherwise
*/
virtual bool act(int command) = 0;

/** @} */

Expand Down
10 changes: 5 additions & 5 deletions programs/streamingDeviceController/SpnavSensorDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ int roboticslab::SpnavSensorDevice::getActuatorState()

if (button1 == 1)
{
actuatorState = 1;
actuatorState = VOCAB_CC_ACTUATOR_CLOSE_GRIPPER;
}
else if (button2 == 1)
{
actuatorState = 2;
actuatorState = VOCAB_CC_ACTUATOR_OPEN_GRIPPER;
}
else
{
if (actuatorState != 0)
if (actuatorState != VOCAB_CC_ACTUATOR_NONE)
{
actuatorState = 3;
actuatorState = VOCAB_CC_ACTUATOR_STOP_GRIPPER;
}

actuatorState = 0;
actuatorState = VOCAB_CC_ACTUATOR_NONE;
}

return actuatorState;
Expand Down
2 changes: 1 addition & 1 deletion programs/streamingDeviceController/StreamingDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ StreamingDevice * StreamingDeviceFactory::makeDevice(const std::string & deviceN

StreamingDevice::StreamingDevice(yarp::os::Searchable & config)
: iCartesianControl(NULL),
actuatorState(0)
actuatorState(VOCAB_CC_ACTUATOR_NONE)
{
data.resize(6, 0.0);
fixedAxes.resize(6, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool StreamingDeviceController::updateModule()

int actuatorState = streamingDevice->getActuatorState();

if (actuatorState != 0)
if (actuatorState != VOCAB_CC_ACTUATOR_NONE)
{
iCartesianControl->act(actuatorState);
}
Expand Down

0 comments on commit 7bf9927

Please sign in to comment.