Skip to content

Commit

Permalink
AP_DDS: Use common quaternion initialization function
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com>
  • Loading branch information
Ryanf55 authored and peterbarker committed May 30, 2024
1 parent e27dea7 commit 513938b
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions libraries/AP_DDS/AP_DDS_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ const AP_Param::GroupInfo AP_DDS_Client::var_info[] {
AP_GROUPEND
};

static void initialize(geometry_msgs_msg_Quaternion& q)
{
q.x = 0.0;
q.y = 0.0;
q.z = 0.0;
q.w = 1.0;
}

AP_DDS_Client::~AP_DDS_Client()
{
// close transport
Expand Down Expand Up @@ -226,11 +234,8 @@ void AP_DDS_Client::populate_static_transforms(tf2_msgs_msg_TFMessage& msg)
msg.transforms[i].transform.translation.y = -1 * offset[1];
msg.transforms[i].transform.translation.z = -1 * offset[2];

// Ensure rotation is normalised
msg.transforms[i].transform.rotation.x = 0.0;
msg.transforms[i].transform.rotation.y = 0.0;
msg.transforms[i].transform.rotation.z = 0.0;
msg.transforms[i].transform.rotation.w = 1.0;
// Ensure rotation is initialized.
initialize(msg.transforms[i].transform.rotation);

msg.transforms_size++;
}
Expand Down Expand Up @@ -344,10 +349,7 @@ void AP_DDS_Client::update_topic(geometry_msgs_msg_PoseStamped& msg)
msg.pose.orientation.y = orientation[2];
msg.pose.orientation.z = orientation[3];
} else {
msg.pose.orientation.x = 0.0;
msg.pose.orientation.y = 0.0;
msg.pose.orientation.z = 0.0;
msg.pose.orientation.w = 1.0;
initialize(msg.pose.orientation);
}
}

Expand Down Expand Up @@ -428,10 +430,7 @@ void AP_DDS_Client::update_topic(geographic_msgs_msg_GeoPoseStamped& msg)
msg.pose.orientation.y = orientation[2];
msg.pose.orientation.z = orientation[3];
} else {
msg.pose.orientation.x = 0.0;
msg.pose.orientation.y = 0.0;
msg.pose.orientation.z = 0.0;
msg.pose.orientation.w = 1.0;
initialize(msg.pose.orientation);
}
}

Expand All @@ -452,10 +451,7 @@ void AP_DDS_Client::update_topic(sensor_msgs_msg_Imu& msg)
msg.orientation.z = orientation[2];
msg.orientation.w = orientation[3];
} else {
msg.orientation.x = 0.0;
msg.orientation.y = 0.0;
msg.orientation.z = 0.0;
msg.orientation.w = 1.0;
initialize(msg.orientation);
}
msg.orientation_covariance[0] = -1;

Expand Down

0 comments on commit 513938b

Please sign in to comment.