11 getParameter<uint8_t>(25, param_buffer,
hand_side);
23 std::this_thread::sleep_for(std::chrono::milliseconds(1));
29 std::this_thread::sleep_for(std::chrono::milliseconds(1));
30 if (!set_fail && param_type != 1) {
33 std::this_thread::sleep_for(std::chrono::milliseconds(1));
38 int set_fail =
setParameter(25, Communication::vectorSwapAndCast<int8_t, uint8_t>({hand_side}));
43 uint8_t previous_id =
params_->id;
45 std::this_thread::sleep_for(std::chrono::milliseconds(1));
51 std::this_thread::sleep_for(std::chrono::milliseconds(1));
56 std::vector<int16_t> positions;
60 std::this_thread::sleep_for(std::chrono::milliseconds(200));
61 std::vector<int16_t> offsets;
65 std::this_thread::sleep_for(std::chrono::milliseconds(200));
66 std::transform(offsets.begin(), offsets.end(), positions.begin(), offsets.begin(), std::minus<int16_t>());
79 std::for_each( encoder_offsets.begin()+2, encoder_offsets.end(), [](int16_t &x){x *= -1;} );
84 return getParamHandSide(std::dynamic_pointer_cast<qbrobotics_research_api::qbSoftHand2MotorsResearch::Params>(
params_)->hand_side);
88 std::vector<int8_t> param_buffer;
92 Params::getParameter<uint8_t>(25, param_buffer, hand_side);
97 std::vector<int8_t> data_in;
101 synergies = Communication::vectorCastAndSwap<int16_t>(data_in);
106 std::vector<int16_t> legacy_offsets = encoder_offsets;
108 std::for_each( legacy_offsets.begin()+2, legacy_offsets.end(), [](int16_t &x){ x *= -1; } );
113 auto const data_out = Communication::vectorSwapAndCast<int8_t, int16_t>({synergy_1, synergy_2});
121 if(synergy_1 < 0 || synergy_1 > 1 || synergy_2 < -1 || synergy_2 > 1) {
124 int32_t l =
getParams()->position_limits[0];
125 int32_t L =
getParams()->position_limits[1];
126 int32_t Lr = (L + l);
127 float Sf = (2/(float)Lr);
128 float mf = (1/(float)l);
130 int16_t q1 = (1 + synergy_2)*synergy_1/Sf - synergy_2/mf;
131 int16_t q2 = (1 - synergy_2)*synergy_1/Sf + synergy_2/mf;
133 std::vector<int16_t> refs{q1, q2};
140 std::vector<int16_t> synergies;
142 std::vector<int32_t> limits;
145 if(synergies.size() <= 0 || result < 0 || limits.size() < 4){
148 std::vector<std::vector<int>> synergies_references{{limits.at(0), 0}, {synergies.at(0), 0}};
149 std::vector<int> synergies_to_reach {-1000, 200};
151 int synergy_to_cancel = 1;
152 while(!synergies_references.empty()) {
156 auto t_start = std::chrono::high_resolution_clock::now();
157 auto t_end = t_start;
158 double elapsed_time_ms;
159 bool condition =
true;
162 if(synergy_to_cancel == 1) {
163 condition = std::abs(synergies.at(synergy_to_cancel)) > synergies_to_reach.back();
165 condition = synergies.at(synergy_to_cancel) > synergies_to_reach.back();
168 std::this_thread::sleep_for(std::chrono::milliseconds(1));
169 t_end = std::chrono::high_resolution_clock::now();
170 elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end-t_start).count();
171 if(elapsed_time_ms > 2000.0) {
176 synergies_references.pop_back();
177 synergies_to_reach.pop_back();
178 synergy_to_cancel --;