Skip to content

Commit 0ac8a87

Browse files
authored
Merge pull request #1 from jhu-saw/rc-1.2.0
1.2.0
2 parents 266a42c + 1380fc3 commit 0ac8a87

File tree

10 files changed

+639
-138
lines changed

10 files changed

+639
-138
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
Change log
22
==========
33

4+
5+
1.2.0 (2024-01-02)
6+
==================
7+
8+
* API changes:
9+
* In JSON configuration file, `data` has been replaced by `read-commands`
10+
* Deprecated features:
11+
* `.rosintall` has been removed, migrated to `vcs`
12+
* New features:
13+
* Added support for void and write events
14+
* Added void and write commands
15+
* Added snippet of code for C#/Unity
16+
* Bug fixes:
17+
* Fixed CMake to use new cisst CMake macros, compiles with catkin and colcon
18+
419
1.1.0 (2021-04-08)
520
==================
621

CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#
2-
# (C) Copyright 2019 Johns Hopkins University (JHU), All Rights
3-
# Reserved.
2+
# (C) Copyright 2019-2024 Johns Hopkins University (JHU), All Rights Reserved.
43
#
54
# --- begin cisst license - do not edit ---
65
#
@@ -10,6 +9,18 @@
109
#
1110
# --- end cisst license ---
1211

13-
cmake_minimum_required (VERSION 2.8)
12+
cmake_minimum_required(VERSION 3.10)
13+
project (sawSocketStreamerAll VERSION 1.2.0)
14+
15+
find_package (cisst REQUIRED)
16+
include (${CISST_USE_FILE})
17+
cisst_cpack_settings (
18+
VENDOR "JHU"
19+
MAINTAINER "anton.deguet@jhu.edu")
1420

1521
add_subdirectory (components)
22+
23+
include (CPack)
24+
cpack_add_component (sawSocketStreamer)
25+
cpack_add_component (sawSocketStreamer-dev
26+
DEPENDS sawSocketStreamer)

README.md

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
This SAW component allows to stream data from most cisst/SAW components with little or no new code. It compiles on Windows, Linux and likely MacOS. It has been tested with:
44
* Linux
5-
* Streaming prmStateJoint data from sawIntuitiveResearchKit and sawIntuitiveDaVinci
5+
* Streaming `prmStateJoint` data from sawIntuitiveResearchKit and sawIntuitiveDaVinci
66

