Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare cartesian controller interface for tool actuation (AMOR) #181

Merged
merged 57 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6ea6018
Add 'act' RPC command, implement in AmorCartesianControl
PeterBowman Aug 22, 2017
696102d
Merge branch 'sensors' into amor-cc-actuator
PeterBowman Aug 22, 2017
9af52eb
Implement actuator control in streamingSpnav, enable amor_stop_hand()
PeterBowman Aug 22, 2017
fc6b4f1
Merge branch 'streaming-cc-rename-apps' into amor-cc-actuator
PeterBowman Aug 27, 2017
d9830db
Merge branch 'sensors' into amor-cc-actuator
PeterBowman Sep 8, 2017
35c9f5b
Move actuator logic to StreamingDevice and derived classes
PeterBowman Sep 8, 2017
7bf9927
Add actuator control vocabs, fill missing documentation
PeterBowman Sep 9, 2017
2c45c67
Remove unused actuator-related macro definitions
PeterBowman Sep 10, 2017
b27e771
Create HaarDetectionController application
PeterBowman Sep 10, 2017
7736049
Receive data from proximity sensors, actuate robot tool
PeterBowman Sep 11, 2017
0a45747
Disable sensors conditionally
PeterBowman Sep 11, 2017
5013865
Make robot approach toward the object, let users disable this
PeterBowman Sep 11, 2017
e6bb875
Stop control and apply constant act(*_CLOSE_GRIPPER) on target detection
PeterBowman Sep 12, 2017
d06023c
Add --noMove option for testing the gripper (robot won't move at all)
PeterBowman Sep 12, 2017
853cecc
Merge branch 'haar-detection-controller' into amor-cc-actuator
PeterBowman Sep 12, 2017
68de043
Add usage notes about [act] command
PeterBowman Sep 12, 2017
e3df3cd
Fix misplaced colon (kids, be wise and use an IDE)
PeterBowman Sep 13, 2017
ea08c88
Merge branch 'streaming-cc-leap' into amor-cc-actuator
PeterBowman Oct 9, 2017
330b220
Handle actuator by Leap Motion device
PeterBowman Oct 9, 2017
2c3b7af
Don't overwrite VOCAB_CC_ACTUATOR_STOP_GRIPPER value
PeterBowman Oct 9, 2017
5d33488
Send VOCAB_CC_ACTUATOR_STOP_GRIPPER command only once
PeterBowman Oct 10, 2017
72a3333
Merge branch 'streaming-cc-leap' into amor-cc-actuator
PeterBowman Oct 10, 2017
27a601d
Merge branch 'streaming-cc-travis' into amor-cc-actuator
PeterBowman Oct 16, 2017
8b67a5e
Merge branch 'streaming-cartesian-control' into amor-cc-actuator
PeterBowman Oct 20, 2017
2257ac4
Actuate gripper in KeyboardController
PeterBowman Oct 20, 2017
a9b6ecd
Encode actuator command as a vocab
PeterBowman Oct 20, 2017
fc28237
Merge branch 'amor-cc-actuator' into amor-cc-actuator-renaming
PeterBowman Dec 5, 2017
8683ffc
Merge branch 'amor-cc-actuator-renaming' into amor-cc-actuator
PeterBowman Dec 5, 2017
7ead812
Merge branch 'fix-93-stalled-builds' into amor-cc-actuator
PeterBowman Dec 17, 2017
e12a778
Merge branch 'fix-102-fkstream-rebased' into amor-cc-actuator
PeterBowman Jan 2, 2018
a2b17db
Merge branch 'fix-121-controller-conf' into amor-cc-actuator
PeterBowman Jan 20, 2018
b443ae1
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jan 23, 2018
f27f22e
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jan 31, 2018
634137e
Merge branch 'develop' into amor-cc-actuator
PeterBowman Feb 3, 2018
28b6e4d
Merge branch 'develop' into amor-cc-actuator
PeterBowman Feb 10, 2018
b87c4d7
Merge branch 'develop' into amor-cc-actuator
PeterBowman Feb 24, 2018
9af51f6
Merge branch 'interface-targets' into amor-cc-actuator
PeterBowman Mar 9, 2018
48ea63b
Merge branch 'yarp-cmake' into amor-cc-actuator
PeterBowman Mar 23, 2018
edd50b1
Return vanilla C string instead of ConstString
PeterBowman Mar 24, 2018
edaad0e
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jun 8, 2018
ee9e658
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jun 16, 2018
f637dca
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jun 22, 2018
b358b8e
Disable haarDetectionController if dep not found
PeterBowman Jun 22, 2018
f1ca4c2
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jul 13, 2018
bf74e7a
Merge branch 'develop' into amor-cc-actuator
PeterBowman Oct 2, 2018
5c6ce96
Merge branch 'develop' into amor-cc-actuator
PeterBowman Nov 4, 2018
1e0ed5f
Merge branch 'develop' into amor-cc-actuator
PeterBowman Dec 26, 2018
a881b8b
Merge branch 'develop' into amor-cc-actuator
PeterBowman Mar 25, 2019
8abd5de
Merge branch 'upgrade-yarp' into amor-cc-actuator
PeterBowman May 15, 2019
c90bb38
Merge branch 'develop' into amor-cc-actuator
PeterBowman May 18, 2019
105a9a3
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jun 18, 2019
ff4992e
Merge branch 'develop' into amor-cc-actuator
PeterBowman Jun 28, 2019
8693352
Merge branch 'streaming-dev-shared-ctrl' into streaming-dev-shared-ct…
PeterBowman Jun 30, 2019
e6aa31a
Merge branch 'streaming-dev-shared-ctrl' into streaming-dev-shared-ct…
PeterBowman Jul 3, 2019
391e9c8
Conditionally handle button states
PeterBowman Jul 3, 2019
58885aa
Merge branch 'streaming-dev-shared-ctrl' into streaming-dev-shared-ct…
PeterBowman Jul 3, 2019
acc9c4f
Merge branch 'streaming-dev-shared-ctrl-act' into amor-cc-actuator
PeterBowman Jul 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class AmorCartesianControl : public yarp::dev::DeviceDriver, public ICartesianCo

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

virtual bool act(int command);

virtual void twist(const std::vector<double> &xdot);

virtual void pose(const std::vector<double> &x, double interval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <ColorDebug.h>

#include <yarp/os/Vocab.h>

#include "KinematicRepresentation.hpp"

// ------------------- ICartesianControl Related ------------------------------------
Expand Down Expand Up @@ -321,6 +323,37 @@ bool roboticslab::AmorCartesianControl::tool(const std::vector<double> &x)

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

bool roboticslab::AmorCartesianControl::act(int command)
{
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).c_str());
return false;
}

