Skip to content

Commit f9523fc

Browse files
committed
Fix force sign and clarify method contract
1 parent be7289c commit f9523fc

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

libraries/YarpPlugins/AmorCartesianControl/AmorCartesianControl.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AmorCartesianControl : public yarp::dev::DeviceDriver,
4141
bool movl(const std::vector<double> & xd) override;
4242
bool movv(const std::vector<double> & xdotd) override;
4343
bool gcmp() override;
44-
bool forc(const std::vector<double> & td) override;
44+
bool forc(const std::vector<double> & fd) override;
4545
bool stopControl() override;
4646
bool wait(double timeout) override;
4747
bool tool(const std::vector<double> & x) override;

libraries/YarpPlugins/AmorCartesianControl/ICartesianControlImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ bool AmorCartesianControl::gcmp()
252252

253253
// -----------------------------------------------------------------------------
254254

255-
bool AmorCartesianControl::forc(const std::vector<double> &td)
255+
bool AmorCartesianControl::forc(const std::vector<double> &fd)
256256
{
257257
yCWarning(AMOR) << "forc() not implemented";
258258
return false;

libraries/YarpPlugins/BasicCartesianControl/BasicCartesianControl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class BasicCartesianControl : public yarp::dev::DeviceDriver,
120120
bool movl(const std::vector<double> & xd) override;
121121
bool movv(const std::vector<double> & xdotd) override;
122122
bool gcmp() override;
123-
bool forc(const std::vector<double> & td) override;
123+
bool forc(const std::vector<double> & fd) override;
124124
bool stopControl() override;
125125
bool wait(double timeout) override;
126126
bool tool(const std::vector<double> & x) override;
@@ -215,7 +215,7 @@ class BasicCartesianControl : public yarp::dev::DeviceDriver,
215215
std::vector<std::unique_ptr<KDL::Trajectory>> trajectories;
216216

217217
/** FORC desired Cartesian force */
218-
std::vector<double> td;
218+
std::vector<double> fd;
219219

220220
int encoderErrors {0};
221221
std::atomic_bool cmcSuccess;

libraries/YarpPlugins/BasicCartesianControl/ICartesianControlImpl.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <cmath> //-- std::abs
66

77
#include <algorithm> // std::transform
8+
#include <functional> // std::negate
9+
#include <iterator> // std::back_inserter
810
#include <vector>
911

1012
#include <yarp/os/LogStream.h>
@@ -301,7 +303,6 @@ bool BasicCartesianControl::movv(const std::vector<double> &xdotd)
301303

302304
bool BasicCartesianControl::gcmp()
303305
{
304-
//-- Set torque mode and set state which makes periodic thread implement control.
305306
if (!setControlModes(VOCAB_CM_TORQUE))
306307
{
307308
yCError(BCC) << "Unable to set torque mode";
@@ -314,7 +315,7 @@ bool BasicCartesianControl::gcmp()
314315

315316
// -----------------------------------------------------------------------------
316317

317-
bool BasicCartesianControl::forc(const std::vector<double> &td)
318+
bool BasicCartesianControl::forc(const std::vector<double> &fd)
318319
{
319320
yCWarning(BCC) << "FORC mode still experimental";
320321

@@ -324,8 +325,11 @@ bool BasicCartesianControl::forc(const std::vector<double> &td)
324325
return false;
325326
}
326327

327-
//-- Set torque mode and set state which makes periodic thread implement control.
328-
this->td = td;
328+
this->fd.clear();
329+
330+
// negate since the solver contract interprets the wrench as an external force applied on the
331+
// end-effector, whereas the controller's contract interprets it as a force exerted by us
332+
std::transform(fd.cbegin(), fd.cend(), std::back_inserter(this->fd), std::negate<>());
329333

330334
if (!setControlModes(VOCAB_CM_TORQUE))
331335
{

libraries/YarpPlugins/BasicCartesianControl/PeriodicThreadImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void BasicCartesianControl::handleForc(const std::vector<double> &q, const std::
346346

347347
std::vector<double> t(numJoints);
348348

349-
if (!iCartesianSolver->invDyn(q, qdot, qdotdot, td, t, referenceFrame))
349+
if (!iCartesianSolver->invDyn(q, qdot, qdotdot, fd, t, referenceFrame))
350350
{
351351
yCWarning(BCC) << "invDyn() failed";
352352
return;

libraries/YarpPlugins/CartesianControlClient/CartesianControlClient.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CartesianControlClient : public yarp::dev::DeviceDriver,
6161
bool movl(const std::vector<double> &xd) override;
6262
bool movv(const std::vector<double> &xdotd) override;
6363
bool gcmp() override;
64-
bool forc(const std::vector<double> &td) override;
64+
bool forc(const std::vector<double> &fd) override;
6565
bool stopControl() override;
6666
bool wait(double timeout) override;
6767
bool tool(const std::vector<double> &x) override;

libraries/YarpPlugins/CartesianControlClient/ICartesianControlImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ bool roboticslab::CartesianControlClient::gcmp()
225225

226226
// -----------------------------------------------------------------------------
227227

228-
bool roboticslab::CartesianControlClient::forc(const std::vector<double> &td)
228+
bool roboticslab::CartesianControlClient::forc(const std::vector<double> &fd)
229229
{
230-
return handleRpcConsumerCmd(VOCAB_CC_FORC, td);
230+
return handleRpcConsumerCmd(VOCAB_CC_FORC, fd);
231231
}
232232

233233
// -----------------------------------------------------------------------------

libraries/YarpPlugins/ICartesianControl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ class ICartesianControl
254254
*
255255
* Apply desired forces in task space.
256256
*
257-
* @param td 6-element vector describing desired forces in cartesian space; first
258-
* three elements denote translational acceleration (meters/second²), last three
259-
* denote angular acceleration (radians/second²).
257+
* @param fd 6-element vector describing desired force exerted by the TCP in
258+
* cartesian space; first three elements denote linear force (Newton), last
259+
* three denote torque (Newton*meters).
260260
*
261261
* @return true on success, false otherwise
262262
*/
263-
virtual bool forc(const std::vector<double> &td) = 0;
263+
virtual bool forc(const std::vector<double> &fd) = 0;
264264

265265
/**
266266
* @brief Stop control

0 commit comments

Comments
 (0)