-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOpenSotCartesian.cpp
More file actions
81 lines (63 loc) · 2.4 KB
/
OpenSotCartesian.cpp
File metadata and controls
81 lines (63 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "opensot/OpenSotCartesian.h"
using namespace XBot::Cartesian;
OpenSotCartesianAdapter::OpenSotCartesianAdapter(TaskDescription::Ptr task,
Context::ConstPtr context):
OpenSotTaskAdapter(task, context)
{
_ci_cart = std::dynamic_pointer_cast<CartesianTask>(task);
if(!_ci_cart) throw std::runtime_error("Provided task description "
"does not have expected type 'CartesianTask'");
}
TaskPtr OpenSotCartesianAdapter::constructTask()
{
_opensot_cart = SotUtils::make_shared<CartesianSoT>(_ci_cart->getName(),
const_cast<ModelInterface&>(*_model),
_ci_cart->getDistalLink(),
_ci_cart->getBaseLink());
return _opensot_cart;
}
bool OpenSotCartesianAdapter::initialize(const OpenSoT::OptvarHelper& vars)
{
if(vars.getAllVariables().size() > 0)
{
throw BadVariables("[OpenSotCartesianAdapter] requires default variables definition");
}
bool ret = OpenSotTaskAdapter::initialize(vars);
if(!ret) return false;
/* Cartesian task specific parameters */
_opensot_cart->rotateToLocal(_ci_cart->isSubtaskLocal());
/* Register observer */
auto this_shared_ptr = std::dynamic_pointer_cast<OpenSotCartesianAdapter>(shared_from_this());
_ci_cart->registerObserver(this_shared_ptr);
return true;
}
void OpenSotCartesianAdapter::update(double time, double period)
{
// note: this will update lambda
OpenSotTaskAdapter::update(time, period);
// we implement velocity control by forcing lambda = 0.0
auto ctrl = _ci_cart->getControlMode();
if(ctrl == ControlType::Velocity)
{
_opensot_cart->setLambda(0.0);
}
/* Update reference */
Eigen::Affine3d Tref;
Eigen::Vector6d vref;
_ci_cart->getPoseReference(Tref, &vref);
if(_ci_cart->isVelocityLocal())
{
_opensot_cart->setReference(Tref);
_opensot_cart->setVelocityLocalReference(vref*_ctx->params()->getControlPeriod());
}
else
_opensot_cart->setReference(Tref, vref*_ctx->params()->getControlPeriod());
}
bool OpenSotCartesianAdapter::onBaseLinkChanged()
{
return _opensot_cart->setBaseLink(_ci_cart->getBaseLink());
}
bool OpenSotCartesianAdapter::onControlModeChanged()
{
return true;
}