Skip to content

Commit

Permalink
Merge pull request #431 from gergondet/topic/mc_convex_visualization
Browse files Browse the repository at this point in the history
Introduce tools to display surfaces and convex
  • Loading branch information
gergondet authored Feb 5, 2024
2 parents 15f2b8f + abbdd5b commit 7f9465f
Show file tree
Hide file tree
Showing 32 changed files with 988 additions and 144 deletions.
14 changes: 7 additions & 7 deletions doc/_i18n/en/tutorials/tools/mc_convex_visualization.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
`mc_convex_visualization` is a tool that allows you to visualize the convexes of a robot in the RViZ application. It is part of the {% link mc_rtc_ros %} package.
`mc_convex_visualization` is a tool that allows you to visualize the convexes of a robot in any mc_rtc GUI application.

### Launching the visualization

The tool is launched as follows:

```bash
$ roslaunch mc_convex_visualization display.launch robot:=JVRC1
$ mc_convex_visualization JVRC1
```

The `robot` argument should be the same as what you would pass to the `mc_rbdyn::RobotLoader::get_robot_module` function, this can also be a robot alias. For example:
The arguments to the program should be the same as you would use as a `MainRobot` entry. It can also handle aliases. For example:

```bash
# Specify a vector of arguments
$ roslaunch mc_convex_visualization display.launch robot:="[env, `rospack find mc_env_description`, ground]"
$ mc_convex_visualization env `rospack find mc_env_description` ground
# Or an alias
$ roslaunch mc_convex_visualization display.launch robot:=env/ground
$ mc_convex_visualization env/ground
```

After launching it should look like this:
After launching an mc_rtc GUI, it should look like this:

<img src="{{site.baseurl_root}}/assets/tutorials/tools/img/mc_convex_visualization.png" alt="mc_convex_visualization in action" class="img-fluid" />

By enabling/disabling the checkboxes in the highlighted area you can show/hide selected convexes.
You can easily select which convexes to display through the interface.
12 changes: 6 additions & 6 deletions doc/_i18n/en/tutorials/tools/mc_surfaces_visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
The tool is launched as follows:

```bash
$ roslaunch mc_surfaces_visualization display.launch robot:=JVRC1
$ mc_surfaces_visualization JVRC1
```

The `robot` argument should be the same as what you would pass to the `mc_rbdyn::RobotLoader::get_robot_module` function, this can also be a robot alias. For example:
The arguments to the program should be the same as you would use as a `MainRobot` entry. It can also handle aliases. For example:

```bash
# Specify a vector of arguments
$ roslaunch mc_surfaces_visualization display.launch robot:="[env, `rospack find mc_env_description`, ground]"
$ mc_surfaces_visualization env `rospack find mc_env_description` ground
# Or an alias
$ roslaunch mc_surfaces_visualization display.launch robot:=env/ground
$ mc_surfaces_visualization env/ground
```

After launching it should look like this:
After launching an mc_rtc GUI, it should look like this:

<img src="{{site.baseurl_root}}/assets/tutorials/tools/img/mc_surfaces_visualization.png" alt="mc_surfaces_visualization in action" class="img-fluid" />

Expand All @@ -27,4 +27,4 @@ In the 3D display:
- Cylindrical surfaces are green cylinders (not seen in the screenshot);
- Gripper surfaces are represented with blue arrows representing the normal direction of the gripper's points' frame;

By enabling/disabling the checkboxes in the highlighted area you can show/hide selected surfaces.
You can easily select which surfaces to display through the interface.
22 changes: 11 additions & 11 deletions doc/_i18n/jp/tutorials/tools/mc_convex_visualization.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
`mc_convex_visualization`は、ロボットの凸領域をRVizで表示するツールです。{% link mc_rtc_ros %}パッケージに含まれています
`mc_convex_visualization` は mc_rtc GUI アプリケーションでロボットの凸部を可視化するツールです

### 可視化ツールを起動する
### ビジュアライゼーションの起動

以下のようにツールを起動します。
ツールの起動方法は以下の通りです:

```bash
$ roslaunch mc_convex_visualization display.launch robot:=JVRC1
$ mc_convex_visualization JVRC1
```

