本文整理汇总了C++中physics::ModelPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ModelPtr类的具体用法?C++ ModelPtr怎么用?C++ ModelPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboRosF3D::Load( physics::ModelPtr _parent, sdf::ElementPtr _sdf )
{
// Get the world name.
this->world_ = _parent->GetWorld();
// load parameters
this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace"))
this->robot_namespace_ = _sdf->GetElement("robotNamespace")->Get<std::string>() + "/";
if (!_sdf->HasElement("bodyName"))
{
ROS_FATAL("f3d plugin missing <bodyName>, cannot proceed");
return;
}
else
this->link_name_ = _sdf->GetElement("bodyName")->Get<std::string>();
this->link_ = _parent->GetLink(this->link_name_);
if (!this->link_)
{
ROS_FATAL("gazebo_ros_f3d plugin error: bodyName: %s does not exist\n",this->link_name_.c_str());
return;
}
if (!_sdf->HasElement("topicName"))
{
ROS_FATAL("f3d plugin missing <topicName>, cannot proceed");
return;
}
else
this->topic_name_ = _sdf->GetElement("topicName")->Get<std::string>();
if (!_sdf->HasElement("frameName"))
{
ROS_INFO("f3d plugin missing <frameName>, defaults to world");
this->frame_name_ = "world";
}
else
{
this->frame_name_ = _sdf->GetElement("frameName")->Get<std::string>();
// todo: frameName not used
ROS_INFO("f3d plugin specifies <frameName> [%s], not used, default to world",this->frame_name_.c_str());
}
// Make sure the ROS node for Gazebo has already been initialized
if (!ros::isInitialized())
{
ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized, unable to load plugin. "
<< "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
return;
}
this->rosnode_ = new ros::NodeHandle(this->robot_namespace_);
// resolve tf prefix
std::string prefix;
this->rosnode_->getParam(std::string("tf_prefix"), prefix);
this->frame_name_ = tf::resolve(prefix, this->frame_name_);
// Custom Callback Queue
ros::AdvertiseOptions ao = ros::AdvertiseOptions::create<geometry_msgs::WrenchStamped>(
this->topic_name_,1,
boost::bind( &GazeboRosF3D::F3DConnect,this),
boost::bind( &GazeboRosF3D::F3DDisconnect,this), ros::VoidPtr(), &this->queue_);
this->pub_ = this->rosnode_->advertise(ao);
// Custom Callback Queue
this->callback_queue_thread_ = boost::thread( boost::bind( &GazeboRosF3D::QueueThread,this ) );
// New Mechanism for Updating every World Cycle
// Listen to the update event. This event is broadcast every
// simulation iteration.
this->update_connection_ = event::Events::ConnectWorldUpdateBegin(
boost::bind(&GazeboRosF3D::UpdateChild, this));
}
示例2: Load
/**
* Saves the gazebo pointer, creates the device driver
*/
void GazeboYarpTripod::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
{
yarp::os::Network::init();
if (!yarp::os::Network::checkNetwork(GazeboYarpPlugins::yarpNetworkInitializationTimeout)) {
std::cerr << "GazeboYarpTripod::Load error: yarp network does not seem to be available, is the yarpserver running?"<<std::endl;
return;
}
std::cout<<"*** GazeboYarpTripod plugin started ***"<<std::endl;
if (!_parent) {
gzerr << "GazeboYarpTripod plugin requires a parent.\n";
return;
}
m_robotName = _parent->GetScopedName();
GazeboYarpPlugins::Handler::getHandler()->setRobot(get_pointer(_parent));
// Add the gazebo_controlboard device driver to the factory.
yarp::dev::Drivers::factory().add(new yarp::dev::DriverCreatorOf<cer::dev::GazeboTripodMotionControl>("gazebo_tripod", "controlboardwrapper2", "GazeboTripodMotionControl"));
//Getting .ini configuration file from sdf
bool configuration_loaded = false;
yarp::os::Bottle wrapper_group;
yarp::os::Bottle driver_group;
if (_sdf->HasElement("yarpConfigurationFile")) {
std::string ini_file_name = _sdf->Get<std::string>("yarpConfigurationFile");
std::string ini_file_path = gazebo::common::SystemPaths::Instance()->FindFileURI(ini_file_name);
GazeboYarpPlugins::addGazeboEnviromentalVariablesModel(_parent,_sdf,m_parameters);
bool wipe = false;
if (ini_file_path != "" && m_parameters.fromConfigFile(ini_file_path.c_str(),wipe))
{
std::cout << "GazeboYarpTripod: Found yarpConfigurationFile: loading from " << ini_file_path << std::endl;
m_parameters.put("gazebo_ini_file_path",ini_file_path.c_str());
wrapper_group = m_parameters.findGroup("WRAPPER");
if(wrapper_group.isNull()) {
printf("GazeboYarpTripod::Load Error: [WRAPPER] group not found in config file\n");
return;
}
if(m_parameters.check("ROS"))
{
yarp::os::ConstString ROS;
ROS = yarp::os::ConstString ("(") + m_parameters.findGroup("ROS").toString() + yarp::os::ConstString (")");
wrapper_group.append(yarp::os::Bottle(ROS));
}
configuration_loaded = true;
}
}
if (!configuration_loaded) {
std::cout << "GazeboYarpTripod: File .ini not found, quitting\n" << std::endl;
return;
}
m_wrapper.open(wrapper_group);
if (!m_wrapper.isValid())
fprintf(stderr, "GazeboYarpTripod: wrapper did not open\n");
else
fprintf(stderr, "GazeboYarpTripod: wrapper opened correctly\n");
if (!m_wrapper.view(m_iWrap)) {
printf("Wrapper interface not found\n");
}
yarp::os::Bottle *netList = wrapper_group.find("networks").asList();
if (netList->isNull()) {
printf("GazeboYarpTripod ERROR, net list to attach to was not found, exiting\n");
m_wrapper.close();
// m_controlBoard.close();
return;
}
for (int n = 0; n < netList->size(); n++)
{
yarp::dev::PolyDriverDescriptor newPoly;
newPoly.key = netList->get(n).asString();
std::string scopedDeviceName = m_robotName + "::" + newPoly.key.c_str();
newPoly.poly = GazeboYarpPlugins::Handler::getHandler()->getDevice(scopedDeviceName);
if( newPoly.poly != NULL)
{
// device already exists, use it, setting it againg to increment the usage counter.
printf("controlBoard %s already opened\n", newPoly.key.c_str());
}
else
{
driver_group = m_parameters.findGroup(newPoly.key.c_str());
if (driver_group.isNull()) {
fprintf(stderr, "GazeboYarpTripod::Load Error: [%s] group not found in config file. Closing wrapper \n", newPoly.key.c_str());
m_wrapper.close();
//.........这里部分代码省略.........
示例3: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboRosGps::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
world = _model->GetWorld();
// load parameters
if (!_sdf->HasElement("robotNamespace"))
namespace_.clear();
else
namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
if (!_sdf->HasElement("bodyName"))
{
link = _model->GetLink();
link_name_ = link->GetName();
}
else {
link_name_ = _sdf->GetElement("bodyName")->GetValueString();
link = boost::shared_dynamic_cast<physics::Link>(world->GetEntity(link_name_));
}
if (!link)
{
ROS_FATAL("GazeboRosGps plugin error: bodyName: %s does not exist\n", link_name_.c_str());
return;
}
double update_rate = 4.0;
if (_sdf->HasElement("updateRate")) update_rate = _sdf->GetElement("updateRate")->GetValueDouble();
update_period = update_rate > 0.0 ? 1.0/update_rate : 0.0;
if (!_sdf->HasElement("frameId"))
frame_id_ = link_name_;
else
frame_id_ = _sdf->GetElement("frameId")->GetValueString();
if (!_sdf->HasElement("topicName"))
fix_topic_ = "fix";
else
fix_topic_ = _sdf->GetElement("topicName")->GetValueString();
if (!_sdf->HasElement("velocityTopicName"))
velocity_topic_ = "fix_velocity";
else
velocity_topic_ = _sdf->GetElement("velocityTopicName")->GetValueString();
if (!_sdf->HasElement("referenceLatitude"))
reference_latitude_ = DEFAULT_REFERENCE_LATITUDE;
else
reference_latitude_ = _sdf->GetElement("referenceLatitude")->GetValueDouble();
if (!_sdf->HasElement("referenceLongitude"))
reference_longitude_ = DEFAULT_REFERENCE_LONGITUDE;
else
reference_longitude_ = _sdf->GetElement("referenceLongitude")->GetValueDouble();
if (!_sdf->HasElement("referenceHeading"))
reference_heading_ = DEFAULT_REFERENCE_HEADING * M_PI/180.0;
else
reference_heading_ = _sdf->GetElement("referenceLatitude")->GetValueDouble() * M_PI/180.0;
if (!_sdf->HasElement("referenceAltitude"))
reference_altitude_ = DEFAULT_REFERENCE_ALTITUDE;
else
reference_altitude_ = _sdf->GetElement("referenceLatitude")->GetValueDouble();
if (!_sdf->HasElement("status"))
status_ = sensor_msgs::NavSatStatus::STATUS_FIX;
else
status_ = _sdf->GetElement("status")->GetValueUInt();
if (!_sdf->HasElement("service"))
service_ = sensor_msgs::NavSatStatus::SERVICE_GPS;
else
service_ = _sdf->GetElement("service")->GetValueUInt();
fix_.header.frame_id = frame_id_;
fix_.status.status = status_;
fix_.status.service = service_;
velocity_.header.frame_id = frame_id_;
position_error_model_.Load(_sdf);
velocity_error_model_.Load(_sdf, "velocity");
// start ros node
if (!ros::isInitialized())
{
int argc = 0;
char** argv = NULL;
ros::init(argc,argv,"gazebo",ros::init_options::NoSigintHandler|ros::init_options::AnonymousName);
}
node_handle_ = new ros::NodeHandle(namespace_);
fix_publisher_ = node_handle_->advertise<sensor_msgs::NavSatFix>(fix_topic_, 10);
velocity_publisher_ = node_handle_->advertise<geometry_msgs::Vector3Stamped>(velocity_topic_, 10);
Reset();
// New Mechanism for Updating every World Cycle
//.........这里部分代码省略.........
示例4: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboQuadrotorAerodynamics::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
model = _model;
world = _model->GetWorld();
// load parameters
if (!_sdf->HasElement("robotNamespace"))
namespace_.clear();
else
namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
if (!_sdf->HasElement("paramNamespace"))
param_namespace_ = "~/quadrotor_aerodynamics/";
else
param_namespace_ = _sdf->GetElement("paramNamespace")->GetValueString() + "/";
if (!_sdf->HasElement("voltageTopicName"))
voltage_topic_ = "motor_pwm";
else
voltage_topic_ = _sdf->GetElement("voltageTopicName")->GetValueString();
if (!_sdf->HasElement("windTopicName"))
wind_topic_ = "wind";
else
wind_topic_ = _sdf->GetElement("windTopicName")->GetValueString();
if (!_sdf->HasElement("wrenchTopic"))
wrench_topic_ = "wrench_out";
else
wrench_topic_ = _sdf->GetElement("wrenchTopic")->GetValueString();
if (!_sdf->HasElement("statusTopic"))
status_topic_ = "motor_status";
else
status_topic_ = _sdf->GetElement("statusTopic")->GetValueString();
// set control timing parameters
control_rate_ = 100.0;
if (_sdf->HasElement("controlRate")) control_rate_ = _sdf->GetElement("controlRate")->GetValueDouble();
control_period_ = (control_rate_ > 0) ? (1.0 / control_rate_) : 0.0;
control_tolerance_ = control_period_ / 2.0;
if (_sdf->HasElement("controlTolerance")) control_tolerance_ = _sdf->GetElement("controlTolerance")->GetValueDouble();
control_delay_ = Time();
if (_sdf->HasElement("controlDelay")) control_delay_ = _sdf->GetElement("controlDelay")->GetValueDouble();
// start ros node
if (!ros::isInitialized())
{
int argc = 0;
char **argv = NULL;
ros::init(argc,argv,"gazebo",ros::init_options::NoSigintHandler|ros::init_options::AnonymousName);
}
node_handle_ = new ros::NodeHandle(namespace_);
// subscribe command
if (!voltage_topic_.empty())
{
ros::SubscribeOptions ops = ros::SubscribeOptions::create<hector_uav_msgs::MotorPWM>(
voltage_topic_, 1,
boost::bind(&GazeboQuadrotorAerodynamics::CommandCallback, this, _1),
ros::VoidPtr(), &callback_queue_);
voltage_subscriber_ = node_handle_->subscribe(ops);
}
// subscribe command
if (!wind_topic_.empty())
{
ros::SubscribeOptions ops = ros::SubscribeOptions::create<geometry_msgs::Vector3>(
wind_topic_, 1,
boost::bind(&GazeboQuadrotorAerodynamics::WindCallback, this, _1),
ros::VoidPtr(), &callback_queue_);
wind_subscriber_ = node_handle_->subscribe(ops);
}
// publish wrench
if (!wrench_topic_.empty())
{
ros::AdvertiseOptions ops = ros::AdvertiseOptions::create<geometry_msgs::Wrench>(
wrench_topic_, 10,
ros::SubscriberStatusCallback(), ros::SubscriberStatusCallback(),
ros::VoidConstPtr(), &callback_queue_);
wrench_publisher_ = node_handle_->advertise(ops);
}
// publish motor_status
if (!status_topic_.empty())
{
ros::AdvertiseOptions ops = ros::AdvertiseOptions::create<hector_uav_msgs::MotorStatus>(
status_topic_, 10,
ros::SubscriberStatusCallback(), ros::SubscriberStatusCallback(),
ros::VoidConstPtr(), &callback_queue_);
motor_status_publisher_ = node_handle_->advertise(ops);
}
callback_queue_thread_ = boost::thread( boost::bind( &GazeboQuadrotorAerodynamics::QueueThread,this ) );
Reset();
//.........这里部分代码省略.........
示例5: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboRosBaro::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
world = _model->GetWorld();
// load parameters
if (!_sdf->HasElement("robotNamespace"))
namespace_.clear();
else
namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
if (!_sdf->HasElement("bodyName"))
{
link = _model->GetLink();
link_name_ = link->GetName();
}
else {
link_name_ = _sdf->GetElement("bodyName")->GetValueString();
link = _model->GetLink( link_name_ );
}
ROS_INFO_NAMED( "gazebo_ros_baro", "got link %s for model %s for baro", link->GetName().c_str(), link->GetModel()->GetName().c_str() );
if (!link)
{
ROS_FATAL("gazebo_ros_baro plugin error: bodyName: %s does not exist\n", link_name_.c_str());
return;
}
double update_rate = 0.0;
if (_sdf->HasElement("updateRate")) update_rate = _sdf->GetElement("updateRate")->GetValueDouble();
update_period = update_rate > 0.0 ? 1.0/update_rate : 0.0;
if (!_sdf->HasElement("frameId"))
frame_id_ = link->GetName();
else
frame_id_ = _sdf->GetElement("frameId")->GetValueString();
if (!_sdf->HasElement("topicName"))
height_topic_ = "pressure_height";
else
height_topic_ = _sdf->GetElement("topicName")->GetValueString();
if (!_sdf->HasElement("altimeterTopicName"))
altimeter_topic_ = "altimeter";
else
altimeter_topic_ = _sdf->GetElement("altimeterTopicName")->GetValueString();
if (!_sdf->HasElement("elevation"))
elevation_ = DEFAULT_ELEVATION;
else
elevation_ = _sdf->GetElement("elevation")->GetValueDouble();
if (!_sdf->HasElement("qnh"))
qnh_ = DEFAULT_QNH;
else
qnh_ = _sdf->GetElement("qnh")->GetValueDouble();
sensor_model_.Load(_sdf);
height_.header.frame_id = frame_id_;
// start ros node
if (!ros::isInitialized())
{
int argc = 0;
char **argv = NULL;
ros::init(argc,argv,"gazebo",ros::init_options::NoSigintHandler|ros::init_options::AnonymousName);
}
node_handle_ = new ros::NodeHandle(namespace_);
if (!height_topic_.empty()) {
#ifdef USE_MAV_MSGS
height_publisher_ = node_handle_->advertise<mav_msgs::Height>(height_topic_, 10);
#else
height_publisher_ = node_handle_->advertise<geometry_msgs::PointStamped>(height_topic_, 10);
#endif
}
if (!altimeter_topic_.empty()) {
altimeter_publisher_ = node_handle_->advertise<hector_uav_msgs::Altimeter>(altimeter_topic_, 10);
}
Reset();
// New Mechanism for Updating every World Cycle
// Listen to the update event. This event is broadcast every
// simulation iteration.
updateConnection = event::Events::ConnectWorldUpdateStart(
boost::bind(&GazeboRosBaro::Update, this));
}
示例6: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboRosMagnetic::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
world = _model->GetWorld();
// load parameters
if (!_sdf->HasElement("robotNamespace"))
namespace_.clear();
else
namespace_ = _sdf->GetElement("robotNamespace")->Get<std::string>() + "/";
if (!_sdf->HasElement("topicName"))
topic_ = "magnetic";
else
topic_ = _sdf->GetElement("topicName")->Get<std::string>();
link = _model->GetChildLink("base_link");
if (!link)
{
ROS_FATAL("GazeboRosMagnetic plugin error: bodyName: %s does not exist\n", link_name_.c_str());
return;
}
double update_rate = 0.0;
if (_sdf->HasElement("updateRate")) update_rate = _sdf->GetElement("updateRate")->Get<double>();
update_period = update_rate > 0.0 ? 1.0/update_rate : 0.0;
if (!_sdf->HasElement("frameId"))
frame_id_ = link_name_;
else
frame_id_ = _sdf->GetElement("frameId")->Get<std::string>();
if (!_sdf->HasElement("magnitude"))
magnitude_ = DEFAULT_MAGNITUDE;
else
magnitude_ = _sdf->GetElement("magnitude")->Get<double>();
if (!_sdf->HasElement("referenceHeading"))
reference_heading_ = DEFAULT_REFERENCE_HEADING * M_PI/180.0;
else
reference_heading_ = _sdf->GetElement("referenceHeading")->Get<double>() * M_PI/180.0;
if (!_sdf->HasElement("declination"))
declination_ = DEFAULT_DECLINATION * M_PI/180.0;
else
declination_ = _sdf->GetElement("declination")->Get<double>() * M_PI/180.0;
if (!_sdf->HasElement("inclination"))
inclination_ = DEFAULT_INCLINATION * M_PI/180.0;
else
inclination_ = _sdf->GetElement("inclination")->Get<double>() * M_PI/180.0;
// Note: Gazebo uses NorthWestUp coordinate system, heading and declination are compass headings
magnetic_field_.header.frame_id = frame_id_;
magnetic_field_world_.x = magnitude_ * cos(inclination_) * cos(reference_heading_ - declination_);
magnetic_field_world_.y = magnitude_ * sin(reference_heading_ - declination_);
magnetic_field_world_.z = magnitude_ * -sin(inclination_) * cos(reference_heading_ - declination_);
sensor_model_.Load(_sdf);
// start ros node
if (!ros::isInitialized())
{
int argc = 0;
char** argv = NULL;
ros::init(argc,argv,"gazebo",ros::init_options::NoSigintHandler|ros::init_options::AnonymousName);
}
node_handle_ = new ros::NodeHandle(namespace_);
publisher_ = node_handle_->advertise<geometry_msgs::Vector3Stamped>(topic_, 1);
Reset();
// New Mechanism for Updating every World Cycle
// Listen to the update event. This event is broadcast every
// simulation iteration.
updateConnection = event::Events::ConnectWorldUpdateBegin(
boost::bind(&GazeboRosMagnetic::Update, this));
}
示例7: Load
void GazeboRosKobuki::Load(physics::ModelPtr parent, sdf::ElementPtr sdf)
{
model_ = parent;
if (!model_)
{
ROS_ERROR_STREAM("Invalid model pointer! [" << node_name_ << "]");
return;
}
// Get then name of the parent model and use it as node name
std::string model_name = sdf->GetParent()->GetValueString("name");
gzdbg << "Plugin model name: " << model_name << "\n";
nh_ = ros::NodeHandle("");
// creating a private name pace until Gazebo implements topic remappings
nh_priv_ = ros::NodeHandle("/" + model_name);
node_name_ = model_name;
world_ = parent->GetWorld();
// TODO: use when implementing subs
// ros_spinner_thread_ = new boost::thread(boost::bind(&GazeboRosKobuki::spin, this));
//
// this->node_namespace_ = "";
// if (_sdf->HasElement("node_namespace"))
// this->node_namespace_ = _sdf->GetElement("node_namespace")->GetValueString() + "/";
/*
* Prepare receiving motor power commands
*/
motor_power_sub_ = nh_priv_.subscribe("commands/motor_power", 10, &GazeboRosKobuki::motorPowerCB, this);
motors_enabled_ = true;
/*
* Prepare joint state publishing
*/
if (sdf->HasElement("left_wheel_joint_name"))
{
left_wheel_joint_name_ = sdf->GetElement("left_wheel_joint_name")->GetValueString();
}
else
{
ROS_ERROR_STREAM("Couldn't find left wheel joint in the model description!"
<< " Did you specify the correct joint name?" << " [" << node_name_ <<"]");
return;
}
if (sdf->HasElement("right_wheel_joint_name"))
{
right_wheel_joint_name_ = sdf->GetElement("right_wheel_joint_name")->GetValueString();
}
else
{
ROS_ERROR_STREAM("Couldn't find right wheel joint in the model description!"
<< " Did you specify the correct joint name?" << " [" << node_name_ <<"]");
return;
}
joints_[LEFT] = parent->GetJoint(left_wheel_joint_name_);
joints_[RIGHT] = parent->GetJoint(right_wheel_joint_name_);
if (!joints_[LEFT] || !joints_[RIGHT])
{
ROS_ERROR_STREAM("Couldn't find specified wheel joints in the model! [" << node_name_ <<"]");
return;
}
joint_state_.header.frame_id = "Joint States";
joint_state_.name.push_back(left_wheel_joint_name_);
joint_state_.position.push_back(0);
joint_state_.velocity.push_back(0);
joint_state_.effort.push_back(0);
joint_state_.name.push_back(right_wheel_joint_name_);
joint_state_.position.push_back(0);
joint_state_.velocity.push_back(0);
joint_state_.effort.push_back(0);
joint_state_pub_ = nh_.advertise<sensor_msgs::JointState>("joint_states", 1);
/*
* Prepare publishing odometry data
*/
if (sdf->HasElement("wheel_separation"))
{
wheel_sep_ = sdf->GetElement("wheel_separation")->GetValueDouble();
}
else
{
ROS_ERROR_STREAM("Couldn't find the wheel separation parameter in the model description!"
<< " Did you specify it?" << " [" << node_name_ <<"]");
return;
}
if (sdf->HasElement("wheel_diameter"))
{
wheel_diam_ = sdf->GetElement("wheel_diameter")->GetValueDouble();
}
else
{
ROS_ERROR_STREAM("Couldn't find the wheel diameter parameter in the model description!"
<< " Did you specify it?" << " [" << node_name_ <<"]");
return;
}
if (sdf->HasElement("torque"))
{
torque_ = sdf->GetElement("torque")->GetValueDouble();
}
else
//.........这里部分代码省略.........
示例8: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboQuadrotorStateController::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
world = _model->GetWorld();
// load parameters
if (!_sdf->HasElement("robotNamespace"))
namespace_.clear();
else
namespace_ = _sdf->GetElement("robotNamespace")->Get<std::string>() + "/";
if (!_sdf->HasElement("topicName"))
velocity_topic_ = "cmd_vel";
else
velocity_topic_ = _sdf->GetElement("topicName")->Get<std::string>();
if (!_sdf->HasElement("takeoffTopic"))
takeoff_topic_ = "/ardrone/takeoff";
else
takeoff_topic_ = _sdf->GetElement("takeoffTopic")->Get<std::string>();
if (!_sdf->HasElement("/ardrone/land"))
land_topic_ = "/ardrone/land";
else
land_topic_ = _sdf->GetElement("landTopic")->Get<std::string>();
if (!_sdf->HasElement("resetTopic"))
reset_topic_ = "/ardrone/reset";
else
reset_topic_ = _sdf->GetElement("resetTopic")->Get<std::string>();
if (!_sdf->HasElement("navdataTopic"))
navdata_topic_ = "/ardrone/navdata";
else
navdata_topic_ = _sdf->GetElement("navdataTopic")->Get<std::string>();
if (!_sdf->HasElement("imuTopic"))
imu_topic_.clear();
else
imu_topic_ = _sdf->GetElement("imuTopic")->Get<std::string>();
if (!_sdf->HasElement("sonarTopic"))
sonar_topic_.clear();
else
sonar_topic_ = _sdf->GetElement("sonarTopic")->Get<std::string>();
if (!_sdf->HasElement("contactTopic"))
contact_topic_.clear();
else
contact_topic_ = _sdf->GetElement("contactTopic")->Get<std::string>();
if (!_sdf->HasElement("stateTopic"))
state_topic_.clear();
else
state_topic_ = _sdf->GetElement("stateTopic")->Get<std::string>();
if (!_sdf->HasElement("bodyName"))
{
link = _model->GetLink();
link_name_ = link->GetName();
}
else {
link_name_ = _sdf->GetElement("bodyName")->Get<std::string>();
link = boost::dynamic_pointer_cast<physics::Link>(world->GetEntity(link_name_));
}
if (!link)
{
ROS_FATAL("gazebo_ros_baro plugin error: bodyName: %s does not exist\n", link_name_.c_str());
return;
}
node_handle_ = new ros::NodeHandle(namespace_);
// subscribe command: velocity control command
if (!velocity_topic_.empty())
{
ros::SubscribeOptions ops = ros::SubscribeOptions::create<geometry_msgs::Twist>(
velocity_topic_, 1,
boost::bind(&GazeboQuadrotorStateController::VelocityCallback, this, _1),
ros::VoidPtr(), &callback_queue_);
velocity_subscriber_ = node_handle_->subscribe(ops);
}
// subscribe command: take off command
if (!takeoff_topic_.empty())
{
ros::SubscribeOptions ops = ros::SubscribeOptions::create<std_msgs::Empty>(
takeoff_topic_, 1,
boost::bind(&GazeboQuadrotorStateController::TakeoffCallback, this, _1),
ros::VoidPtr(), &callback_queue_);
takeoff_subscriber_ = node_handle_->subscribe(ops);
}
// subscribe command: take off command
if (!land_topic_.empty())
{
ros::SubscribeOptions ops = ros::SubscribeOptions::create<std_msgs::Empty>(
land_topic_, 1,
//.........这里部分代码省略.........
示例9: Load
void GazeboJointStateClient::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
{
// Make sure the ROS node for Gazebo has already been initalized
if (!ros::isInitialized())
{
ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized, unable to load plugin. "
<< "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' "
<< "in the gazebo_ros package)");
return;
}
// get joint names from parameters
std::string armNamespace = _parent->GetName();
if (_sdf->HasElement("robot_components_namespace"))
{
sdf::ElementPtr armParamElem = _sdf->GetElement("robot_components_namespace");
armNamespace = armParamElem->Get<std::string>();
}
else
{
ROS_WARN("SDF Element 'robot_components_namespace' not defined, so using robot name as namespace for components.");
}
// ROS_INFO_STREAM("GazeboJointStateClient loading joints from components namespace '"<<armNamespace<<"'");
ROS_INFO_STREAM("GazeboJointStateClient: Loading arm component parameters from "<< armNamespace);
joints = ArmComponentsNameManagerPtr(new ArmComponentsNameManager(armNamespace,false));
if (!joints->waitToLoadParameters(1, 3, 0.5))
{
ROS_FATAL_STREAM("Cannot load arm components for robot "<<_parent->GetName()<<" from namespace "<<armNamespace);
return;
}
physics::BasePtr jcChild = _parent->GetChild(physics::JointControllerThreadsafe::UniqueName());
if (!jcChild.get())
{
ROS_ERROR("Cannot load GazeboJointStateClient if no default JointControllerThreadsafe is set for the model");
throw std::string("Cannot load GazeboJointStateClient if no default JointController is set for the model");
}
physics::JointControllerThreadsafePtr ptr =
boost::dynamic_pointer_cast<physics::JointControllerThreadsafe>(jcChild);
if (!ptr.get())
{
ROS_ERROR_STREAM("Cannot load GazeboJointStateClient if child '"
<< physics::JointControllerThreadsafe::UniqueName()
<< "' is not of class JointControllerThreadsafe");
throw std::string("Cannot load GazeboJointStateClient if child '"
+ physics::JointControllerThreadsafe::UniqueName()
+ "' is not of class JointControllerThreadsafe");
}
jointController = ptr;
// get joint names from parameters
std::vector<std::string> joint_names;
joints->getJointNames(joint_names, true);
const std::vector<float>& arm_init = joints->getArmJointsInitPose();
const std::vector<float>& gripper_init = joints->getGripperJointsInitPose();
// Print the joint names to help debugging
std::map<std::string, physics::JointPtr > jntMap = jointController->GetJoints();
for (std::map<std::string, physics::JointPtr>::iterator it = jntMap.begin(); it != jntMap.end(); ++it)
{
physics::JointPtr j = it->second;
ROS_INFO_STREAM("Gazebo joint: '"<<j->GetName()<<"' is registered as '"<<it->first<<"'");
}
// check if the joint names maintained in 'joints' match the names in gazebo,
// that the joints can be used by this class, and if yes, load PID controllers.
int i = 0;
for (std::vector<std::string>::iterator it = joint_names.begin();
it != joint_names.end(); ++it)
{
// ROS_INFO_STREAM("Local joint name: '"<<*it<<"'");
physics::JointPtr joint = _parent->GetJoint(*it);
if (!joint.get())
{
ROS_FATAL_STREAM("Joint name " << *it << " not found as robot joint");
throw std::string("Joint not found");
}
std::string scopedName = joint->GetScopedName();
std::map<std::string, physics::JointPtr >::iterator jit = jntMap.find(scopedName);
if (jit == jntMap.end())
{
ROS_ERROR_STREAM("Joint name " << *it << " not found in joint controller joints");
throw std::string("Joint not found");
}
++i;
}
model = _parent;
jsSub = nh.subscribe(jointStateTopic, 1, &GazeboJointStateClient::JointStateCallback, this);
}
示例10:
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboRosP3D::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
{
// Get the world name.
this->world_ = _parent->GetWorld();
this->model_ = _parent;
// load parameters
this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace"))
this->robot_namespace_ =
_sdf->GetElement("robotNamespace")->Get<std::string>() + "/";
if (!_sdf->HasElement("bodyName"))
{
ROS_FATAL("p3d plugin missing <bodyName>, cannot proceed");
return;
}
else
this->link_name_ = _sdf->GetElement("bodyName")->Get<std::string>();
this->link_ = _parent->GetLink(this->link_name_);
if (!this->link_)
{
ROS_FATAL("gazebo_ros_p3d plugin error: bodyName: %s does not exist\n",
this->link_name_.c_str());
return;
}
if (!_sdf->HasElement("topicName"))
{
ROS_FATAL("p3d plugin missing <topicName>, cannot proceed");
return;
}
else
this->topic_name_ = _sdf->GetElement("topicName")->Get<std::string>();
if (!_sdf->HasElement("frameName"))
{
ROS_DEBUG("p3d plugin missing <frameName>, defaults to world");
this->frame_name_ = "world";
}
else
this->frame_name_ = _sdf->GetElement("frameName")->Get<std::string>();
if (!_sdf->HasElement("xyzOffset"))
{
ROS_DEBUG("p3d plugin missing <xyzOffset>, defaults to 0s");
this->offset_.pos = math::Vector3(0, 0, 0);
}
else
this->offset_.pos = _sdf->GetElement("xyzOffset")->Get<math::Vector3>();
if (!_sdf->HasElement("rpyOffset"))
{
ROS_DEBUG("p3d plugin missing <rpyOffset>, defaults to 0s");
this->offset_.rot = math::Vector3(0, 0, 0);
}
else
this->offset_.rot = _sdf->GetElement("rpyOffset")->Get<math::Vector3>();
if (!_sdf->HasElement("gaussianNoise"))
{
ROS_DEBUG("p3d plugin missing <gaussianNoise>, defaults to 0.0");
this->gaussian_noise_ = 0;
}
else
this->gaussian_noise_ = _sdf->GetElement("gaussianNoise")->Get<double>();
if (!_sdf->HasElement("updateRate"))
{
ROS_DEBUG("p3d plugin missing <updateRate>, defaults to 0.0"
" (as fast as possible)");
this->update_rate_ = 0;
}
else
this->update_rate_ = _sdf->GetElement("updateRate")->Get<double>();
// Make sure the ROS node for Gazebo has already been initialized
if (!ros::isInitialized())
{
ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized, unable to load plugin. "
<< "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
return;
}
this->rosnode_ = new ros::NodeHandle(this->robot_namespace_);
// publish multi queue
this->pmq.startServiceThread();
// resolve tf prefix
std::string prefix;
this->rosnode_->getParam(std::string("tf_prefix"), prefix);
this->tf_frame_name_ = tf::resolve(prefix, this->frame_name_);
if (this->topic_name_ != "")
{
this->pub_Queue = this->pmq.addPub<nav_msgs::Odometry>();
//.........这里部分代码省略.........
示例11: Load
void GazeboPressurePlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf) {
if (kPrintOnPluginLoad) {
gzdbg << __FUNCTION__ << "() called." << std::endl;
}
gzdbg << "_model = " << _model->GetName() << std::endl;
// Store the pointer to the model and the world.
model_ = _model;
world_ = model_->GetWorld();
//==============================================//
//========== READ IN PARAMS FROM SDF ===========//
//==============================================//
// Use the robot namespace to create the node handle.
if (_sdf->HasElement("robotNamespace"))
namespace_ = _sdf->GetElement("robotNamespace")->Get<std::string>();
else
gzerr << "[gazebo_pressure_plugin] Please specify a robotNamespace.\n";
// Get node handle.
node_handle_ = transport::NodePtr(new transport::Node());
// Initialise with default namespace (typically /gazebo/default/).
node_handle_->Init();
std::string link_name;
if (_sdf->HasElement("linkName"))
link_name = _sdf->GetElement("linkName")->Get<std::string>();
else
gzerr << "[gazebo_pressure_plugin] Please specify a linkName.\n";
// Get the pointer to the link.
link_ = model_->GetLink(link_name);
if (link_ == NULL)
gzthrow("[gazebo_pressure_plugin] Couldn't find specified link \"" << link_name << "\".");
frame_id_ = link_name;
// Retrieve the rest of the SDF parameters.
getSdfParam<std::string>(_sdf, "pressureTopic", pressure_topic_, kDefaultPressurePubTopic);
getSdfParam<double>(_sdf, "referenceAltitude", ref_alt_, kDefaultRefAlt);
getSdfParam<double>(_sdf, "pressureVariance", pressure_var_, kDefaultPressureVar);
CHECK(pressure_var_ >= 0.0);
// Initialize the normal distribution for pressure.
double mean = 0.0;
pressure_n_[0] = NormalDistribution(mean, sqrt(pressure_var_));
// Listen to the update event. This event is broadcast every simulation
// iteration.
this->updateConnection_ = event::Events::ConnectWorldUpdateBegin(
boost::bind(&GazeboPressurePlugin::OnUpdate, this, _1));
//==============================================//
//=== POPULATE STATIC PARTS OF PRESSURE MSG ====//
//==============================================//
pressure_message_.mutable_header()->set_frame_id(frame_id_);
pressure_message_.set_variance(pressure_var_);
}
示例12: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void DRCVehicleROSPlugin::Load(physics::ModelPtr _parent,
sdf::ElementPtr _sdf)
{
DRCVehiclePlugin::Load(_parent, _sdf);
// initialize ros
if (!ros::isInitialized())
{
gzerr << "Not loading plugin since ROS hasn't been "
<< "properly initialized. Try starting gazebo with ros plugin:\n"
<< " gazebo -s libgazebo_ros_api_plugin.so\n";
return;
}
// ros stuff
this->rosNode = new ros::NodeHandle("");
// Get the world name.
this->world = _parent->GetWorld();
this->model = _parent;
ros::SubscribeOptions hand_wheel_cmd_so =
ros::SubscribeOptions::create<std_msgs::Float64>(
this->model->GetName() + "/hand_wheel/cmd", 100,
boost::bind(static_cast<void (DRCVehicleROSPlugin::*)
(const std_msgs::Float64::ConstPtr&)>(
&DRCVehicleROSPlugin::SetHandWheelState), this, _1),
ros::VoidPtr(), &this->queue);
this->subHandWheelCmd = this->rosNode->subscribe(hand_wheel_cmd_so);
ros::SubscribeOptions hand_brake_cmd_so =
ros::SubscribeOptions::create<std_msgs::Float64>(
this->model->GetName() + "/hand_brake/cmd", 100,
boost::bind(static_cast<void (DRCVehicleROSPlugin::*)
(const std_msgs::Float64::ConstPtr&)>(
&DRCVehicleROSPlugin::SetHandBrakeState), this, _1),
ros::VoidPtr(), &this->queue);
this->subHandBrakeCmd = this->rosNode->subscribe(hand_brake_cmd_so);
ros::SubscribeOptions gas_pedal_cmd_so =
ros::SubscribeOptions::create<std_msgs::Float64>(
this->model->GetName() + "/gas_pedal/cmd", 100,
boost::bind(static_cast<void (DRCVehicleROSPlugin::*)
(const std_msgs::Float64::ConstPtr&)>(
&DRCVehicleROSPlugin::SetGasPedalState), this, _1),
ros::VoidPtr(), &this->queue);
this->subGasPedalCmd = this->rosNode->subscribe(gas_pedal_cmd_so);
ros::SubscribeOptions brake_pedal_cmd_so =
ros::SubscribeOptions::create<std_msgs::Float64>(
this->model->GetName() + "/brake_pedal/cmd", 100,
boost::bind(static_cast<void (DRCVehicleROSPlugin::*)
(const std_msgs::Float64::ConstPtr&)>(
&DRCVehicleROSPlugin::SetBrakePedalState), this, _1),
ros::VoidPtr(), &this->queue);
this->subBrakePedalCmd = this->rosNode->subscribe(brake_pedal_cmd_so);
ros::SubscribeOptions key_cmd_so =
ros::SubscribeOptions::create<std_msgs::Int8>(
this->model->GetName() + "/key/cmd", 100,
boost::bind(static_cast<void (DRCVehicleROSPlugin::*)
(const std_msgs::Int8::ConstPtr&)>(
&DRCVehicleROSPlugin::SetKeyState), this, _1),
ros::VoidPtr(), &this->queue);
this->subKeyCmd = this->rosNode->subscribe(key_cmd_so);
ros::SubscribeOptions direction_cmd_so =
ros::SubscribeOptions::create<std_msgs::Int8>(
this->model->GetName() + "/direction/cmd", 100,
boost::bind(static_cast<void (DRCVehicleROSPlugin::*)
(const std_msgs::Int8::ConstPtr&)>(
&DRCVehicleROSPlugin::SetDirectionState), this, _1),
ros::VoidPtr(), &this->queue);
this->subDirectionCmd = this->rosNode->subscribe(direction_cmd_so);
this->pubHandWheelState = this->rosNode->advertise<std_msgs::Float64>(
this->model->GetName() + "/hand_wheel/state", 10);
this->pubHandBrakeState = this->rosNode->advertise<std_msgs::Float64>(
this->model->GetName() + "/hand_brake/state", 10);
this->pubGasPedalState = this->rosNode->advertise<std_msgs::Float64>(
this->model->GetName() + "/gas_pedal/state", 10);
this->pubBrakePedalState = this->rosNode->advertise<std_msgs::Float64>(
this->model->GetName() + "/brake_pedal/state", 10);
this->pubKeyState = this->rosNode->advertise<std_msgs::Int8>(
this->model->GetName() + "/key/state", 10);
this->pubDirectionState = this->rosNode->advertise<std_msgs::Int8>(
this->model->GetName() + "/direction/state", 10);
// ros callback queue for processing subscription
this->callbackQueueThread = boost::thread(
boost::bind(&DRCVehicleROSPlugin::QueueThread, this));
this->ros_publish_connection_ = event::Events::ConnectWorldUpdateBegin(
boost::bind(&DRCVehicleROSPlugin::RosPublishStates, this));
}
示例13: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void GazeboRosGps::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
world = _model->GetWorld();
// load parameters
if (!_sdf->HasElement("robotNamespace"))
namespace_.clear();
else
namespace_ = _sdf->GetElement("robotNamespace")->GetValue()->GetAsString();
if (!_sdf->HasElement("bodyName"))
{
link = _model->GetLink();
link_name_ = link->GetName();
}
else {
link_name_ = _sdf->GetElement("bodyName")->GetValue()->GetAsString();
link = _model->GetLink(link_name_);
}
if (!link)
{
ROS_FATAL("GazeboRosGps plugin error: bodyName: %s does not exist\n", link_name_.c_str());
return;
}
// default parameters
frame_id_ = "/world";
fix_topic_ = "fix";
velocity_topic_ = "fix_velocity";
reference_latitude_ = DEFAULT_REFERENCE_LATITUDE;
reference_longitude_ = DEFAULT_REFERENCE_LONGITUDE;
reference_heading_ = DEFAULT_REFERENCE_HEADING * M_PI/180.0;
reference_altitude_ = DEFAULT_REFERENCE_ALTITUDE;
status_ = sensor_msgs::NavSatStatus::STATUS_FIX;
service_ = sensor_msgs::NavSatStatus::SERVICE_GPS;
fix_.header.frame_id = frame_id_;
fix_.status.status = status_;
fix_.status.service = service_;
velocity_.header.frame_id = frame_id_;
if (_sdf->HasElement("frameId"))
frame_id_ = _sdf->GetElement("frameId")->GetValue()->GetAsString();
if (_sdf->HasElement("topicName"))
fix_topic_ = _sdf->GetElement("topicName")->GetValue()->GetAsString();
if (_sdf->HasElement("velocityTopicName"))
velocity_topic_ = _sdf->GetElement("velocityTopicName")->GetValue()->GetAsString();
if (_sdf->HasElement("referenceLatitude"))
_sdf->GetElement("referenceLatitude")->GetValue()->Get(reference_latitude_);
if (_sdf->HasElement("referenceLongitude"))
_sdf->GetElement("referenceLongitude")->GetValue()->Get(reference_longitude_);
if (_sdf->HasElement("referenceHeading"))
if (_sdf->GetElement("referenceHeading")->GetValue()->Get(reference_heading_))
reference_heading_ *= M_PI/180.0;
if (_sdf->HasElement("referenceAltitude"))
_sdf->GetElement("referenceAltitude")->GetValue()->Get(reference_altitude_);
if (_sdf->HasElement("status"))
_sdf->GetElement("status")->GetValue()->Get(status_);
if (_sdf->HasElement("service"))
_sdf->GetElement("service")->GetValue()->Get(service_);
fix_.header.frame_id = frame_id_;
fix_.status.status = status_;
fix_.status.service = service_;
velocity_.header.frame_id = frame_id_;
position_error_model_.Load(_sdf);
velocity_error_model_.Load(_sdf, "velocity");
// calculate earth radii
double temp = 1.0 / (1.0 - excentrity2 * sin(reference_latitude_ * M_PI/180.0) * sin(reference_latitude_ * M_PI/180.0));
double prime_vertical_radius = equatorial_radius * sqrt(temp);
radius_north_ = prime_vertical_radius * (1 - excentrity2) * temp;
radius_east_ = prime_vertical_radius * cos(reference_latitude_ * M_PI/180.0);
// Make sure the ROS node for Gazebo has already been initialized
if (!ros::isInitialized())
{
ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized, unable to load plugin. "
<< "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
return;
}
node_handle_ = new ros::NodeHandle(namespace_);
fix_publisher_ = node_handle_->advertise<sensor_msgs::NavSatFix>(fix_topic_, 10);
velocity_publisher_ = node_handle_->advertise<geometry_msgs::Vector3Stamped>(velocity_topic_, 10);
//.........这里部分代码省略.........
示例14: Load
////////////////////////////////////////////////////////////////////////////////
// Load the controller
void BonebrakerController::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
std::cerr << std::endl << std::endl << "Cargando plugin" << std::endl << std::endl;
world = _model->GetWorld();
// load parameters
if (!_sdf->HasElement("robotNamespace") || !_sdf->GetElement("robotNamespace")->GetValue())
namespace_.clear();
else
namespace_ = _sdf->GetElement("robotNamespace")->Get<std::string>() + "/";
if (!_sdf->HasElement("controlReferencesRW") || !_sdf->GetElement("controlReferencesRW")->GetValue())
control_ref_rw_topic_ = "/bonebraker/control_ref_gazebo";
else
control_ref_rw_topic_ = _sdf->GetElement("control_ref_gazebo")->Get<std::string>();
if (!_sdf->HasElement("joystickTopic") || !_sdf->GetElement("joystickTopic")->GetValue())
joystick_topic_ = "/bonebraker/joystick_control";
else
joystick_topic_ = _sdf->GetElement("joystickTopic")->Get<std::string>();
if (!_sdf->HasElement("jointsState") || !_sdf->GetElement("jointsState")->GetValue())
joint_state_subscriber_topic_ = "/bonebraker/joints_state";
else
joint_state_subscriber_topic_ = _sdf->GetElement("jointsState")->Get<std::string>();
if (!_sdf->HasElement("armControlReference") || !_sdf->GetElement("armControlReference")->GetValue())
arm_control_ref_topic_ = "/bonebraker/arm_control_ref_gazebo";
else
arm_control_ref_topic_ = _sdf->GetElement("armControlReference")->Get<std::string>();
if (!_sdf->HasElement("jointPosition_gazebo") || !_sdf->GetElement("jointPosition_gazebo")->GetValue())
joint_position_publisher_topic_ = "/bonebraker/set_joint_position";
else
joint_position_publisher_topic_ = _sdf->GetElement("jointPosition_gazebo")->Get<std::string>();
if (!_sdf->HasElement("imuTopic") || !_sdf->GetElement("imuTopic")->GetValue())
imu_topic_.clear();
else
imu_topic_ = _sdf->GetElement("imuTopic")->Get<std::string>();
if (!_sdf->HasElement("stateTopic") || !_sdf->GetElement("stateTopic")->GetValue())
state_topic_.clear();
else
state_topic_ = _sdf->GetElement("stateTopic")->Get<std::string>();
if (!_sdf->HasElement("bodyName") || !_sdf->GetElement("bodyName")->GetValue())
{
link = _model->GetLink();
link_name_ = link->GetName();
}
else {
link_name_ = _sdf->GetElement("bodyName")->Get<std::string>();
link = _model->GetLink(link_name_);
}
if (!link)
{
ROS_FATAL("gazebo_ros_baro plugin error: bodyName: %s does not exist\n", link_name_.c_str());
return;
}
if (!_sdf->HasElement("maxForce") || !_sdf->GetElement("maxForce")->GetValue())
max_force_ = -1;
else
max_force_ = _sdf->GetElement("maxForce")->Get<double>();
// Get inertia and mass of quadrotor body
inertia = link->GetInertial()->GetPrincipalMoments();
mass = link->GetInertial()->GetMass();
node_handle_ = new ros::NodeHandle(namespace_);
// joystick command
if (!joystick_topic_.empty())
{
ros::SubscribeOptions ops = ros::SubscribeOptions::create<arcas_msgs::Joystick>(
joystick_topic_, 1,
boost::bind(&BonebrakerController::Joystick_Callback, this, _1),
ros::VoidPtr(), &callback_queue_);
joystick_subscriber_ = node_handle_->subscribe(ops);
}
// joints State
if (!joint_state_subscriber_topic_.empty())
{
ros::SubscribeOptions ops = ros::SubscribeOptions::create<sensor_msgs::JointState>(
joint_state_subscriber_topic_, 15,
boost::bind(&BonebrakerController::JointsState_Callback, this, _1),
ros::VoidPtr(), &callback_queue_);
joint_state_subscriber_ = node_handle_->subscribe(ops);
}
// subscribe command
//.........这里部分代码省略.........
示例15: Load
void GazeboFwDynamicsPlugin::Load(physics::ModelPtr _model,
sdf::ElementPtr _sdf) {
if (kPrintOnPluginLoad) {
gzdbg << __FUNCTION__ << "() called." << std::endl;
}
gzdbg << "_model = " << _model->GetName() << std::endl;
// Store the pointer to the model.
model_ = _model;
world_ = model_->GetWorld();
namespace_.clear();
// Get the robot namespace.
if (_sdf->HasElement("robotNamespace"))
namespace_ = _sdf->GetElement("robotNamespace")->Get<std::string>();
else
gzerr << "[gazebo_fw_dynamics_plugin] Please specify a robotNamespace.\n";
// Create the node handle.
node_handle_ = transport::NodePtr(new transport::Node());
// Initialise with default namespace (typically /gazebo/default/).
node_handle_->Init();
// Get the link name.
std::string link_name;
if (_sdf->HasElement("linkName"))
link_name = _sdf->GetElement("linkName")->Get<std::string>();
else
gzerr << "[gazebo_fw_dynamics_plugin] Please specify a linkName.\n";
// Get the pointer to the link.
link_ = model_->GetLink(link_name);
if (link_ == NULL) {
gzthrow("[gazebo_fw_dynamics_plugin] Couldn't find specified link \""
<< link_name << "\".");
}
// Get the path to fixed-wing aerodynamics parameters YAML file. If not
// provided, default Techpod parameters are used.
if (_sdf->HasElement("aeroParamsYAML")) {
std::string aero_params_yaml =
_sdf->GetElement("aeroParamsYAML")->Get<std::string>();
aero_params_.LoadAeroParamsYAML(aero_params_yaml);
} else {
gzwarn << "[gazebo_fw_dynamics_plugin] No aerodynamic paramaters YAML file"
<< " specified, using default Techpod parameters.\n";
}
// Get the path to fixed-wing vehicle parameters YAML file. If not provided,
// default Techpod parameters are used.
if (_sdf->HasElement("vehicleParamsYAML")) {
std::string vehicle_params_yaml =
_sdf->GetElement("vehicleParamsYAML")->Get<std::string>();
vehicle_params_.LoadVehicleParamsYAML(vehicle_params_yaml);
} else {
gzwarn << "[gazebo_fw_dynamics_plugin] No vehicle paramaters YAML file"
<< " specified, using default Techpod parameters.\n";
}
// Get the rest of the sdf parameters.
getSdfParam<bool>(_sdf, "isInputJoystick", is_input_joystick_,
kDefaultIsInputJoystick);
getSdfParam<std::string>(_sdf, "actuatorsSubTopic",
actuators_sub_topic_,
mav_msgs::default_topics::COMMAND_ACTUATORS);
getSdfParam<std::string>(_sdf, "rollPitchYawrateThrustSubTopic",
roll_pitch_yawrate_thrust_sub_topic_,
mav_msgs::default_topics::
COMMAND_ROLL_PITCH_YAWRATE_THRUST);
getSdfParam<std::string>(_sdf, "windSpeedSubTopic",
wind_speed_sub_topic_,
mav_msgs::default_topics::WIND_SPEED);
// Listen to the update event. This event is broadcast every
// simulation iteration.
this->updateConnection_ = event::Events::ConnectWorldUpdateBegin(
boost::bind(&GazeboFwDynamicsPlugin::OnUpdate, this, _1));
}