5 auto position = pose_message.position();
6 auto orientation = pose_message.orientation();
8 return ignition::math::Pose3d(position.x(), position.y(), position.z(), orientation.w(), orientation.x(),
9 orientation.y(), orientation.z());
14 this->m_gazebo_node = gazebo::transport::NodePtr(
new gazebo::transport::Node());
15 this->m_gazebo_node->Init();
17 this->m_camera_pose_publisher = this->m_gazebo_node->Advertise<gazebo::msgs::Pose>(
TOPIC_CAMERA_POSE);
18 this->m_racer_pose_subscriber =
19 this->m_gazebo_node->Subscribe(
TOPIC_GAZEBO_POSES, &ChaseCam::gazeboPosesCallback,
this);
22 void ChaseCam::gazeboPosesCallback(ConstPosesStampedPtr&
message)
24 for (
int i = 0; i < message->pose_size(); i++)
26 auto pose_message = message->pose(i);
30 this->updateCamera(pose);
36 void ChaseCam::updateCamera(ignition::math::Pose3d& car_pose)
38 auto car_rotation = ignition::math::Quaterniond(0, 0, car_pose.Rot().Yaw());
40 this->m_last_position = car_pose.Pos() * 0.1 + this->m_last_position * 0.9;
41 this->m_last_rotation = ignition::math::Quaterniond::Slerp(0.08, this->m_last_rotation, car_rotation,
true);
43 auto camera_position = this->m_last_position + this->m_last_rotation *
CAMERA_OFFSET;
45 auto camera_pose = ignition::math::Pose3d(camera_position, this->m_last_rotation);
46 this->publishCameraPose(camera_pose);
49 void ChaseCam::publishCameraPose(ignition::math::Pose3d& pose)
52 gazebo::msgs::Set(&message, pose);
53 this->m_camera_pose_publisher->Publish(message);
56 int main(
int argc,
char** argv)
58 gazebo::client::setup(argc, argv);
63 gazebo::common::Time::MSleep(1000);
66 gazebo::client::shutdown();
Chase camera Gazebo node that listens to racer pose messages and updates the Gazebo client camera pos...
constexpr const char * TOPIC_CAMERA_POSE
const ignition::math::Vector3d CAMERA_OFFSET(-1.7, 0, 0.5)
constexpr const char * TOPIC_GAZEBO_POSES
ignition::math::Pose3d convertPoseMessageToPose(const gazebo::msgs::Pose pose_message)
int main(int argc, char **argv)
const std::string CAR_NAME