引数`robot`には、`mc_rbdyn::RobotLoader::get_robot_module`関数に渡すのと同じものを指定する必要があります。なお、この引数ではロボットの別名を使用できます。例:
プログラムの引数は `MainRobot` のエントリと同じものを指定します。エイリアスも扱えます。例えば

```bash
# 引数のベクトルとして与える方法
$ roslaunch mc_convex_visualization display.launch robot:="[env, `rospack find mc_env_description`, ground]"
# エイリアスを使用する方法
$ roslaunch mc_convex_visualization display.launch robot:=env/ground
# 引数のベクトルを指定する
$ mc_convex_visualization env `rospack find mc_env_description` ground
# またはエイリアス
$ mc_convex_visualization env/ground
```

このツールを起動すると、以下のように表示されます。
mc_rtc GUIを起動した後、これが表示されるはずです:

<img src="{{site.baseurl_root}}/assets/tutorials/tools/img/mc_convex_visualization.png" alt="mc_convex_visualization in action" class="img-fluid" />

赤い枠で囲まれた領域にあるチェックボックスをオン・オフすることで、選択した凸領域の表示・非表示を切り替えられます
インターフェースを通じて表示する凸形状を簡単に選択できます
18 changes: 9 additions & 9 deletions doc/_i18n/jp/tutorials/tools/mc_surfaces_visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

### 可視化ツールを起動する

以下のようにツールを起動します。
ツールの起動方法は以下の通りです:

```bash
$ roslaunch mc_surfaces_visualization display.launch robot:=JVRC1
$ mc_surfaces_visualization JVRC1
```

引数`robot`には、`mc_rbdyn::RobotLoader::get_robot_module`関数に渡すのと同じものを指定する必要があります。なお、この引数ではロボットの別名を使用できます。例:
プログラムの引数は `MainRobot` のエントリと同じものを指定します。エイリアスも扱えます。例えば

```bash
# 引数のベクトルとして与える方法
$ roslaunch mc_surfaces_visualization display.launch robot:="[env, `rospack find mc_env_description`, ground]"
# エイリアスとして与える方法
$ roslaunch mc_surfaces_visualization display.launch robot:=env/ground
# 引数のベクトルを指定する
$ mc_surfaces_visualization env `rospack find mc_env_description` ground
# またはエイリアス
$ mc_surfaces_visualization env/ground
```

このツールを起動すると、以下のように表示されます。
mc_rtc GUIを起動した後、これが表示されるはずです:

<img src="{{site.baseurl_root}}/assets/tutorials/tools/img/mc_surfaces_visualization.png" alt="mc_surfaces_visualization in action" class="img-fluid" />

Expand All @@ -27,4 +27,4 @@ $ roslaunch mc_surfaces_visualization display.launch robot:=env/ground
- 円筒形の表面は、緑の円筒で表示されます(このスクリーンショットには表示されていません)。
- グリッパーの表面は、グリッパーの先端方向を示すフレームの法線の向きを示す青い矢印で表されます。

赤い枠で囲まれた領域にあるチェックボックスをオン・オフすることで、選択した表面の表示・非表示を切り替えることができます。
インターフェースを通じて表示する表面を簡単に選択できます
Binary file modified doc/assets/tutorials/tools/img/mc_convex_visualization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/assets/tutorials/tools/img/mc_surfaces_visualization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions include/mc_control/ControllerServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <mc_control/ControllerServerConfiguration.h>
#include <mc_control/MCController.h>

#include <mc_rtc/gui/StateBuilder.h>
Expand Down Expand Up @@ -41,6 +42,14 @@ struct MC_CONTROL_DLLAPI ControllerServer
const std::vector<std::string> & pub_bind_uri,
const std::vector<std::string> & pull_bind_uri);

/** Construct from the provided configuration
*
* \param dt Controller timestep
*
* \param config Server configuration \ref ControllerServerConfiguration for details
*/
ControllerServer(double dt, const ControllerServerConfiguration & config);

~ControllerServer();

