diff --git a/examples/standalone/scene_provider/README.md b/examples/standalone/scene_provider/README.md index 3183a83e4..4d83fe9ca 100644 --- a/examples/standalone/scene_provider/README.md +++ b/examples/standalone/scene_provider/README.md @@ -52,14 +52,26 @@ Echo camera pose: gz topic -e -t /gui/camera/pose ``` -Follow box: +Echo camera tracking information: + +``` +gz topic -e -t /gui/currently_tracked +``` + +Follow box from service (depricated): ``` gz service -s /gui/follow --reqtype gz.msgs.StringMsg --reptype gz.msgs.Boolean --timeout 2000 --req 'data: "box_model"' ``` +Follow box from service (depricated): + +``` +gz topic -t /gui/track -m gz.msgs.CameraTrack -p 'track_mode: 2, follow_target: "box_model"' +``` + Update follow offset: ``` -gz service -s /gui/follow/offset --reqtype gz.msgs.Vector3d --reptype gz.msgs.Boolean --timeout 2000 --req 'x: 5, y: 5, z: 5' +gz topic -t /gui/track -m gz.msgs.CameraTrack -p 'track_mode: 2, follow_target: "box_model", follow_offset: {x: -1, y: 0, z: 1}' ``` diff --git a/src/plugins/camera_tracking/CameraTracking.cc b/src/plugins/camera_tracking/CameraTracking.cc index c5bdea7c7..640b1daee 100644 --- a/src/plugins/camera_tracking/CameraTracking.cc +++ b/src/plugins/camera_tracking/CameraTracking.cc @@ -62,9 +62,16 @@ class CameraTrackingPrivate msgs::Boolean &_res); /// \brief Callback for a track message - /// \param[in] _msg Message consistes of the target to track, type of tracking, offset and pgain. + /// \param[in] _msg Message consists of the target to track, type of tracking, offset and pgain. public: void OnTrackSub(const msgs::CameraTrack &_msg); + /// \brief Callback for a follow request + /// \param[in] _msg Request message to set the target to follow. + /// \param[in] _res Response data + /// \return True if the request is received + public: bool OnFollow(const msgs::StringMsg &_msg, + msgs::Boolean &_res); + /// \brief Callback for a move to pose request. /// \param[in] _msg GUICamera request message. /// \param[in] _res Response data @@ -142,6 +149,9 @@ class CameraTrackingPrivate /// \brief Move to service public: std::string moveToService; + /// \brief Follow service + public: std::string followService; + /// \brief The pose set from the move to pose service. public: std::optional moveToPoseValue; @@ -196,6 +206,12 @@ void CameraTrackingPrivate::Initialize() gzmsg << "Move to service on [" << this->moveToService << "]" << std::endl; + this->followService = "/gui/follow"; + this->node.Advertise(this->followService, + &CameraTrackingPrivate::OnFollow, this); + gzmsg << "Follow service on [" + << this->followService << "]" << std::endl; + // track this->trackTopic = "/gui/track"; this->node.Subscribe(this->trackTopic, @@ -237,6 +253,21 @@ bool CameraTrackingPrivate::OnMoveTo(const msgs::StringMsg &_msg, return true; } +///////////////////////////////////////////////// +bool CameraTrackingPrivate::OnFollow(const msgs::StringMsg &_msg, + msgs::Boolean &_res) +{ + std::lock_guard lock(this->mutex); + this->selectedFollowTarget = _msg.data(); + + _res.set_data(true); + + this->trackMode = gz::msgs::CameraTrack::FOLLOW; + + this->newTrack = true; + return true; +} + ///////////////////////////////////////////////// void CameraTrackingPrivate::OnTrackSub(const msgs::CameraTrack &_msg) { diff --git a/src/plugins/camera_tracking/CameraTracking.qml b/src/plugins/camera_tracking/CameraTracking.qml index acdf09575..a8c82d45e 100644 --- a/src/plugins/camera_tracking/CameraTracking.qml +++ b/src/plugins/camera_tracking/CameraTracking.qml @@ -27,10 +27,12 @@ ColumnLayout { anchors.margins: 10 property string message: 'Services provided:

Topics provided:
' + '
  • /gui/camera/pose
  • '+ + '
  • /gui/currently_tracked
  • ' Label { Layout.fillWidth: true diff --git a/test/integration/camera_tracking.cc b/test/integration/camera_tracking.cc index 010e12c62..0bb8a2a3d 100644 --- a/test/integration/camera_tracking.cc +++ b/test/integration/camera_tracking.cc @@ -186,17 +186,6 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config)) EXPECT_TRUE(result); EXPECT_TRUE(rep.data()); - msgs::Vector3d reqOffset; - reqOffset.set_x(1.0); - reqOffset.set_y(1.0); - reqOffset.set_z(1.0); - result = false; - executed = node.Request("/gui/follow/offset", reqOffset, timeout, rep, - result); - EXPECT_TRUE(executed); - EXPECT_TRUE(result); - EXPECT_TRUE(rep.data()); - // Many update loops to process many events maxSleep = 600; for (auto it : {150.0, 200.0})