Comments (3)
I believe message_type =
should be String
not String()
from rclpy.
serialized message seems to be wrong, the following works w/o any problem.
def main():
msg = String()
msg.data = 'Hello, world!'
msg_serialized = serialize_message(msg)
print(msg_serialized)
msg_deserialized = deserialize_message(msg_serialized, String)
print(msg_deserialized)
the output is,
b'\x00\x01\x00\x00\x0e\x00\x00\x00Hello, world!\x00'
std_msgs.msg.String(data='Hello, world!')
from rclpy.
I have tried what you suggest @fujitatomoya and I'm able to successfully decode the string, the issue is that my data come from foxglove_bridge and the encoding seems to be a bit different.
To give a bit more context, I try to create a ws-client to subscribe to a topic with a foxglove_bridge (https://github.com/foxglove/ros-foxglove-bridge), so I have:
ROS2 string publisher -> foxglove_bridge-> ws-client
The data copy pasted in the question is the string received from the foxglove_bridge.
Here is the complete python script of the ws-client:
import asyncio
import websockets
import json
from std_msgs.msg import String
from rclpy.serialization import deserialize_message
from mcap.reader import make_reader
from mcap_ros2.reader import read_ros2_messages
from mcap_ros2.decoder import DecoderFactory
async def handle_event(websocket, message, subscribed):
# Handle different types of events here
print("Received event:", message)
if subscribed == False:
subscribed = True
subsriber = {
"op": "subscribe",
"subscriptions": [
{"id": 3, "channelId": 3} # replace by the selected channel id the subscribe
]
}
await websocket.send(json.dumps(subsriber))
if type(message) == bytes:
print("Start to deserialize")
message_type = String()
# Decode the message here
#decoded_data = deserialize_message(serialized_message=message, message_type=message_type)
# print(decoded_data)
async def connect_to_server():
uri = "ws://0.0.0.0:9090" # Change this to your server URI
subscribed = False
async with websockets.connect(uri, subprotocols=["foxglove.websocket.v1"]) as websocket:
print("Connected to server.")
try:
while True:
message = await websocket.recv()
await handle_event(websocket, message, subscribed)
subscribed = True
except websockets.ConnectionClosed:
print("Connection to server closed.")
async def main():
await connect_to_server()
if __name__ == "__main__":
asyncio.run(main())
from rclpy.
Related Issues (20)
- Feature Request for MultiProcessExecutor HOT 2
- async wait/sleep implementation HOT 4
- KeyError in ActionServer._execute_goal HOT 5
- [Feature] Static Type Checking With ament_mypy HOT 1
- Added optional TimerInfo to timer callback
- :farmer: `test_guard_condition` failing consisntent in CycloneDDS HOT 1
- Add utility function to get datetime.datetime from Time HOT 1
- Rate object's destroy() does not destroy the underlying Timer object, leading to CPU usage explosion HOT 6
- Update the executor to not throw ExternalShutdownException
- Make nodes, publishers, subscriptions, services, clients, action servers, action clients Python context managers
- aarch64 cross compiling HOT 9
- Executors mishandle invalid waitables HOT 4
- context.on_shutdown is never called HOT 7
- Bad interaction between `torch.compile` and `MultiThreadedExecutor` HOT 1
- First Time Contributors Documentation (CONTRIBUTING.md) HOT 2
- Python message with uint32 Assertion `PyLong_Check(field)' failed HOT 2
- Memory leak in ActionServer. ```taken_data = self._handle.take_goal_request``` HOT 4
- [Bug] error when node created with rclpy.node.Node HOT 1
- Async tasks are processed in LIFO not FIFO HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rclpy.