Skip to content

Improve fault tolerance of logic showing connected motors. #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/Braccio++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,26 @@ void BraccioClass::setMotorConnectionStatus(int const id, bool const is_connecte

void BraccioClass::motorConnectedThreadFunc()
{
int next_id_to_be_pinged = SmartServoClass::MIN_MOTOR_ID;
int servo_missed_ping_cnt[SmartServoClass::NUM_MOTORS] = {0};

static int const MAX_MISSED_PING_CNT = 2;

for (;;)
{
if (isPingAllowed())
{
for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++)
{
bool const is_connected = (_servos.ping(id) == 0);
setMotorConnectionStatus(id, is_connected);
}
bool const is_connected = (_servos.ping(next_id_to_be_pinged) == 0);

if (!is_connected) servo_missed_ping_cnt[SmartServoClass::idToArrayIndex(next_id_to_be_pinged)]++;
else servo_missed_ping_cnt[SmartServoClass::idToArrayIndex(next_id_to_be_pinged)] = 0;

if (servo_missed_ping_cnt[SmartServoClass::idToArrayIndex(next_id_to_be_pinged)] >= MAX_MISSED_PING_CNT)
setMotorConnectionStatus(next_id_to_be_pinged, false);
else
setMotorConnectionStatus(next_id_to_be_pinged, true);

next_id_to_be_pinged = (next_id_to_be_pinged < SmartServoClass::MAX_MOTOR_ID) ? next_id_to_be_pinged + 1 : SmartServoClass::MIN_MOTOR_ID;

for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++) {
if (connected(id))
Expand All @@ -359,7 +370,7 @@ void BraccioClass::motorConnectedThreadFunc()
expander_setRed(id);
}
}
delay(1000);
delay(500);
}
}

Expand Down