Compare commits

...

2 Commits

Author SHA1 Message Date
JaeyoungLim 7de2f1d618 Fix 2025-12-01 02:49:10 -08:00
JaeyoungLim 2ea7cc015b Make gz camera follow vehicle closely
F
2025-11-30 16:56:15 -08:00
2 changed files with 18 additions and 0 deletions
@@ -89,6 +89,8 @@ int GZBridge::init()
return PX4_ERROR;
}
_camera_pub = _node.Advertise<gz::msgs::GUICamera>("/gui/move_to/pose");
// OPTIONAL:
if (_sim_gz_en_gps.get()) {
if (!subscribeNavsat(false)) {
@@ -506,6 +508,21 @@ void GZBridge::poseInfoCallback(const gz::msgs::Pose_V &msg)
const double dt = math::constrain((timestamp - _timestamp_prev) * 1e-6, 0.001, 0.1);
_timestamp_prev = timestamp;
gz::math::Pose3d model_pose = gz::msgs::Convert(msg.pose(p));
gz::math::Vector3d offset = gz::math::Vector3d(5.0, 5.0, 5.0);
double offset_yaw = 0.1;
gz::math::Vector3d offset_world = model_pose.Rot().RotateVector(offset);
gz::math::Vector3d camera_position = model_pose.Pos() + offset_world;
double model_yaw = model_pose.Rot().Yaw();
// Camera looks at the model with specified pitch and yaw offset
gz::math::Quaterniond camera_orientation(0.0, -0.1, model_yaw + offset_yaw);
gz::msgs::GUICamera camera_msg;
gz::msgs::Set(camera_msg.mutable_pose()->mutable_position(), camera_position);
gz::msgs::Set(camera_msg.mutable_pose()->mutable_orientation(), camera_orientation);
// camera_msg.set_duration(0.1);
_camera_pub.Publish(camera_msg);
gz::msgs::Vector3d pose_position = msg.pose(p).position();
gz::msgs::Quaternion pose_orientation = msg.pose(p).orientation();
@@ -178,6 +178,7 @@ private:
bool _realtime_clock_set{false};
gz::transport::Node _node;
gz::transport::Node::Publisher _camera_pub;
// GPS noise model
float _gps_pos_noise_n = 0.0f;