-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOpenSotGaze.cpp
More file actions
76 lines (58 loc) · 2.11 KB
/
OpenSotGaze.cpp
File metadata and controls
76 lines (58 loc) · 2.11 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
#include "opensot/OpenSotGaze.h"
using namespace XBot::Cartesian;
OpenSotGazeAdapter::OpenSotGazeAdapter(TaskDescription::Ptr task,
Context::ConstPtr context):
OpenSotTaskAdapter(task, context)
{
_ci_cart = std::dynamic_pointer_cast<GazeTask>(task);
if(!_ci_cart) throw std::runtime_error("Provided task description "
"does not have expected type 'GazeTask'");
}
TaskPtr OpenSotGazeAdapter::constructTask()
{
Eigen::VectorXd q;
_model->getJointPosition(q);
_opensot_cart = SotUtils::make_shared<GazeSoT>(_ci_cart->getName(),
q,
const_cast<ModelInterface&>(*_model),
_ci_cart->getBaseLink(),
_ci_cart->getDistalLink());
return _opensot_cart;
}
bool OpenSotGazeAdapter::initialize(const OpenSoT::OptvarHelper& vars)
{
if(vars.getAllVariables().size() > 0)
{
throw BadVariables("[OpenSotGazeAdapter] requires default variables definition");
}
bool ret = OpenSotTaskAdapter::initialize(vars);
if(!ret) return false;
/* Register observer */
auto this_shared_ptr = std::dynamic_pointer_cast<OpenSotGazeAdapter>(shared_from_this());
_ci_cart->registerObserver(this_shared_ptr);
return true;
}
void OpenSotGazeAdapter::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);
_opensot_cart->setGaze(Tref);
}
bool OpenSotGazeAdapter::onBaseLinkChanged()
{
return _opensot_cart->setBaseLink(_ci_cart->getBaseLink());
}
bool OpenSotGazeAdapter::onControlModeChanged()
{
return true;
}