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

Commit 62bda03

Browse files
committed
Move init to main
1 parent cd79333 commit 62bda03

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

march_hardware/src/EtherCAT/EthercatMaster.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ EthercatMaster::EthercatMaster(std::vector<Joint>* jointListPtr, std::string ifn
3232

3333
EthercatMaster::~EthercatMaster()
3434
{
35-
std::cout << "Ethercat master has been deconstructed\n";
3635
this->stop();
3736
}
3837

@@ -79,7 +78,7 @@ void EthercatMaster::ethercatMasterInitiation()
7978
*/
8079
void EthercatMaster::ethercatSlaveInitiation()
8180
{
82-
ROS_INFO("Request per-operational state for all slaves");
81+
ROS_INFO("Request pre-operational state for all slaves");
8382
ec_statecheck(0, EC_STATE_PRE_OP, EC_TIMEOUTSTATE * 4);
8483

8584
for (auto& i : *jointListPtr)

march_hardware_interface/include/march_hardware_interface/march_hardware_interface.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class MarchHardwareInterface : public march_hardware_interface::MarchHardware
4242
* for each joint.
4343
*/
4444
void init();
45-
void update(const ros::TimerEvent& e);
45+
void update(const ros::Duration& elapsed_time);
4646

4747
/**
4848
* @brief Read actual postion from the hardware.
4949
*/
50-
void read(ros::Duration elapsed_time = ros::Duration(0.01));
50+
void read(const ros::Duration& elapsed_time = ros::Duration(0.01));
5151

5252
/**
5353
* @brief Perform all safety checks that might crash the exoskeleton.
@@ -58,18 +58,16 @@ class MarchHardwareInterface : public march_hardware_interface::MarchHardware
5858
* @brief Write position commands to the hardware.
5959
* @param elapsed_time Duration since last write action
6060
*/
61-
void write(ros::Duration elapsed_time);
61+
void write(const ros::Duration& elapsed_time);
6262

6363
protected:
6464
::march4cpp::MarchRobot marchRobot;
6565
ros::NodeHandle nh_;
66-
ros::Timer non_realtime_loop_;
6766
ros::Duration control_period_;
6867
ros::Duration elapsed_time_;
6968
PositionJointInterface positionJointInterface;
7069
PositionJointSoftLimitsInterface positionJointSoftLimitsInterface;
7170
EffortJointSoftLimitsInterface effortJointSoftLimitsInterface;
72-
double loop_hz_;
7371
bool hasPowerDistributionBoard = false;
7472
boost::shared_ptr<controller_manager::ControllerManager> controller_manager_;
7573
typedef boost::shared_ptr<realtime_tools::RealtimePublisher<march_shared_resources::ImcErrorState> > RtPublisherPtr;

march_hardware_interface/src/march_hardware_interface.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ namespace march_hardware_interface
2929
MarchHardwareInterface::MarchHardwareInterface(ros::NodeHandle& nh, AllowedRobot robotName)
3030
: nh_(nh), marchRobot(HardwareBuilder(robotName).createMarchRobot())
3131
{
32-
controller_manager_.reset(new controller_manager::ControllerManager(this, nh_));
33-
nh_.param("/march/hardware_interface/loop_hz", loop_hz_, 100.0);
34-
ros::Duration update_freq = ros::Duration(1.0 / loop_hz_);
35-
non_realtime_loop_ = nh_.createTimer(update_freq, &MarchHardwareInterface::update, this);
3632
}
3733

3834
void MarchHardwareInterface::init()
@@ -212,15 +208,15 @@ void MarchHardwareInterface::init()
212208
}
213209
}
214210
ROS_INFO("Successfully actuated all joints");
211+
controller_manager_.reset(new controller_manager::ControllerManager(this, nh_));
215212
}
216213

217-
void MarchHardwareInterface::update(const ros::TimerEvent& e)
214+
void MarchHardwareInterface::update(const ros::Duration& elapsed_time)
218215
{
219-
elapsed_time_ = ros::Duration(e.current_real - e.last_real);
220-
read(elapsed_time_);
216+
read(elapsed_time);
221217
validate();
222-
controller_manager_->update(ros::Time::now(), elapsed_time_);
223-
write(elapsed_time_);
218+
controller_manager_->update(ros::Time::now(), elapsed_time);
219+
write(elapsed_time);
224220
}
225221

226222
void MarchHardwareInterface::validate()
@@ -232,7 +228,7 @@ void MarchHardwareInterface::validate()
232228
}
233229
}
234230

235-
void MarchHardwareInterface::read(ros::Duration elapsed_time)
231+
void MarchHardwareInterface::read(const ros::Duration& elapsed_time)
236232
{
237233
for (int i = 0; i < num_joints_; i++)
238234
{
@@ -272,7 +268,7 @@ void MarchHardwareInterface::read(ros::Duration elapsed_time)
272268
}
273269
}
274270

275-
void MarchHardwareInterface::write(ros::Duration elapsed_time)
271+
void MarchHardwareInterface::write(const ros::Duration& elapsed_time)
276272
{
277273
joint_effort_command_copy.clear();
278274
joint_effort_command_copy.resize(joint_effort_command_.size());

march_hardware_interface/src/march_hardware_interface_node.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2019 Project March.
2+
#include <ros/ros.h>
23
#include <march_hardware_interface/march_hardware_interface.h>
34

45
int main(int argc, char** argv)
@@ -18,8 +19,24 @@ int main(int argc, char** argv)
1819
spinner.start();
1920

2021
march_hardware_interface::MarchHardwareInterface march(nh, selected_robot);
21-
march.init();
2222

23-
ros::waitForShutdown();
23+
try
24+
{
25+
march.init();
26+
}
27+
catch (const std::exception& e)
28+
{
29+
ROS_FATAL("Hardware interface caught an exception during init: %s", e.what());
30+
return 1;
31+
}
32+
33+
const double loop_hz = ros::param::param("~loop_hz", 100.0);
34+
ros::Rate rate(loop_hz);
35+
while (ros::ok())
36+
{
37+
march.update(rate.expectedCycleTime());
38+
rate.sleep();
39+
}
40+
2441
return 0;
2542
}

0 commit comments

Comments
 (0)