if (amor_command(handle) != AMOR_SUCCESS)
{
CD_ERROR("%s\n", amor_error());
return false;
}

return true;
}

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

void roboticslab::AmorCartesianControl::twist(const std::vector<double> &xdot)
{
AMOR_VECTOR7 positions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ class BasicCartesianControl : public yarp::dev::DeviceDriver,

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

virtual bool act(int command);

virtual void twist(const std::vector<double> &xdot);

virtual void pose(const std::vector<double> &x, double interval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ bool roboticslab::BasicCartesianControl::tool(const std::vector<double> &x)

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

bool roboticslab::BasicCartesianControl::act(int command)
{
CD_ERROR("Not implemented.\n");
return false;
}

void roboticslab::BasicCartesianControl::twist(const std::vector<double> &xdot)
{
if (getCurrentState() != VOCAB_CC_NOT_CONTROLLING || streamingCommand != VOCAB_CC_TWIST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class CartesianControlClient : public yarp::dev::DeviceDriver, public ICartesian

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

virtual bool act(int command);

virtual void twist(const std::vector<double> &xdot);

virtual void pose(const std::vector<double> &x, double interval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ bool roboticslab::CartesianControlClient::tool(const std::vector<double> &x)

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

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

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

rpcClient.write(cmd,response);

return checkSuccess(response);
}

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

void roboticslab::CartesianControlClient::twist(const std::vector<double> &xdot)
{
handleStreamingConsumerCmd(VOCAB_CC_TWIST, xdot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class RpcResponder : public yarp::dev::DeviceResponder

bool handleStatMsg(const yarp::os::Bottle& in, yarp::os::Bottle& out);
bool handleWaitMsg(const yarp::os::Bottle& in, yarp::os::Bottle& out);
bool handleActMsg(const yarp::os::Bottle& in, yarp::os::Bottle& out);

bool handleRunnableCmdMsg(const yarp::os::Bottle& in, yarp::os::Bottle& out, RunnableFun cmd);
bool handleConsumerCmdMsg(const yarp::os::Bottle& in, yarp::os::Bottle& out, ConsumerFun cmd);
Expand Down
33 changes: 33 additions & 0 deletions libraries/YarpPlugins/CartesianControlServer/RpcResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ bool roboticslab::RpcResponder::respond(const yarp::os::Bottle& in, yarp::os::Bo
return handleWaitMsg(in, out);
case VOCAB_CC_TOOL:
return handleConsumerCmdMsg(in, out, &ICartesianControl::tool);
case VOCAB_CC_ACT:
return handleActMsg(in, out);
case VOCAB_CC_SET:
return isGroupParam(in) ? handleParameterSetterGroup(in, out) : handleParameterSetter(in, out);
case VOCAB_CC_GET:
Expand Down Expand Up @@ -133,6 +135,10 @@ void roboticslab::RpcResponder::makeUsage()
addUsage(ss.str().c_str(), "append fixed link to end effector");
ss.str("");

ss << "[" << yarp::os::Vocab::decode(VOCAB_CC_ACT) << "] vocab";
addUsage(ss.str().c_str(), "actuate tool using selected command vocab");
ss.str("");

ss << "[" << yarp::os::Vocab::decode(VOCAB_CC_SET) << "] vocab value";
addUsage(ss.str().c_str(), "set configuration parameter");
ss.str("");
Expand Down Expand Up @@ -254,6 +260,33 @@ bool roboticslab::RpcResponder::handleWaitMsg(const yarp::os::Bottle& in, yarp::

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

bool roboticslab::RpcResponder::handleActMsg(const yarp::os::Bottle& in, yarp::os::Bottle& out)
{
if (in.size() > 1)
{
int commandCode = in.get(1).asVocab();

if (iCartesianControl->act(commandCode))
{
out.addVocab(VOCAB_CC_OK);
return true;
}
else
{
out.addVocab(VOCAB_CC_FAILED);
return false;
}
}
else
{
CD_ERROR("size error\n");
out.addVocab(VOCAB_CC_FAILED);
return false;
}
}

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

bool roboticslab::RpcResponder::handleRunnableCmdMsg(const yarp::os::Bottle& in, yarp::os::Bottle& out, RunnableFun cmd)
{
if ((iCartesianControl->*cmd)())
Expand Down
28 changes: 28 additions & 0 deletions libraries/YarpPlugins/ICartesianControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#define VOCAB_CC_STOP ROBOTICSLAB_VOCAB('s','t','o','p') ///< Stop control
#define VOCAB_CC_WAIT ROBOTICSLAB_VOCAB('w','a','i','t') ///< Wait motion done
#define VOCAB_CC_TOOL ROBOTICSLAB_VOCAB('t','o','o','l') ///< Change tool
#define VOCAB_CC_ACT ROBOTICSLAB_VOCAB('a','c','t',0) ///< Actuate tool

/** @} */

Expand Down Expand Up @@ -99,6 +100,22 @@

/** @} */

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

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

/**
* @name Controller configuration vocabs
*
Expand Down Expand Up @@ -296,6 +313,17 @@ class ICartesianControl
*/
virtual bool tool(const std::vector<double> &x) = 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;

/** @} */

//--------------------- Streaming commands ---------------------
Expand Down
1 change: 1 addition & 0 deletions programs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# programs

add_subdirectory(haarDetectionController)
add_subdirectory(keyboardController)
add_subdirectory(streamingDeviceController)
add_subdirectory(transCoords)
30 changes: 30 additions & 0 deletions programs/haarDetectionController/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if(NOT ROBOTICSLAB_YARP_DEVICES_FOUND AND (NOT DEFINED ENABLE_haarDetectionController OR ENABLE_haarDetectionController))
message(WARNING "ROBOTICSLAB_YARP_DEVICES package not found, disabling haarDetectionController program")
endif()

cmake_dependent_option(ENABLE_haarDetectionController "Enable/disable haarDetectionController program" ON
ROBOTICSLAB_YARP_DEVICES_FOUND OFF)

if(ENABLE_haarDetectionController)

add_executable(haarDetectionController main.cpp
HaarDetectionController.hpp
HaarDetectionController.cpp
GrabberResponder.hpp
GrabberResponder.cpp)

target_link_libraries(haarDetectionController YARP::YARP_OS
YARP::YARP_init
YARP::YARP_dev
ROBOTICSLAB::ColorDebug
KinematicsDynamicsInterfaces
ROBOTICSLAB::YarpDevicesInterfaces)

install(TARGETS haarDetectionController
DESTINATION ${CMAKE_INSTALL_BINDIR})

else()

set(ENABLE_haarDetectionController OFF CACHE BOOL "Enable/disable haarDetectionController program" FORCE)

endif()
71 changes: 71 additions & 0 deletions programs/haarDetectionController/GrabberResponder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

#include "GrabberResponder.hpp"

#include <cmath>
#include <vector>

#include <ColorDebug.h>

namespace
{
const double STEP_X = 0.0001;
const double STEP_Y = 0.0001;
const double STEP_Z = 0.01;

// just in case, not used by now
const double DEADBAND_X_PX = 0.0;
const double DEADBAND_Y_PX = 0.0;
}

void roboticslab::GrabberResponder::onRead(yarp::os::Bottle &b)
{
CD_DEBUG("Got: %s\n", b.toString().c_str());

if (b.size() != 2)
{
CD_WARNING("Wrong data size: %d (expected: 2).\n", b.size());
return;
}

const double input_x = b.get(0).asFloat64();
const double input_y = b.get(1).asFloat64();

double target_x = 0.0;
double target_y = 0.0;

bool move = false;

if (std::abs(input_x) > DEADBAND_X_PX)
{
target_x = input_x * STEP_X;
move = true;
}

if (std::abs(input_y) > DEADBAND_Y_PX)
{
target_y = input_y * STEP_Y;
move = true;
}

if (move)
{
std::vector<double> xdot(6);
xdot[0] = target_x;
xdot[1] = -target_y; // inverted for AMOR
xdot[2] = noApproach ? 0.0 : STEP_Z;

iCartesianControl->twist(xdot);

isStopped = false;
}
else if (!isStopped)
{
iCartesianControl->stopControl();
isStopped = true;
}
else
{
isStopped = true;
}
}
50 changes: 50 additions & 0 deletions programs/haarDetectionController/GrabberResponder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

#ifndef __GRABBER_RESPONDER_HPP__
#define __GRABBER_RESPONDER_HPP__

#include <yarp/os/Bottle.h>
#include <yarp/os/PortReaderBuffer.h>

#include "ICartesianControl.h"

namespace roboticslab
{

/**
* @ingroup haarDetectionController
*
* @brief Callback class for dealing with incoming grabber
* data streams.
*/
class GrabberResponder : public yarp::os::TypedReaderCallback<yarp::os::Bottle>
{
public:

GrabberResponder() : iCartesianControl(NULL),
isStopped(true),
noApproach(false)
{}

virtual void onRead(yarp::os::Bottle &b);

void setICartesianControlDriver(roboticslab::ICartesianControl *iCartesianControl)
{
this->iCartesianControl = iCartesianControl;
}

void setNoApproachSetting(bool noApproach)
{
this->noApproach = noApproach;
}

private:

roboticslab::ICartesianControl *iCartesianControl;

bool isStopped, noApproach;
};

} // namespace roboticslab

#endif // __GRABBER_RESPONDER_HPP__
Loading