'How to correctly initialize an event
I'm a student and currently experimenting with the QoS-settings in ROS 2. I'm trying to implement the (RMW_EVENT_REQUESTED_DEADLINE_MISSED) event.
First I declare the subscription and event:
static const rmw_subscription_t sub1
{
"sub1", (void *) "gets deadline missed", "topic1"
};
static const rmw_event_t deadline_missed =
{
"event 1" , (void *) "deadline missed", RMW_EVENT_REQUESTED_DEADLINE_MISSED
};
After that I try to initialize the event:
rmw_subscription_event_init(deadline_missed, sub1, RMW_EVENT_REQUESTED_DEADLINE_MISSED);
But I get an error ( No matching function for call to 'rmw_subscription_event_init')
The program suggests me to change my subscription and event declaration to:
static const rmw_subscription_t *const sub1
{
"sub1", (void *) "gets deadline missed", "topic1"
};
static rmw_event_t *const deadline_missed =
{
"event 1" , (void *) "deadline missed", RMW_EVENT_REQUESTED_DEADLINE_MISSED
};
But then I get the following error (Excess elements in scalar initializer).
How do I fix this problem and which of those 2 cases is the best? Or is there a completely other way of creating this event?
Thanks in advance!
Solution 1:[1]
rmw_subscription_event_init
takes pointers as argument so you need to pass the memory adress of your objects rmw_subscription_t
and rmw_event_t
:
rmw_subscription_event_init(&deadline_missed, &sub1, RMW_EVENT_REQUESTED_DEADLINE_MISSED);
You can also change the definition of sub1
and deadline_missed
to be pointers (as you suggested), but in that case you need to properly initialize the pointers to your structs. I recommand reading these excellent answers for more information.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |