Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates GZBridge to extract the drone name from a drone in a nested S… #21768

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/modules/simulation/gz_bridge/GZBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ GZBridge::~GZBridge()

int GZBridge::init()
{
if (!_model_sim.empty()) {
std::string model_name_no_nesting = model_name_trim_nesting();

if (!_model_sim.empty()) {
// service call to create model
gz::msgs::EntityFactory req{};
req.set_sdf_filename(_model_sim + "/model.sdf");
Expand Down Expand Up @@ -181,12 +182,12 @@ int GZBridge::init()
return PX4_ERROR;
}

if (!_mixing_interface_esc.init(_model_name)) {
if (!_mixing_interface_esc.init(model_name_no_nesting)) {
PX4_ERR("failed to init ESC output");
return PX4_ERROR;
}

if (!_mixing_interface_servo.init(_model_name)) {
if (!_mixing_interface_servo.init(model_name_no_nesting)) {
PX4_ERR("failed to init servo output");
return PX4_ERROR;
}
Expand Down Expand Up @@ -471,8 +472,10 @@ void GZBridge::poseInfoCallback(const gz::msgs::Pose_V &pose)

pthread_mutex_lock(&_node_mutex);

std::string model_name_no_nesting = model_name_trim_nesting();

for (int p = 0; p < pose.pose_size(); p++) {
if (pose.pose(p).name() == _model_name) {
if (pose.pose(p).name() == model_name_no_nesting) {

const uint64_t time_us = (pose.header().stamp().sec() * 1000000) + (pose.header().stamp().nsec() / 1000);

Expand Down Expand Up @@ -751,6 +754,20 @@ int GZBridge::print_usage(const char *reason)
return 0;
}

std::string GZBridge::model_name_trim_nesting()
{
int ind_slash = _model_name.find_last_of("/");
std::string model_name_no_nesting = "";

if(ind_slash >= 0){
model_name_no_nesting = _model_name.substr(ind_slash+1, _model_name.length());
}else{
model_name_no_nesting = _model_name;
}

return model_name_no_nesting;
}

extern "C" __EXPORT int gz_bridge_main(int argc, char *argv[])
{
return GZBridge::main(argc, argv);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/simulation/gz_bridge/GZBridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class GZBridge : public ModuleBase<GZBridge>, public ModuleParams, public px4::S
void poseInfoCallback(const gz::msgs::Pose_V &pose);
void odometryCallback(const gz::msgs::OdometryWithCovariance &odometry);

std::string model_name_trim_nesting();

/**
*
* Convert a quaterion from FLU_to_ENU frames (ROS convention)
Expand Down