53 const uint32_t& reset_timeout)
57 , m_connection_feedback_given(false)
58 , m_homing_timeout(10)
72 , m_reset_speed_factor(0.2)
73 , m_reset_timeout(reset_timeout)
79 , m_serial_device(
"/dev/ttyUSB0")
104 <<
" was disabled as per user request. It will not do anything!");
137 "Finger manager is trying to connect to the Hardware...");
152 unsigned int num_retries = retry_count;
180 auto start_time = std::chrono::high_resolution_clock::now();
181 bool timeout =
false;
182 unsigned int received_count = 0;
183 unsigned int send_count = 0;
188 if (send_count == received_count)
192 "Successfully established connection to SCHUNK five finger hand."
193 <<
"Send packages = " << send_count
194 <<
", received packages = " << received_count);
197 "Try to connect to SCHUNK five finger hand: Send packages = "
198 << send_count <<
", received packages = " << received_count);
201 if ((std::chrono::high_resolution_clock::now() - start_time) >
m_reset_timeout)
205 "Connection timeout! Could not connect to SCHUNK five finger hand."
206 <<
"Send packages = " << send_count
207 <<
", received packages = " << received_count);
209 std::this_thread::sleep_for(std::chrono::microseconds(50000));
215 if (received_count > 0 && num_retries >= 0)
219 "Connection Failed! Send packages = "
220 << send_count <<
", received packages = " << received_count
221 <<
". Retrying, count: " << num_retries);
227 "Connection Failed! Send packages = "
228 << send_count <<
", received packages = " << received_count
229 <<
". Not Retrying anymore.");
239 "A Stable connection could NOT be made, however some packages where "
240 "received. Please check the hardware!");
258 "Finger manager is starting the fedback polling thread");
278 "Finger manager is trying to discoconnect to the Hardware...");
305 bool reset_all_success =
true;
309 size_t max_reset_counter = 3;
310 bool reset_success =
false;
311 while (!reset_success && max_reset_counter > 0)
319 "resetChannel",
"Channel " <<
m_reset_order[i] <<
" reset success = " << reset_success);
322 reset_all_success = reset_all_success && reset_success;
325 return reset_all_success;
337 "Setting reset position values for controller of channel " << channel);
353 int32_t position = 0;
357 position =
static_cast<int32_t
>(pos_set.
wmx);
361 position =
static_cast<int32_t
>(pos_set.
wmn);
366 << channel <<
" to hardstop. Detection thresholds: Current MIN: "
377 auto start_time = std::chrono::high_resolution_clock::now();
378 auto start_time_log = std::chrono::high_resolution_clock::now();
380 bool stale_notification_sent =
false;
382 for (
size_t hit_count = 0; hit_count < 10;)
390 if (std::chrono::duration_cast<std::chrono::milliseconds>(
391 std::chrono::high_resolution_clock::now() - start_time_log) >
392 std::chrono::milliseconds(1000))
397 <<
" current: " << control_feedback.
current <<
" mA");
398 start_time_log = std::chrono::high_resolution_clock::now();
401 double threshold = 80;
408 if (delta <= -threshold)
419 if (delta >= threshold)
451 <<
" Hit Count increased: " << hit_count);
453 else if (hit_count > 0)
459 <<
" Hit Count Decreased: " << hit_count);
463 if ((std::chrono::high_resolution_clock::now() - start_time) >
m_homing_timeout)
467 "Timeout: Aborted finding home position for channel " << channel);
482 start_time = std::chrono::high_resolution_clock::now();
483 if (stale_notification_sent)
489 <<
" Stale resolved, continuing detection");
490 stale_notification_sent =
false;
495 if (!stale_notification_sent)
501 <<
" Stale detected. Starting Timeout");
502 stale_notification_sent =
true;
507 control_feedback_previous = control_feedback;
514 <<
" current: " << control_feedback.
current <<
" mA");
527 "Setting soft stops for Channel "
537 start_time = std::chrono::high_resolution_clock::now();
547 <<
" current: " << control_feedback.
current
548 <<
" mA, position ticks: " << control_feedback.
position);
550 if (abs(position - control_feedback.
position) < 1000)
558 if ((std::chrono::high_resolution_clock::now() - start_time) >
m_homing_timeout)
562 "Channel " << channel <<
" home position is not reachable after "
564 <<
"s! There could be an hardware error!");
572 "Restoring default position values for controller of channel "
579 "Channel " << channel
580 <<
"switched of by user, homing is set to finished");
604 "Could not reset channel "
605 << channel <<
": No connection to SCHUNK five finger hand!");
627 "Could not get diagnostic status for unknown/unsupported channel "
688 bool all_disabled =
true;
708 "Feedback for channel "
709 << channel <<
" could not be requested. FM is not connected to HW.");
760 current = controller_feedback.
current;
781 bool reject_command =
false;
798 reject_command =
true;
812 "Could not set target position vector: At least one channel is out of bounds!");
819 "Size of target position vector wrong: size = "
820 << positions.size() <<
" expected size = " << (
int)
SVH_DIMENSION);
830 "Could not set target position vector: No connection to SCHUNK five finger hand!");
848 "Target position for channel "
849 << channel <<
" was ignored as it is switched off by the user");
876 "Target position for channel " << channel <<
" out of bounds!");
883 "Could not set target position for channel " << channel
884 <<
": Reset first!");
891 "Could not set target position for channel " << channel
892 <<
": Illegal Channel");
903 "Could not set target position for channel "
904 << channel <<
": No connection to SCHUNK five finger hand!");
916 bool all_enabled =
true;
948 "isEnabled was requested for UNKNOWN Channel: " << channel);
957 bool all_homed =
true;
964 "All finger homed check failed: Channel: "
981 "isHomed was requested for UNKNOWN Channel: " << channel);
996 "Could not get current settings for unknown/unsupported channel "
1012 "Could not get position settings for unknown/unsupported channel "
1028 "Could not get home settings for unknown/unsupported channel " << channel);
1036 bool settings_are_safe =
false;
1045 if (current_settings.
wmx <=
1050 settings_are_safe =
true;
1055 "Current value given: " << current_settings.
wmx <<
" is not valid.");
1058 " Please provide values between "
1070 return settings_are_safe;
1085 "WARNING!!! Current Controller Params for channel "
1086 << channel <<
" would be dangerous! Currents are limited!!!");
1104 "Could not set Current Controller Params for channel "
1105 << channel <<
": No such channel");
1131 "Could not set Position Controller Params for channel "
1132 << channel <<
": No such channel");
1146 "Channel " << channel <<
" setting new homing settings : ");
1148 "Direction " << home_settings.
direction <<
" "
1152 <<
"Range Rad " << home_settings.
range_rad <<
" "
1167 "Could not set homing settings for channel " << channel
1168 <<
": No such channel");
1189 "Diagnostic data for all channel reseted successfully");
1203 "Diagnostic data for channel " << channel <<
" reseted successfully");
1209 "Could not reset diagnostic data for channel " << channel
1210 <<
": No such channel");
1259 std::vector<SVHCurrentSettings> current_settings(
SVH_DIMENSION);
1266 -500.0f, 500.0f, 0.405f, 4e-6f, -25.0f, 25.0f, 0.6f, 10.0f, -255.0f, 255.0f);
1268 -500.0f, 500.0f, 0.405f, 4e-6f, -25.0f, 25.0f, 1.0f, 10.0f, -255.0f, 255.0f);
1270 -300.0f, 300.0f, 0.405f, 4e-6f, -25.0f, 25.0f, 1.0f, 10.0f, -255.0f, 255.0f);
1272 -350.0f, 350.0f, 0.405f, 4e-6f, -25.0f, 25.0f, 1.0f, 10.0f, -255.0f, 255.0f);
1274 -300.0f, 300.0f, 0.405f, 4e-6f, -10.0f, 10.0f, 1.0f, 25.0f, -255.0f, 255.0f);
1276 -500.0f, 500.0f, 0.405f, 4e-6f, -4.0f, 4.0f, 0.7f, 60.0f, -255.0f, 255.0f);
1284 : cur_set_thumb_opposition;
1287 : cur_set_distal_joint;
1291 : cur_set_proximal_joint;
1295 : cur_set_distal_joint;
1299 : cur_set_proximal_joint;
1302 : cur_set_outer_joint;
1304 : cur_set_outer_joint;
1307 : cur_set_finger_spread;
1309 return current_settings;
1318 std::vector<SVHPositionSettings> position_settings(
SVH_DIMENSION);
1329 -1.0e6f, 1.0e6f, 65.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.5f, 0.0f, 400.0f);
1331 -1.0e6f, 1.0e6f, 50.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.5f, 0.1f, 100.0f);
1333 -1.0e6f, 1.0e6f, 45.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.5f, 0.0f, 40.0f);
1335 -1.0e6f, 1.0e6f, 40.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.8f, 0.0f, 1000.0f);
1337 -1.0e6f, 1.0e6f, 45.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.5f, 0.0f, 10.0f);
1339 -1.0e6f, 1.0e6f, 40.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.8f, 0.0f, 1000.0f);
1341 -1.0e6f, 1.0e6f, 45.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.5f, 0.0f, 100.0f);
1343 -1.0e6f, 1.0e6f, 45.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.5f, 0.0f, 100.0f);
1345 -1.0e6f, 1.0e6f, 25.0e3f, 1.00f, 1e-3f, -500.0f, 500.0f, 0.5f, 0.0f, 100.0f);
1368 : pos_set_thumb_flexion;
1371 : pos_set_thumb_opposition;
1375 : pos_set_finger_index_distal;
1379 : pos_set_finger_index_proximal;
1383 : pos_set_finger_middle_distal;
1387 : pos_set_finger_middle_proximal;
1390 : pos_set_finger_ring;
1393 : pos_set_finger_pinky;
1408 return position_settings;
1413 if ((speed >= 0.0) && (speed <= 1.0))
1415 m_reset_speed_factor = speed;
1421 "The reset speed value given: "
1422 << speed <<
" is not valid. Please provide a value between 0.0 and 1.0, default is 0.2");
1429 int32_t target_position =
static_cast<int32_t
>(position /
m_ticks2rad[channel]);
1440 return target_position;
1446 int32_t cleared_position_ticks;
1457 return static_cast<double>(cleared_position_ticks *
m_ticks2rad[channel]);
1468 current =
static_cast<uint16_t
>(
1505 "Channel" << channel <<
" : "
1507 <<
" Target: " << target_position <<
"("
1523 (reset_timeout > 0) ? std::chrono::seconds(reset_timeout) : std::chrono::seconds(0);
1528 if (max_force > 0 && max_force <= 1)
1537 "Maximal Force / current should be in the range of [0,1], was set to: " << max_force);
1551 current_settings.
wmx = current;
1552 current_settings.
wmn = -
static_cast<float>(current);
1566 const unsigned int& retry_count)
1571 bool was_connected =
true;
1575 was_connected =
false;
1593 unsigned int num_retries = retry_count;
1599 std::this_thread::sleep_for(std::chrono::microseconds(100000));
1607 "Getting Firmware Version failed,.Retrying, count: " << num_retries);
1637 SVH_LOG_WARN_STREAM(
"SVHFeedbackPollingThread",
"SCHUNK five finger hand is not connected!");
1639 std::this_thread::sleep_for(std::chrono::milliseconds(100));