/** Handle requests made by the GUI users */
Expand Down
89 changes: 89 additions & 0 deletions include/mc_control/ControllerServerConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2015-2024 CNRS-UM LIRMM, CNRS-AIST JRL
*/

#pragma once

#include <mc_control/api.h>

#include <mc_rtc/Configuration.h>
#include <mc_rtc/path.h>

namespace mc_control
{

namespace details
{

// FIXME This could be inside ControllerServerConfiguration but it crashes clang-10

/** "Classic" socket configuration
*
* \tparam default_pub_port Default publisher port
*
* \tparam default_pull_port Default pull port
*/
template<uint16_t default_pub_port, uint16_t default_pull_port>
struct SocketConfiguration
{
/** Which host the socket binds to */
std::string host = "*";
/** Publisher port */
uint16_t pub_port = default_pub_port;
/** Pull request port */
uint16_t pull_port = default_pull_port;
};

} // namespace details

/** Configuration for \ref mc_control::ControllerServer */
struct MC_CONTROL_DLLAPI ControllerServerConfiguration
{
/** Controller server publication timestep
*
* If it is null or negative, the timestep will be the same as the controller
*
* If it happens to be lower than the controller's timestep then it will also be the same
*/
double timestep = 0.05;

/** IPC socket file
*
* Actual ipc sockets are created as socket + "_pub.ipc" and socket + "_rep.ipc"
*
* If nullopt, IPC is disabled
*/
std::optional<std::string> ipc_socket = mc_rtc::temp_directory_path("mc_rtc");

using TCPConfiguration = details::SocketConfiguration<4242, 4343>;

/** Configuration for the TCP socket
*
* TCP is disabled if this is nullopt
*/
std::optional<TCPConfiguration> tcp_config = TCPConfiguration{};

using WebSocketConfiguration = details::SocketConfiguration<8080, 8081>;

/** Configuration for the WebSocket socket
*
* WebSocket is disabled if this is nullopt (default)
*/
std::optional<WebSocketConfiguration> websocket_config = std::nullopt;

/** Loads from a configuration object */
void load(const mc_rtc::Configuration & config);

/** Returns the URI(s) the PUB socket should bind to */
std::vector<std::string> pub_uris() const noexcept;

/** Returns the URI(s) the PULL socket should bind to */
std::vector<std::string> pull_uris() const noexcept;

/** Prints a message about the server configuration */
void print_serving_information() const noexcept;

static ControllerServerConfiguration fromConfiguration(const mc_rtc::Configuration & config);
};

} // namespace mc_control
4 changes: 1 addition & 3 deletions include/mc_control/mc_global_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,7 @@ struct MC_CONTROL_DLLAPI MCGlobalController
std::string log_template = "mc-control";

bool enable_gui_server = true;
double gui_timestep = 0.05;
std::vector<std::string> gui_server_pub_uris;
std::vector<std::string> gui_server_rep_uris;
ControllerServerConfiguration gui_server_configuration;

Configuration config;

Expand Down
48 changes: 48 additions & 0 deletions include/mc_rbdyn/gui/RobotConvex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2015-2024 CNRS-UM LIRMM, CNRS-AIST JRL
*/

#pragma once

#include <mc_rbdyn/Robot.h>

#include <mc_rtc/gui/StateBuilder.h>
#include <mc_rtc/gui/types.h>

namespace mc_rbdyn::gui
{

static const mc_rtc::gui::PolyhedronConfig defaultConvexConfig = []()
{
mc_rtc::gui::PolyhedronConfig cfg;
cfg.triangle_color = {0, 0.8, 0, 0.5};
cfg.edge_config.color = {0, 1, 0, 1};
cfg.edge_config.width = 0.001;
cfg.show_edges = true;
cfg.show_vertices = false;
return cfg;
}();

/** Helper function to create a GUI element from a convex object inside a robot
*
* \param gui State builder where the object is added (typically controller.gui()
*
* \param category Category where the object is added
*
* \param cfg Configuration of the appearance of the convex object
*
* \param robot Robot that the convex belongs to, this reference is captured by the GUI and should survive
*
* \param name Name of the collision object added to the GUI, the object should remain in the robot while it is in the
* GUI
*
* \param publishName Name of the object in the GUI, defaults to \param name
*/
MC_RBDYN_DLLAPI void addConvexToGUI(mc_rtc::gui::StateBuilder & gui,
const std::vector<std::string> & category,
const mc_rbdyn::Robot & robot,
const std::string & name,
const mc_rtc::gui::PolyhedronConfig & cfg = defaultConvexConfig,
const std::optional<std::string> & publishName = std::nullopt);

} // namespace mc_rbdyn::gui
44 changes: 44 additions & 0 deletions include/mc_rbdyn/gui/RobotSurface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2015-2024 CNRS-UM LIRMM, CNRS-AIST JRL
*/

