Skip to content

Commit

Permalink
Actuate gripper in KeyboardController
Browse files Browse the repository at this point in the history
So far only open/close gripper is enabled. Gripper won't stop if no key
is pressed.
  • Loading branch information
PeterBowman committed Oct 20, 2017
1 parent 8b67a5e commit 2257ac4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
47 changes: 45 additions & 2 deletions programs/keyboardController/KeyboardController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <yarp/os/Value.h>
#include <yarp/os/Property.h>
#include <yarp/os/Time.h>
#include <yarp/os/Vocab.h>

#include <ColorDebug.hpp>

Expand Down Expand Up @@ -220,14 +221,15 @@ bool roboticslab::KeyboardController::configure(yarp::os::ResourceFinder &rf)
cartesianThread->start(); // initialize the new thread
}

controlMode = NOT_CONTROLLING;
currentActuatorCommand = VOCAB_CC_ACTUATOR_NONE;

issueStop(); // just in case

ttyset();

printHelp();

controlMode = NOT_CONTROLLING;

return true;
}

Expand Down Expand Up @@ -354,6 +356,14 @@ bool roboticslab::KeyboardController::updateModule()
case 'm':
toggleReferenceFrame();
break;
// actuate tool (open gripper)
case 'k':
actuateTool(VOCAB_CC_ACTUATOR_OPEN_GRIPPER);
break;
// actuate tool (close gripper)
case 'l':
actuateTool(VOCAB_CC_ACTUATOR_CLOSE_GRIPPER);
break;
// issue stop
case 13: // enter
default:
Expand Down Expand Up @@ -515,6 +525,25 @@ void roboticslab::KeyboardController::toggleReferenceFrame()
std::cout << std::endl;
}

void roboticslab::KeyboardController::actuateTool(int command)
{
if (!cartesianControlDevice.isValid())
{
CD_WARNING("Unrecognized command (you chose not to launch cartesian controller client).\n");
issueStop();
return;
}

if (!iCartesianControl->act(command))
{
CD_ERROR("Unable to send '%s' command to actuator.\n", yarp::os::Vocab::decode(command).c_str());
}
else
{
currentActuatorCommand = command;
}
}

void roboticslab::KeyboardController::printJointPositions()
{
if (!controlboardDevice.isValid())
Expand Down Expand Up @@ -554,6 +583,18 @@ void roboticslab::KeyboardController::issueStop()
{
if (cartesianControlDevice.isValid())
{
if (currentActuatorCommand != VOCAB_CC_ACTUATOR_NONE)
{
if (!iCartesianControl->act(VOCAB_CC_ACTUATOR_STOP_GRIPPER))
{
CD_WARNING("Unable to stop actuator.\n");
}
else
{
currentActuatorCommand = VOCAB_CC_ACTUATOR_NONE;
}
}

if (!cartesianThread->isSuspended())
{
cartesianThread->suspend();
Expand Down Expand Up @@ -639,6 +680,8 @@ void roboticslab::KeyboardController::printHelp()

std::cout << " 'm' - toggle reference frame (current: ";
std::cout << (cartFrame == INERTIAL ? "inertial" : "end effector") << ")" << std::endl;

std::cout << " 'k'/'l' - open/close gripper" << std::endl;
}

std::cout << " [Enter] - issue stop" << std::endl;
Expand Down
3 changes: 3 additions & 0 deletions programs/keyboardController/KeyboardController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class KeyboardController : public yarp::os::RFModule

void toggleReferenceFrame();

void actuateTool(int command);

void printJointPositions();
void printCartesianPositions();

Expand All @@ -123,6 +125,7 @@ class KeyboardController : public yarp::os::RFModule
void printHelp();

int axes;
int currentActuatorCommand;

cart_frames cartFrame;
std::string angleRepr;
Expand Down

0 comments on commit 2257ac4

Please sign in to comment.