Skip to content

Commit ca12125

Browse files
author
Aart Stuurman
committed
Format
1 parent f949242 commit ca12125

1 file changed

Lines changed: 56 additions & 55 deletions

File tree

cpprevolve/revolve/gazebo/plugin/RobotController.cpp

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*/
1919

20-
#include <stdexcept>
20+
#include <stdexcept>
2121

2222
#include <gazebo/sensors/sensors.hh>
2323

@@ -54,62 +54,63 @@ void RobotController::Load(
5454
::gazebo::physics::ModelPtr _parent,
5555
sdf::ElementPtr _sdf)
5656
{
57-
try {
58-
// Store the pointer to the model / world
59-
this->model_ = _parent;
60-
this->world_ = _parent->GetWorld();
61-
this->initTime_ = this->world_->SimTime().Double();
62-
63-
// Create transport node
64-
this->node_.reset(new gz::transport::Node());
65-
this->node_->Init();
66-
67-
// Subscribe to robot battery state updater
68-
this->batterySetSub_ = this->node_->Subscribe(
69-
"~/battery_level/request",
70-
&RobotController::UpdateBattery,
71-
this);
72-
this->batterySetPub_ = this->node_->Advertise<gz::msgs::Response>(
73-
"~/battery_level/response");
74-
75-
if (not _sdf->HasElement("rv:robot_config")) {
76-
std::cerr
77-
<< "No `rv:robot_config` element found, controller not initialized."
78-
<< std::endl;
79-
return;
80-
}
81-
82-
auto robotConfiguration = _sdf->GetElement("rv:robot_config");
83-
84-
if (robotConfiguration->HasElement("rv:update_rate")) {
85-
auto updateRate = robotConfiguration->GetElement("rv:update_rate")->Get<double>();
86-
this->actuationTime_ = 1.0 / updateRate;
87-
}
88-
89-
// Load motors
90-
this->motorFactory_ = this->MotorFactory(_parent);
91-
this->LoadActuators(robotConfiguration);
92-
93-
// Load sensors
94-
this->sensorFactory_ = this->SensorFactory(_parent);
95-
this->LoadSensors(robotConfiguration);
96-
97-
// Load brain, this needs to be done after the motors and sensors so they
98-
// can potentially be reordered.
99-
this->LoadBrain(robotConfiguration);
100-
101-
// Call the battery loader
102-
this->LoadBattery(robotConfiguration);
103-
104-
// Call startup function which decides on actuation
105-
this->Startup(_parent, _sdf);
57+
try
58+
{
59+
// Store the pointer to the model / world
60+
this->model_ = _parent;
61+
this->world_ = _parent->GetWorld();
62+
this->initTime_ = this->world_->SimTime().Double();
63+
64+
// Create transport node
65+
this->node_.reset(new gz::transport::Node());
66+
this->node_->Init();
67+
68+
// Subscribe to robot battery state updater
69+
this->batterySetSub_ = this->node_->Subscribe(
70+
"~/battery_level/request",
71+
&RobotController::UpdateBattery,
72+
this);
73+
this->batterySetPub_ = this->node_->Advertise<gz::msgs::Response>(
74+
"~/battery_level/response");
75+
76+
if (not _sdf->HasElement("rv:robot_config")) {
77+
std::cerr
78+
<< "No `rv:robot_config` element found, controller not initialized."
79+
<< std::endl;
80+
return;
10681
}
107-
catch (const std::exception &e)
108-
{
109-
std::cerr << "Error Loading the Robot Controller, exception: " << std::endl
110-
<< e.what() << std::endl;
111-
throw;
82+
83+
auto robotConfiguration = _sdf->GetElement("rv:robot_config");
84+
85+
if (robotConfiguration->HasElement("rv:update_rate")) {
86+
auto updateRate = robotConfiguration->GetElement("rv:update_rate")->Get<double>();
87+
this->actuationTime_ = 1.0 / updateRate;
11288
}
89+
90+
// Load motors
91+
this->motorFactory_ = this->MotorFactory(_parent);
92+
this->LoadActuators(robotConfiguration);
93+
94+
// Load sensors
95+
this->sensorFactory_ = this->SensorFactory(_parent);
96+
this->LoadSensors(robotConfiguration);
97+
98+
// Load brain, this needs to be done after the motors and sensors so they
99+
// can potentially be reordered.
100+
this->LoadBrain(robotConfiguration);
101+
102+
// Call the battery loader
103+
this->LoadBattery(robotConfiguration);
104+
105+
// Call startup function which decides on actuation
106+
this->Startup(_parent, _sdf);
107+
}
108+
catch (const std::exception &e)
109+
{
110+
std::cerr << "Error Loading the Robot Controller, exception: " << std::endl
111+
<< e.what() << std::endl;
112+
throw;
113+
}
113114
}
114115

115116
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)