Skip to content

Commit

Permalink
Add service to change camera follow pgain.
Browse files Browse the repository at this point in the history
Example: gz service -s /gui/follow/pgain --reqtype gz.msgs.Double --reptype gz.msgs.Boolean --timeout 2000 --req 'data: 1.0'

Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
  • Loading branch information
bperseghetti committed Jan 28, 2023
1 parent a9605c0 commit 0b70f45
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
12 changes: 12 additions & 0 deletions examples/standalone/scene_provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ 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'
```

Set next follow pgain:

```
gz service -s /gui/follow/pgain --reqtype gz.msgs.Double --reptype gz.msgs.Boolean --timeout 2000 --req 'data: 1.0'
```

Update follow offset with new pgain:

```
gz service -s /gui/follow/offset --reqtype gz.msgs.Vector3d --reptype gz.msgs.Boolean --timeout 2000 --req 'x: 1, y: 1, z: 5'
```
40 changes: 34 additions & 6 deletions src/plugins/camera_tracking/CameraTracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class gz::gui::plugins::CameraTrackingPrivate
public: bool OnFollowOffset(const msgs::Vector3d &_msg,
msgs::Boolean &_res);

/// \brief Callback for a follow pgain request
/// \param[in] _msg Request message to set the camera's follow pgain.
/// \param[in] _res Response data
/// \return True if the request is received
public: bool OnFollowPGain(const msgs::Double &_msg,
msgs::Boolean &_res);

/// \brief Callback when a move to animation is complete
private: void OnMoveToComplete();

Expand Down Expand Up @@ -140,6 +147,9 @@ class gz::gui::plugins::CameraTrackingPrivate
/// \brief Follow offset service
public: std::string followOffsetService;

/// \brief Follow offset pgain service
public: std::string followPGainService;

/// \brief Camera pose topic
public: std::string cameraPoseTopic;

Expand Down Expand Up @@ -208,12 +218,19 @@ void CameraTrackingPrivate::Initialize()
gzmsg << "Camera pose topic advertised on ["
<< this->cameraPoseTopic << "]" << std::endl;

// follow offset
this->followOffsetService = "/gui/follow/offset";
this->node.Advertise(this->followOffsetService,
&CameraTrackingPrivate::OnFollowOffset, this);
gzmsg << "Follow offset service on ["
<< this->followOffsetService << "]" << std::endl;
// follow offset
this->followOffsetService = "/gui/follow/offset";
this->node.Advertise(this->followOffsetService,
&CameraTrackingPrivate::OnFollowOffset, this);
gzmsg << "Follow offset service on ["
<< this->followOffsetService << "]" << std::endl;

// follow pgain
this->followPGainService = "/gui/follow/pgain";
this->node.Advertise(this->followPGainService,
&CameraTrackingPrivate::OnFollowPGain, this);
gzmsg << "Follow P gain service on ["
<< this->followPGainService << "]" << std::endl;
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -267,6 +284,17 @@ bool CameraTrackingPrivate::OnFollowOffset(const msgs::Vector3d &_msg,
return true;
}

/////////////////////////////////////////////////
bool CameraTrackingPrivate::OnFollowPGain(const msgs::Double &_msg,
msgs::Boolean &_res)
{
std::lock_guard<std::mutex> lock(this->mutex);
this->followPGain = msgs::Convert(_msg);

_res.set_data(true);
return true;
}

/////////////////////////////////////////////////
bool CameraTrackingPrivate::OnMoveToPose(const msgs::GUICamera &_msg,
msgs::Boolean &_res)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/camera_tracking/CameraTracking.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace plugins
/// * `/gui/move_to/pose`: Move the user camera to a given pose.
/// * `/gui/follow`: Set the user camera to follow a given target,
/// identified by name.
/// * `/gui/follow/pgain`: Set the pgain for following.
/// * `/gui/follow/offset`: Set the offset for following.
///
/// Topics:
Expand Down
1 change: 1 addition & 0 deletions src/plugins/camera_tracking/CameraTracking.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ColumnLayout {
'<li>/gui/move_to</li>' +
'<li>/gui/move_to/pose</li>' +
'<li>/gui/follow</li>' +
'<li>/gui/follow/pgain</li>' +
'<li>/gui/follow/offset</li></ul><br>Topics provided:<br><ul>' +
'<li>/gui/camera/pose</li></ul>'

Expand Down
8 changes: 8 additions & 0 deletions test/integration/camera_tracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
EXPECT_TRUE(result);
EXPECT_TRUE(rep.data());

msgs::Double reqPGain;
reqPGain.set_data(1.0);
executed = node.Request("/gui/follow/pgain", reqPGain, timeout, rep,
result);
EXPECT_TRUE(executed);
EXPECT_TRUE(result);
EXPECT_TRUE(rep.data());

// Many update loops to process many events
maxSleep = 300;
for (auto it : {150.0, 200.0})
Expand Down

0 comments on commit 0b70f45

Please sign in to comment.