tiiuae / rclgo

ROS Client Library for Golang
Apache License 2.0
84 stars 14 forks source link

example StringSubscription #14

Closed ra014620 closed 1 year ago

ra014620 commented 1 year ago

Do you have any example code to create and use a StringSubscription along with a callback function? I've tried but getting an error so I'm probably doing something wrong.

[*rclgo.SubscriptionTakeFailed] rcltake() failed for subscription='&{rosID:1 waitable:{:{} v:0} TopicName:py_pubsub Ros2MsgType:{} Callback:0x6476a0 node:0xc0001ea770 rcl_subscription_t:0x28cab10 topicName:0x2935b90}' error not set

ra014620 commented 1 year ago

I got a subscriber working by adapting the custom_message_package/greeter example. Which Spin() function should I use? node.Spin(ctx) or rclgo.Spin(ctx)? They both seem to work.

lassilaiho commented 1 year ago

It depends on what resources you want to spin. The package level Spin function spins all ROS resources that are created by calling package level functions or methods of rclgo.DefaultContext() or descending from them. The node Spin method does the same thing for resources created by calling the methods on the node. If you have only subscriptions, publishers etc. created by calling methods on a single node created with the default context, you can use either Spin function.

ra014620 commented 1 year ago

Got it. Thank you!