#pragma once

#include <mc_rbdyn/Robot.h>
#include <mc_rtc/gui/StateBuilder.h>

namespace mc_rbdyn::gui
{

static const mc_rtc::gui::LineConfig defaultSurfaceConfig = []() {
return mc_rtc::gui::LineConfig{mc_rtc::gui::Color::Green, 0.01};
}();

/** Helper function to create a GUI element from a surface object inside a robot
*
* Multiple elements can be added based on the surface type (e.g. for a planar surface, the polygon and the normal are
* added) so this function returns the names of the elements that were added
*
* \param gui State builder where the object is added (typically controller.gui()
*
* \param category Category where the object is added
*
* \param cfg Configuration for the surface polygon
*
* \param robot Robot that the surfaces belongs to, this reference is captured by the GUI and should survive
*
* \param name Name of the surface added to the GUI, the object should remain in the robot while it is in the
* GUI
*
* \param publishName Name of the object in the GUI, defaults to \param name
*
* \returns The names of the elements added by the function
*/
MC_RBDYN_DLLAPI std::vector<std::string> addSurfaceToGUI(mc_rtc::gui::StateBuilder & gui,
const std::vector<std::string> & category,
const mc_rbdyn::Robot & robot,
const std::string & name,
const mc_rtc::gui::LineConfig & cfg = defaultSurfaceConfig,
const std::optional<std::string> & publishName = std::nullopt);

} // namespace mc_rbdyn::gui
36 changes: 36 additions & 0 deletions include/mc_rtc/path.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2015-2024 CNRS-UM LIRMM, CNRS-AIST JRL
*/

#pragma once

/** This header defines a number of utility functions related to forming path in the environment
*
* They are thin wrapper around boost::filesystem to be later replaced by std::filesystem after Ubuntu 18.04 support is
* fully dropped
*/

#include <mc_rtc/utils_api.h>

#include <string>

namespace mc_rtc
{

/** Returns the path to the OS temporary directory
*
* \param suffix Added (with a path separator) to the returned path
*/
MC_RTC_UTILS_DLLAPI std::string temp_directory_path(const std::string & suffix = "");

/** Returns the path to the user's config directory
*
* On Linux/macOS this returns ${HOME}/.config/mc_rtc folder
*
* On Windows this returns the %APPDATA%/mc_rtc folder
*
* \param suffix Added (with a path separator) to the returned path
*/
MC_RTC_UTILS_DLLAPI std::string user_config_directory_path(const std::string & suffix = "");

} // namespace mc_rtc
1 change: 1 addition & 0 deletions plugins/ROS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ endif()
set(mc_rtc_ros_SRC src/mc_rtc_ros/ros.cpp)
set(mc_rtc_ros_HDR include/mc_rtc_ros/ros.h include/mc_rtc_ros/api.h)
add_library(mc_rtc_ros SHARED ${mc_rtc_ros_SRC} ${mc_rtc_ros_HDR})
add_library(mc_rtc::mc_rtc_ros ALIAS mc_rtc_ros)
set_target_properties(mc_rtc_ros PROPERTIES COMPILE_FLAGS "-DMC_RTC_ROS_EXPORTS")
target_link_libraries(mc_rtc_ros PUBLIC mc_rtc::mc_rbdyn mc_rtc_3rd_party::ROS)
target_include_directories(
Expand Down
Loading

0 comments on commit 7f9465f

Please sign in to comment.