Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.

Commit 7cde562

Browse files
JorisWeedamartijnvandermarelRoelemansOlavhaasie
authored andcommitted
Feature/pm 203 new imc initialization (#191)
* Removed the reset IMC until they work function for a single reset of all the IMC's. * Added try catch to the update of the hardware_interface_node to be certain that the ethercat master gets deconstructed. * Added boundaries to the encode reset to check not only on an angle-value of 0. * fixed clang8 format fail. * Updated format to match the cpp style guide * Removed space after public declaration of class. * Added include string. Co-authored-by: martijnvandermarel <martijn.vander.marel@hetnet.nl> Co-authored-by: Roelemans <47626418+Roelemans@users.noreply.github.com> Co-authored-by: Olav de Haas <olavh@protonmail.com>
1 parent d17b615 commit 7cde562

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

march_hardware/include/march_hardware/MarchRobot.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ class MarchRobot
1919
private:
2020
std::unique_ptr<EthercatMaster> ethercatMaster;
2121
std::unique_ptr<PowerDistributionBoard> powerDistributionBoard;
22-
23-
public:
2422
::std::vector<Joint> jointList;
2523

24+
public:
2625
MarchRobot(::std::vector<Joint> jointList, ::std::string ifName, int ecatCycleTime);
2726

2827
MarchRobot(::std::vector<Joint> jointList, PowerDistributionBoard powerDistributionBoard, ::std::string ifName,

march_hardware_interface/include/march_hardware_interface/march_hardware_interface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace march_hardware_interface
2626
{
2727
static const double POSITION_STEP_FACTOR = 10;
2828
static const double VELOCITY_STEP_FACTOR = 10;
29+
static const int LOWER_BOUNDARY_ANGLE_IU = -2;
30+
static const int UPPER_BOUNDARY_ANGLE_IU = 2;
2931

3032
/**
3133
* @brief HardwareInterface to allow ros_control to actuate our hardware.
@@ -84,7 +86,7 @@ class MarchHardwareInterface : public march_hardware_interface::MarchHardware
8486
void updatePowerDistributionBoard();
8587
void updateAfterLimitJointCommand();
8688
void updateIMotionCubeState();
87-
void resetIMotionCubesUntilTheyWork();
89+
void initiateIMC();
8890
void outsideLimitsCheck(int joint_index);
8991
void iMotionCubeStateCheck(int joint_index);
9092
};

march_hardware_interface/src/march_hardware_interface.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <joint_limits_interface/joint_limits_interface.h>
55
#include <joint_limits_interface/joint_limits_urdf.h>
66
#include <sstream>
7+
#include <string>
78

89
#include <march_hardware/MarchRobot.h>
910
#include <march_hardware/Joint.h>
@@ -23,6 +24,7 @@ using joint_limits_interface::JointLimits;
2324
using joint_limits_interface::PositionJointSoftLimitsHandle;
2425
using joint_limits_interface::PositionJointSoftLimitsInterface;
2526
using joint_limits_interface::SoftJointLimits;
27+
using march4cpp::Joint;
2628

2729
namespace march_hardware_interface
2830
{
@@ -84,7 +86,7 @@ void MarchHardwareInterface::init()
8486
soft_limits_[i] = soft_limits;
8587
}
8688

87-
resetIMotionCubesUntilTheyWork();
89+
initiateIMC();
8890

8991
// Print all joint positions on startup in case initialization fails.
9092
this->read();
@@ -123,7 +125,7 @@ void MarchHardwareInterface::init()
123125
{
124126
marchRobot.getPowerDistributionBoard()->getHighVoltage().setNetOnOff(true, netNumber);
125127
usleep(100000);
126-
ROS_INFO_THROTTLE(1, "[%s] Waiting on high voltage", joint_names_[i].c_str());
128+
ROS_WARN("[%s] Waiting on high voltage", joint_names_[i].c_str());
127129
}
128130
}
129131
}
@@ -317,33 +319,34 @@ void MarchHardwareInterface::write(const ros::Duration& elapsed_time)
317319
}
318320
}
319321

320-
void MarchHardwareInterface::resetIMotionCubesUntilTheyWork()
322+
void MarchHardwareInterface::initiateIMC()
321323
{
322-
bool encoderSetCorrectly = false;
323-
324-
while (!encoderSetCorrectly)
324+
ROS_INFO("Resetting all IMC on initialization");
325+
for (const std::string& joint_name : joint_names_)
325326
{
326-
encoderSetCorrectly = true;
327-
for (int i = 0; i < num_joints_; ++i)
327+
Joint joint = marchRobot.getJoint(joint_name);
328+
329+
if (LOWER_BOUNDARY_ANGLE_IU <= joint.getAngleIU() && joint.getAngleIU() <= UPPER_BOUNDARY_ANGLE_IU)
328330
{
329-
march4cpp::Joint joint = marchRobot.getJoint(joint_names_[i]);
330-
if (joint.getAngleIU() == 0)
331-
{
332-
ROS_ERROR("[%s] Failed (encoder reset)", joint_names_[i].c_str());
333-
encoderSetCorrectly = false;
334-
}
331+
ROS_WARN("Before reset joint: [%s] has angle-value of: %i. Which is within boundary of lower: %i and upper: %i",
332+
joint_name.c_str(), joint.getAngleIU(), LOWER_BOUNDARY_ANGLE_IU, UPPER_BOUNDARY_ANGLE_IU);
335333
}
336-
if (!encoderSetCorrectly)
334+
335+
joint.resetIMotionCube();
336+
}
337+
338+
ROS_INFO("Restarting EtherCAT");
339+
marchRobot.stopEtherCAT();
340+
marchRobot.startEtherCAT();
341+
342+
for (const std::string& joint_name : joint_names_)
343+
{
344+
Joint joint = marchRobot.getJoint(joint_name);
345+
346+
if (LOWER_BOUNDARY_ANGLE_IU <= joint.getAngleIU() && joint.getAngleIU() <= UPPER_BOUNDARY_ANGLE_IU)
337347
{
338-
// TODO(Martijn) check if you need to reset all joints.
339-
for (int i = 0; i < num_joints_; ++i)
340-
{
341-
march4cpp::Joint joint = marchRobot.getJoint(joint_names_[i]);
342-
joint.resetIMotionCube();
343-
}
344-
ROS_INFO("Restarting EtherCAT");
345-
marchRobot.stopEtherCAT();
346-
marchRobot.startEtherCAT();
348+
ROS_WARN("After reset joint: [%s] has angle-value of: %i. Which is within boundary of lower: %i and upper: %i",
349+
joint_name.c_str(), joint.getAngleIU(), LOWER_BOUNDARY_ANGLE_IU, UPPER_BOUNDARY_ANGLE_IU);
347350
}
348351
}
349352
}

march_hardware_interface/src/march_hardware_interface_node.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,19 @@ int main(int argc, char** argv)
3232

3333
const double loop_hz = ros::param::param("~loop_hz", 100.0);
3434
ros::Rate rate(loop_hz);
35+
3536
while (ros::ok())
3637
{
37-
march.update(rate.expectedCycleTime());
38-
rate.sleep();
38+
try
39+
{
40+
march.update(rate.expectedCycleTime());
41+
rate.sleep();
42+
}
43+
catch (const std::exception& e)
44+
{
45+
ROS_FATAL("Hardware interface caught an exception during update: %s", e.what());
46+
return 1;
47+
}
3948
}
4049

4150
return 0;

0 commit comments

Comments
 (0)