-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsin dance cpp
185 lines (108 loc) · 3.83 KB
/
sin dance cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "Backpack_controller.h"
#include <mc_solver/ConstraintSetLoader.h>
//#include <iostream>
//#include <cmath>
using namespace std;
Backpack_controller::Backpack_controller(mc_rbdyn::RobotModulePtr rm, double dt, const mc_rtc::Configuration & config)
: mc_control::MCController(rm, dt)
{
config_.load(config);
static auto constraint = mc_solver::ConstraintSetLoader::load(solver(),config("collisions")[0]);
solver().addConstraintSet(*constraint);
solver().addConstraintSet(contactConstraint);
solver().addConstraintSet(dynamicsConstraint);
solver().addTask(postureTask);
//solver().addTask(armTask);
solver().setContacts({
{robots(), 0, 1, "LeftFoot", "AllGround"},
{robots(), 0, 1, "RightFoot", "AllGround"}
});
m_deltaTime = dt;
m_amplitude = 0.5;
m_frequency = 1;
m_phase = 0.0;
m_time = 0.0;
/*void selectActiveJoints(mc_solver::QPSolver & solver,
const std::vector<std::string> & activeJointsName);
std::vector<std::string> activeJoints = {"R_SHOULDER_R", "L_SHOULDER_R"};
auto postureTask = std::make_shared<mc_task::postureTask>(robots(), 0);
postureTask->selectActiveJoints(solver(), activeJoints);
*/
comTask = std::make_shared<mc_tasks::CoMTask>(robots(), 0, 10.0, 2000.0);
solver().addTask(comTask);
postureTask->stiffness(1);
/*armTask = std::make_shared<mc_tasks::PostureTask>(solver(), robots().robotIndex(), 100, 10);
armTask->selectActiveJoints(solver(), {"R_SHOULDER_R", "L_SHOULDER_R"}); */
/*end effector task
efTask = std::make_shared<mc_tasks::EndEffectorTask>("l_wrist", robots(), 0, 5.0, 500.0);
solver().addTask(efTask); */
mc_rtc::log::success("Backpack_controller init done ");
}
bool Backpack_controller::run()
{
// if(armTask->eval().norm() < 1)
// {
// switch_target();
// }
//auto arm_posture = robot().mbc().q;
double t = count * m_deltaTime;
double omega = 2*M_PI*m_frequency;
double value = m_amplitude*std::sin(t*omega + m_phase);
comTask->com(comZero + value*Eigen::Vector3d{0, 0.1, 0});
/*
arm_posture[rightShoulderIndex][0] = value ;
arm_posture[leftShoulderIndex][0] = m_amplitude- value;
armTask->posture(arm_posture); */
// if(comTask->eval().norm() < 1)
// {
// switch_com_target();
// }
/* avec Ef
if(efTask->eval().norm() < 0.1)
{
switch_ef_target();
} */
return mc_control::MCController::run();
}
void Backpack_controller::reset(const mc_control::ControllerResetData & reset_data)
{
mc_control::MCController::reset(reset_data);
comTask->reset();
//armTask->reset();
comZero = comTask->com();
//print ComZero
// mc_rtc::log::info("current coM= {}", comZero);
//avec End Effector
//efTask ->reset();
}
/* void Backpack_controller::parameters()
{
// initialize values
m_amplitude = 0.5;
m_frequency = 1;
m_phase = 0.0;
m_time = 0.0;
m_deltaTime = 1 /m_time;
}
void Backpack_controller::switch_target()
{
for (int omega = 0; omega < 1000; ++omega) {
value = m_amplitude * sin(2 * M_PI * m_frequency * m_time + m_phase);
m_time += m_deltaTime;
}
auto arm_posture = robot().mbc().q;
arm_posture[rightShoulderIndex][0] = value ;
arm_posture[leftShoulderIndex][0] = value + m_phase ;
armTask->posture(arm_posture);
}
void Backpack_controller::switch_com_target()
{
comTask->com(comZero + value*Eigen::Vector3d{0, 0.1, 0});
} */
/*avec EF
void Backpack_controller::switch_ef_target()
{
auto pt = efTask->get_ef_pose();
efTask->set_ef_pose(sva::PTransformd{sva::RotY(-M_PI/2), Eigen::Vector3d{0.5, -0.5, 1.2}});
} */
CONTROLLER_CONSTRUCTOR("Backpack_controller", Backpack_controller)