Add format script which invokes clang-format on the C++ source code (#41)

On Windows machines, clang-format.exe must be in the PATH environment variable.
This commit is contained in:
Tyler Veness
2016-05-20 17:30:37 -07:00
committed by Peter Johnson
parent 68690643d2
commit e14e45da76
383 changed files with 13787 additions and 13198 deletions

View File

@@ -7,7 +7,6 @@
#include "gyro.h"
GZ_REGISTER_MODEL_PLUGIN(Gyro)
Gyro::Gyro() {}
@@ -22,7 +21,7 @@ void Gyro::Load(physics::ModelPtr model, sdf::ElementPtr sdf) {
if (sdf->HasElement("topic")) {
topic = sdf->Get<std::string>("topic");
} else {
topic = "~/"+sdf->GetAttribute("name")->GetAsString();
topic = "~/" + sdf->GetAttribute("name")->GetAsString();
}
std::string axisString = sdf->Get<std::string>("axis");
@@ -41,20 +40,22 @@ void Gyro::Load(physics::ModelPtr model, sdf::ElementPtr sdf) {
<< " axis=" << axis << " radians=" << radians << std::endl;
// Connect to Gazebo transport for messaging
std::string scoped_name = model->GetWorld()->GetName()+"::"+model->GetScopedName();
std::string scoped_name =
model->GetWorld()->GetName() + "::" + model->GetScopedName();
boost::replace_all(scoped_name, "::", "/");
node = transport::NodePtr(new transport::Node());
node->Init(scoped_name);
command_sub = node->Subscribe(topic+"/control", &Gyro::Callback, this);
pos_pub = node->Advertise<msgs::Float64>(topic+"/position");
vel_pub = node->Advertise<msgs::Float64>(topic+"/velocity");
command_sub = node->Subscribe(topic + "/control", &Gyro::Callback, this);
pos_pub = node->Advertise<msgs::Float64>(topic + "/position");
vel_pub = node->Advertise<msgs::Float64>(topic + "/velocity");
// Connect to the world update event.
// This will trigger the Update function every Gazebo iteration
updateConn = event::Events::ConnectWorldUpdateBegin(boost::bind(&Gyro::Update, this, _1));
updateConn = event::Events::ConnectWorldUpdateBegin(
boost::bind(&Gyro::Update, this, _1));
}
void Gyro::Update(const common::UpdateInfo &info) {
void Gyro::Update(const common::UpdateInfo& info) {
msgs::Float64 pos_msg, vel_msg;
pos_msg.set_data(Limit(GetAngle() - zero));
pos_pub->Publish(pos_msg);
@@ -62,12 +63,13 @@ void Gyro::Update(const common::UpdateInfo &info) {
vel_pub->Publish(vel_msg);
}
void Gyro::Callback(const msgs::ConstStringPtr &msg) {
void Gyro::Callback(const msgs::ConstStringPtr& msg) {
std::string command = msg->data();
if (command == "reset") {
zero = GetAngle();
} else {
gzerr << "WARNING: Gyro got unknown command '" << command << "'." << std::endl;
gzerr << "WARNING: Gyro got unknown command '" << command << "'."
<< std::endl;
}
}
@@ -90,15 +92,21 @@ double Gyro::GetVelocity() {
double Gyro::Limit(double value) {
if (radians) {
while (true) {
if (value < -M_PI) value += 2*M_PI;
else if (value > M_PI) value -= 2*M_PI;
else break;
if (value < -M_PI)
value += 2 * M_PI;
else if (value > M_PI)
value -= 2 * M_PI;
else
break;
}
} else {
while (true) {
if (value < -180) value += 360;
else if (value > 180) value -= 360;
else break;
if (value < -180)
value += 360;
else if (value > 180)
value -= 360;
else
break;
}
}
return value;