Skip to content

Commit

Permalink
changed motor timeout to ros param
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypt1cG committed Nov 24, 2024
1 parent 899b524 commit d3c4b2d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/simulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ simulator:
save_rate: 1.0
save_history: 4096
headless: false
motor_timeout: 100

ref_heading: 90.0 # For the GPS sensor to work

Expand Down
2 changes: 2 additions & 0 deletions simulator/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace mrover {

mIkTargetPub = create_publisher<msg::IK>("arm_ik", 1);

mMotorTimeoutMs = get_parameter("motor_timeout").as_int();

mIsHeadless = get_parameter("headless").as_bool();
mEnablePhysics = mIsHeadless;
{
Expand Down
2 changes: 2 additions & 0 deletions simulator/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ namespace mrover {
R3d mOrientationDrift = R3d::Zero();

bool mIsHeadless{};

int64_t mMotorTimeoutMs{};

// Rendering

Expand Down
4 changes: 1 addition & 3 deletions simulator/simulator.physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace mrover {

constexpr double TAU = 2 * std::numbers::pi;

constexpr int MOTOR_TIMEOUT_MS = 20;

auto btTransformToSe3(btTransform const& transform) -> SE3d {
btVector3 const& p = transform.getOrigin();
btQuaternion const& q = transform.getRotation();
Expand Down Expand Up @@ -58,7 +56,7 @@ namespace mrover {
// check if arm motor commands have expired
// TODO: fix hard-coded names?
for (auto const& name: {"arm_a_link", "arm_b_link", "arm_c_link", "arm_d_link", "arm_e_link"}) {
bool expired = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - rover.linkNameToMeta.at(name).lastUpdate).count() > MOTOR_TIMEOUT_MS;
bool expired = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - rover.linkNameToMeta.at(name).lastUpdate).count() > mMotorTimeoutMs;
if (expired) {
int linkIndex = rover.linkNameToMeta.at(name).index;
auto* motor = std::bit_cast<btMultiBodyJointMotor*>(rover.physics->getLink(linkIndex).m_userPtr);
Expand Down

0 comments on commit d3c4b2d

Please sign in to comment.