7-
It current supports UDP sockets and the data is serialized using JSON
7+
It currently supports UDP sockets and the data is serialized using the JSON
88
format. It is used to stream data from the different da Vinci robots
99
(at JHU) to HoloLens displays. On the HoloLens side, one can use the
10-
open source package [dvrk-xr](https://github.com/jhu-dvrk/dvrk-xr).
10+
open source package [dvrk-xr](https://github.com/jhu-dvrk/dvrk-xr). It can be used to receive and send data to any other SAW component (see https://github.com/jhu-cisst/cisst/wiki/cisst-libraries-and-SAW-components)
1111

1212
Based on user requests, we could add:
1313
* TCP support
@@ -24,43 +24,34 @@ Based on user requests, we could add:
2424

2525
## Adding the component
2626

27-
One can create and add the `mtsSocketStreamer` component manually in
28-
your `main` C function but we strongly recommend using the
27+
You can create and add the `mtsSocketStreamer` component manually in
28+
your `main` C/C++ code but we strongly recommend using the
2929
`cisstMultiTask` manager ability to load a configuration file to add
30-
and connect components. The dVRK main programs provide this options. See https://github.com/jhu-dvrk/sawIntuitiveResearchKit/blob/master/applications/mainQtConsoleJSON.cpp.
30+
and connect components. Most cisst/SAW (including dVRK) programs have
31+
already been updated with the code below so you likely don't need to
32+
add this and can skip to the next section. See
33+
https://github.com/jhu-dvrk/sawIntuitiveResearchKit/blob/master/applications/mainQtConsoleJSON.cpp.
3134

3235
There is first a command line option to specify one or more configuration files for the component manager:
3336
```cpp
3437
cmnCommandLineOptions options;
35-
typedef std::list<std::string> managerConfigType;
36-
managerConfigType managerConfig;
37-
38+
std::list<std::string> managerConfig;
3839
options.AddOptionMultipleValues("m", "component-manager",
3940
"JSON files to configure component manager",
4041
cmnCommandLineOptions::OPTIONAL_OPTION, &managerConfig);
4142
```
4243

4344
Then one has to use the configuration files to configure the component manager:
4445
```cpp
45-
const managerConfigType::iterator endConfig = managerConfig.end();
46-
for (managerConfigType::iterator iterConfig = managerConfig.begin();
47-
iterConfig != endConfig;
48-
++iterConfig) {
49-
if (!iterConfig->empty()) {
50-
if (!cmnPath::Exists(*iterConfig)) {
51-
CMN_LOG_INIT_ERROR << "File " << *iterConfig
52-
<< " not found!" << std::endl;
53-
} else {
54-
if (!componentManager->ConfigureJSON(*iterConfig)) {
55-
CMN_LOG_INIT_ERROR << "Configure: failed to configure component-manager for "
56-
<< *iterConfig << std::endl;
57-
return -1;
58-
}
59-
}
60-
}
46+
mtsManagerLocal * componentManager = mtsManagerLocal::GetInstance();
47+
if (!componentManager->ConfigureJSON(managerConfig)) {
48+
CMN_LOG_INIT_ERROR << "Configure: failed to configure component manager, check cisstLog for error messages" << std::endl;
49+
return -1;
6150
}
6251
```
6352
53+
## Configuration file for the component manager
54+
6455
The configuration files for the component manager will look like (more examples can be found at https://github.com/jhu-dvrk/sawIntuitiveResearchKit/tree/master/share/socket-streamer):
6556
```json
6657
/* -*- Mode: Javascript; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
@@ -118,27 +109,82 @@ The configuration files for the component manager will look like (more examples
118109
119110
```
120111

121-
## Component configuration file
112+
## Socket streamer configuration file
122113

123-
Each component created need a configuration file that specifies with read command to use to retrieve the data as well as the data type. For example:
114+
Each component created need a configuration file that specifies which read command to use to retrieve the data as well as the data type. For example:
124115
```json
125116
/* -*- Mode: Javascript; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
126117
{
127118
"ip": "10.194.86.119",
128119
"port": "48054",
129-
"data": [
120+
"read-commands": [
130121
{
131122
"name": "measured_js",
132123
"type": "prmStateJoint"
133124
}
134125
]
126+
,
127+
"void-commands": ["hold", "free"]
128+
,
129+
"write-commands": [
130+
{
131+
"name": "servo_jp",
132+
"type": "prmPositionJointSet"
133+
}
134+
]
135+
,
136+
"write-events": ["operating_state"]
135137
}
136138
```
137139

140+
138141
## Testing the streamer
139142

140-
To test the streamer, you can use the `nc` tool on Linux. The main options are `l` to listen and `u` for UDP protocol. Then you need to add the IP address and port. With the example above, try:
143+
To test the read commands and events, you can use the `nc` tool on
144+
Linux. The main options are `l` to listen and `u` for UDP protocol.
145+
Then you need to add the IP address and port. With the example above,
146+
try:
141147
```sh
142148
nc -lu 10.194.86.119 48054
143149
```
144-
At that point you should see a continous stream for text in JSON format.
150+
At that point you should see a continous stream of text in JSON format.
151+
152+
To test the void and write commands, you need to create your own code
153+
and send the command name and payload in JSON format. For void
154+
commands, send an empty string (`""`). You can find an example in
155+
Python in the sawIntuitiveResearchKit repository under
156+
`share/socket-streamer`:
157+
https://github.com/jhu-dvrk/sawIntuitiveResearchKit/blob/devel/share/socket-streamer/example.py
158+
159+
## Using the socket streamer with Unity
160+
161+
This is based on code that can be found in the `share` directory.
162+
This code was originally written by An Chi Chen and Muhammad Hadi when
163+
they were students at Johns Hopkins. Their goal was to visualize and
164+
control a dVRK PSM from Unity.
165+
166+
The main parts are setting up the socket in the ``start()``:
167+
```csharp
168+
// udp using socket
169+
data = new byte[1024];
170+
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 48051); // ensure that this port is the same as the one youre sending data from
171+
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
172+
socket.Bind(ip);
173+
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
174+
remote = (EndPoint)(sender);
175+
```
176+
177+
And then you can read from the socket using:
178+
```csharp
179+
// read in message from dVRK
180+
data = new byte[1024];
181+
socket.ReceiveFrom(data, ref remote);
182+
dVRK_msg = Encoding.UTF8.GetString(data); // dVRK_msg will then contain the data
183+
```
184+
185+
Finally an example of how you would send data:
186+
```csharp
187+
// send json strings to dVRK
188+
send_msg = Encoding.UTF8.GetBytes(pose_message); // pose_message is string to send
189+
socket.SendTo(send_msg, remote);
190+
```

colcon.pkg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "sawSocketStreamerAll",
3+
"dependencies": ["cisst"]
4+
}

components/CMakeLists.txt

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# (C) Copyright 2019 Johns Hopkins University (JHU), All Rights Reserved.
2+
# (C) Copyright 2019-2024 Johns Hopkins University (JHU), All Rights Reserved.
33
#
44
# --- begin cisst license - do not edit ---
55
#
@@ -9,42 +9,61 @@
99
#
1010
# --- end cisst license ---
1111

12-
project (sawSocketStreamer)
12+
cmake_minimum_required (VERSION 3.10)
13+
project (sawSocketStreamer VERSION 1.2.0)
1314

14-
cmake_minimum_required(VERSION 2.8)
15+
# create a list of required cisst libraries
16+
set (REQUIRED_CISST_LIBRARIES cisstCommon
17+
cisstVector
18+
cisstOSAbstraction
19+
cisstMultiTask
20+
cisstParameterTypes)
1521

16-
set (REQUIRED_CISST_LIBRARIES
17-
cisstCommon
18-
cisstVector
19-
cisstOSAbstraction
20-
cisstMultiTask
21-
cisstParameterTypes)
22+
find_package (cisst 1.2.1 REQUIRED ${REQUIRED_CISST_LIBRARIES})
2223

23-
find_package (cisst REQUIRED ${REQUIRED_CISST_LIBRARIES})
24+
if (cisst_FOUND_AS_REQUIRED)
2425

25-
if (cisst_FOUND)
2626
# load cisst configuration
2727
include (${CISST_USE_FILE})
2828

2929
# catkin/ROS paths
30-
cisst_is_catkin_build (sawSocketStreamer_IS_CATKIN_BUILT)
31-
if (sawSocketStreamer_IS_CATKIN_BUILT)
32-
set (LIBRARY_OUTPUT_PATH "${CATKIN_DEVEL_PREFIX}/lib")
33-
endif ()
34-
35-
include_directories (${CMAKE_BINARY_DIR})
30+
cisst_set_output_path ()
3631

32+
# create/configure file for find_package (sawSocketStreamer)
3733
set (sawSocketStreamer_INCLUDE_DIR
38-
"${sawSocketStreamer_SOURCE_DIR}/include")
34+
"${sawSocketStreamer_SOURCE_DIR}/include"
35+
"${sawSocketStreamer_BINARY_DIR}/include")
36+
set (sawSocketStreamer_HEADER_DIR "${sawSocketStreamer_SOURCE_DIR}/include/sawSocketStreamer")
37+
set (sawSocketStreamer_LIBRARY_DIR "${LIBRARY_OUTPUT_PATH}")
38+
set (sawSocketStreamer_LIBRARIES sawSocketStreamer)
39+
40+
# Allow c++ code to find local header files
41+
include_directories (${sawSocketStreamer_INCLUDE_DIR} ${sawSocketStreamer_BINARY_DIR})
3942

40-
include_directories (${sawSocketStreamer_INCLUDE_DIR})
43+
# add all config files for this component
44+
cisst_add_config_files (sawSocketStreamer)
4145

4246
add_library (sawSocketStreamer
43-
"include/sawSocketStreamer/sawSocketStreamerExport.h"
44-
"include/sawSocketStreamer/mtsSocketStreamer.h"
45-
"code/mtsSocketStreamer.cpp")
47+
${sawSocketStreamer_HEADER_DIR}/sawSocketStreamerExport.h
48+
code/mtsSocketStreamer.cpp
49+
${sawSocketStreamer_HEADER_DIR}/mtsSocketStreamer.h)
50+
set_target_properties (sawSocketStreamer PROPERTIES
51+
VERSION ${sawSocketStreamer_VERSION}
52+
FOLDER "sawSocketStreamer")
53+
cisst_target_link_libraries (sawSocketStreamer ${REQUIRED_CISST_LIBRARIES})
54+
55+
# Install target for headers and library
56+
install (DIRECTORY
57+
"${sawSocketStreamer_SOURCE_DIR}/include/sawSocketStreamer"
58+
"${sawSocketStreamer_BINARY_DIR}/include/sawSocketStreamer"
59+
DESTINATION include
60+
COMPONENT sawSocketStreamer-dev)
4661

47-
cisst_target_link_libraries (sawSocketStreamer
48-
${REQUIRED_CISST_LIBRARIES})
62+
install (TARGETS sawSocketStreamer COMPONENT sawSocketStreamer
63+
RUNTIME DESTINATION bin
64+
LIBRARY DESTINATION lib
65+
ARCHIVE DESTINATION lib)
4966

50-
endif (cisst_FOUND)
67+
else (cisst_FOUND_AS_REQUIRED)
68+
message ("Information: code in ${CMAKE_CURRENT_SOURCE_DIR} will not be compiled, it requires ${REQUIRED_CISST_LIBRARIES}")
69+
endif (cisst_FOUND_AS_REQUIRED)

0 commit comments

Comments
 (0)