I'm trying to get robot /scan events notification.
It works for me:
// Subscribe to the simulated robot's laser scan topic
laserSub = nh.subscribe("/scan", 1, &MyObject::scanCallback, this);
But when I change the topic to my_robot_name/scan, it doesn't work: I don't get any robot scan notification to my callback.
// Subscribe to the simulated robot's laser scan topic
laserSub = nh.subscribe(my_robot_name + "/scan", 1, &MyObject::scanCallback, this);
I run "rostopic info my_robot_name/scan", and it looks that no publisher to my_robot_name/scan at all.
How can I solve this?
Thanks in advance.
Based on you saying than no one publishes to the topic, it is no wonder that you don't get any messages. If you want to get the messages you need firstly to publish the message.
The problem you are having is that /scan is a topic in the global namespace (prefix /). To publish it to the desired namespace you can change it in the publisher:
publish to the desired namespace ros::Publisher publisher = n.advertise<topic>("my_robot_name/scan", 1);
use a group in the launch file
If you don't have any influence on the publisher you can use remap and remap it to the desired topic:
<node ...start your node...>
<remap from="/scan" to="my_robot_name/scan" />
</node>
this way my_robot_name/scan topic will be available for your callback in the node.
Related
For a c++ and c program, I am trying to set a value for msgId or CorrelId for a particular message in IBM MQ, that will be later put to a topic. But there's an error of "Expression must be a modifiable L-value" for both the ids.
I defined the ids as
MQBYTE24 MsgId;
MQBYTE24 CorrelId;
and the MQMD is defined as default:
MQMD md = {MQMD_DEFAULT};
I cannot use the #define directive as I am trying to single out a message to be put to a topic from the publisher's end. Receive all the messages for subscriber and check for the particular message.
Is my approach of using correlIds or MsgIds correct or is there a better way for doing this?
I would expect you to have some code that looks like the following:-
memcpy(md.CorrelId, CorrelId, MQ_MSG_ID_LENGTH);
Please also remember that the message ID that you MQPUT to a topic does not end up at the subscribers. A new message ID is created for each copy of the published message that is given to each subscriber. You should use the Correlation ID instead to have it flow through to the subscriber, and ensure the subscribers are made correctly to receive the publishers correlation ID.
Read IBM MQ Little Gem #31: Publisher's CorrelId for more information about this.
This is a question related to Node-RED, but I'm asking here because I couldn't find an answer in the Node-RED forum. Maybe someone here can help me out.
I am importing a C++ addon into my Node-RED to send samples from my Analog Discovery 2 device into Node-RED using NAPI. The C++ code basically sends samples from the device to Node-RED using event emitter for each sample sent. The sampling rate is 500 samples/seconds. I can see in the Node-RED window the metric info that the function acutally sends messages upon receiving from the addon each second to Node-RED, but later on after all the samples has been sent (2mins) can see the debug node starting to receive those messages and showing them. I am interested in signal real-time analysis so that's why I would like that the messages get received by the debug node instantaneously upon sedning from the preceding function node and shown in the debug node (or sent to another node for further simultaneous processing)
I read about the Asynchronous behaviour of Node-RED and expected it to work the way I want. Is there a way to let this work simultaneously?
Thanks so much for any helpers.
const EventEmitter = require('events');
const test = require('C:/directory/build/Release/addon');
const emitter = new EventEmitter();
var a;
emitter.on('something',(evt)=>{ a=(evt);msg.payload=a;node.send(msg);node.done();})
test.Hello(emitter.emit.bind(emitter));
function.js
FDwfAnalogInStatusData(hdwf, 0, &rgdSamples[cSamples], cAvailable); //registering new available samples instantaneously into rgdSamples[]
for (int i = cSamples; i < cSamples + cAvailable; i++) {
napi_create_double(env, rgdSamples[i], &myNumber);
emit.Call({ Napi::String::New(env,"something"), myNumber });
}
addon.node
this question mainly comes due to my lack of understanding of the ROS and inability to find exactly the topic.
For turtlesim, the topic is turtle1/cmd_vel to publish command velocity messages to
For turtlebot3, what is the topic to publish cmd_vel messages to?
I have done something like this for turtlesim
command_topic_velocity = '/turtle1/cmd_vel'
publisher_velocity = rospy.Publisher(command_topic_velocity, Twist, queue_size=10)
what would command_topic_velocity be for Turtlebot3 on ROS melodic?
you shoud use cmd_vel
pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
https://github.com/ROBOTIS-GIT/turtlebot3/blob/master/turtlebot3_teleop/nodes/turtlebot3_teleop_key
and you can use rostopic nameoftopic show
I am using ROS to publish double variables on to a ROS topic. This topic will be advertising the topic so that any subscribers can access the data.
The following is the code which I have used to publish the data:
ros::NodeHandle n;
ros::Publisher Auc_pub = n.advertise<std_msgs::Float64>("/auc", 1000);
std_msgs::Float64 areaValue;
areaValue.data.push_back(Area)
Auc_pub.publish(areaValue);
Here Area is the double variable which I need to publish it over the topic /auc. I am not able to build this file as don't know how to enter the Area variable into the areaValue.
If you look at the documentation for std_msgs::Float64, it shows that it contains a single data field, which is called data and will be of type double in C++.
So, in your code, you just do:
areaValue.data = Area
assuming that Area is a double.
I suggest that you take a look at the basic Writing a simple Publisher and Subscriber tutorial on the ROS wiki.
EDIT
If what is in the original post is the entirety of your code, then it's probably not going to do exactly what you think it does. If you use the default constructor for a publisher, messages published on them are emitted once immediately. Any nodes subscribed to that topic at the moment of publishing will get the message, and then the topic will be clear. If you want any node that subscribes to the topic to receive the last message published on it, do the following:
ros::Publisher Auc_pub = n.advertise<std_msgs::Float64>("/auc", 1000, true);
That last bool true tells the publisher that it should latch messages that are published.
But you have yet another problem, presuming this is all your code: You never spin, so your node starts up, advertises its topic, publishes one message on it, and then shuts down, taking the topic with it (assuming nothing was subscribed to the topic). You need to add the following before the end of your main:
ros::spin();
This will keep the node active (and thus the topic alive) until ros::ok() returns false, I.E. until the node is killed.
Of course, your message is still only going to be published once, but the topic will at least stay alive. If you want the message to be broadcast periodically, use a ros::Timer and put the pulish call inside the timer's callback.
But seriously, please read the tutorials, they'll walk you through all of this stuff.
I finally found the solution for the problem. I had multiple ros:spinOnce() in the code. And also in the snippet
ros::NodeHandle n;
ros::Publisher Auc_pub = n.advertise<std_msgs::Float64>("/auc", 1000);
std_msgs::Float64 areaValue;
areaValue.data;
Auc_pub.publish(areaValue);
The publisher Auc_pub was created and destroyed ( As I had included the publisher in a function... my bad). Instead, i included the publisher in the main function where the publisher is created only once and stays alive until the execution completes. And, thanks to #aruisdante your suggestion helped.
I'm trying to use the new event log API to get the oldest record number from a windows event log, but cannot get the the API to return the same answer as event viewer displays (looking at the details EventRecordID). Some sample code I'm using is below:
EVT_HANDLE log = EvtOpenLog(NULL, _logName, EvtOpenChannelPath);
EVT_VARIANT buf;
DWORD need = 0;
int vlen = sizeof(EVT_VARIANT);
ZeroMemory(&buf, vlen);
EvtGetLogInfo(log, EvtLogOldestRecordNumber, vlen, &buf, &need);
UINT64 old = buf.UInt64Val;
EvtClose(log);
What the API appears to be doing is returning the record number of the oldest event in the log, but not the oldest accessible event... What I mean by that is lets say you have 10 records in your log, 1-10 and you clear your log. The next 10 events inserted will be 11-20. If you use the API, it will return 1, not 11 like event viewer displays. If you try to retrieve event 1 using EvtQuery/EvtNext it will fail and not return an event -- as I would expect.
Does anyone have experience with this method? What am I doing wrong? I have used the method successfully with other properties (i.e. EvtLogNumberOfLogRecords), but cannot get this property (EvtLogOldestRecordNumber) to behave as expected.
http://msdn.microsoft.com/en-us/library/aa385385(v=VS.85).aspx
I was not able to get the new API to work for the oldest record number and had to revert to using the legacy API to retrieve the oldest record number.
msdn.microsoft.com/en-us/library/aa363665(VS.85).aspx