Skip to content

Commit

Permalink
Update camera tracking docs.
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Perseghetti <[email protected]>
  • Loading branch information
bperseghetti committed May 10, 2024
1 parent ac1c201 commit 9f715e2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
16 changes: 14 additions & 2 deletions examples/standalone/scene_provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
```
33 changes: 32 additions & 1 deletion src/plugins/camera_tracking/CameraTracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<math::Pose3d> moveToPoseValue;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<std::mutex> 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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/camera_tracking/CameraTracking.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ ColumnLayout {
anchors.margins: 10

property string message: 'Services provided:<br><ul>' +
'<li>/gui/follow/pose</li>' +
'<li>/gui/move_to</li>' +
'<li>/gui/move_to/pose</li>' +
'<li>/gui/track</li></ul><br>Topics provided:<br><ul>' +
'<li>/gui/camera/pose</li></ul>'
'<li>/gui/camera/pose</li>'+
'<li>/gui/currently_tracked</li></ul>'

Label {
Layout.fillWidth: true
Expand Down
11 changes: 0 additions & 11 deletions test/integration/camera_tracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 9f715e2

Please sign in to comment.