How to publish Twist messages cmd_vel to turtlebot on ROS? - python-2.7

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

Related

Correlation Id and Message Id in IBM MQ

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.

Doesn't get robots /scan events [ROS]

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.

c++ quickfix failure to send

I'm having an unexpected issue with a c++ quickfix client application using FIX 4.4. I form marketdatarequest and populate it and then call send which returns true. The message is not found in the message or event log files.
No error seems to be reported - what could be happening?
FIX44::MarketDataRequest request(FIX::MDReqID(tmp)
, FIX::SubscriptionRequestType('1')
, FIX::MarketDepth(depth)); // 0 is full depth
FIX::SubscriptionRequestType subType(FIX::SubscriptionRequestType_SNAPSHOT);
FIX44::MarketDataRequest::NoRelatedSym symbolGroup;
symbolGroup.set(FIX::Symbol(I.subID));
request.addGroup(symbolGroup);
FIX::Header &header = request.getHeader();
header.setField(FIX::SenderCompID(sessionSenderID));
header.setField(FIX::TargetCompID(sessionTargetID));
if (FIX::Session::sendToTarget(request) == false)
return false;
My FixConfig looks like:
[DEFAULT]
HeartBtInt=30
ResetOnLogout=Y
ResetOnLogon=Y
ResetOnDisconnect=Y
ConnectionType=initiator
UseDataDictionary=Y
FileLogPath=logs
[SESSION]
FileLogPath=logs
BeginString=FIX.4.4
DataDictionary=XXXXX
ConnectionType=initiator
ReconnectInterval=60
TargetCompID=tCompID
SenderCompID=sCompID
SocketConnectPort=123456
SocketConnectHost=XX.XX.XXX.XX
SocketConnectProtocol=TCP
StartTime=01:05:00
EndTime=23:05:30
FileLogPath=logs
FileStorePath=logs
SocketUseSSL=N
thanks for any help,
Mark
Mark, just couple of notes not really related to your question but which you may found useful:
you dont have to explicitly set TargetCompId/SenderCompId for each message, engine will do it for you.
Do not place logic into callbacks(like you did with market data subscription in onLogon). Better create additional thread which will consume events from you listener, make decisions and take an action.

Need information regarding publishing a double variable on to a ROS topic

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.

OpenDDS and notification of publisher presence

Problem: How can I get liveliness notifications of booth publisher connect and disconnect?
Background:
I'm working with a OpenDDS implementation where I have a publisher and a subscriber of a data type (dt), using the same topic, located on separate computers.
The reader on the subscriber side has overridden implementations of on_data_available(...)and on_liveliness_changed(...). My subscriber is started first, resulting in a callback to on_liveliness_changed(...) which says that there are no writers available. When the publisher is started I get a new callback to telling me there is a writer available, and when the publisher publishes, on_data_available(...) is called. So far everything is working as expected.
The writer on the publisher has a overridden implementation of on_publication_matched(...). When starting the publisher, on_publication_matched(...) gets called since we already have a subscriber started.
The problem is that when the publisher disconnects, I get no callback to on_liveliness_changed(...) on the reader side, nor do I get a new callback when the publisher is started again.
I have tried to change the readerQos by setting the readerQos.liveliness.lease_duration.
But the result is that the on_data_available(...) never gets called, and the only callback to on_liveliness_changed(...) is at startup, telling me that there are no publishers.
DDS::DataReaderQos readerQos;
DDS::StatusKind mask = DDS::DATA_AVAILABLE_STATUS | DDS::LIVELINESS_CHANGED_STATUS | DDS::LIVELINESS_LOST_STATUS ;
m_subscriber->get_default_datareader_qos( readerQos );
DDS::Duration_t t = { 3, 0 };
readerQos.liveliness.lease_duration = t;
m_binary_Reader = static_cast<binary::binary_tdatareader( m_subscriber->create_datareader(m_Sender_Topic,readerQos,this, mask, 0, false) );
/Kristofer
Ok, guess there aren't many DDS users here.
After some research I found that a reader/writer match occurs only if this compatibility criterion is satisfied: offered lease_duration <= requested lease_duration
The solution was to set the writer QoS to offer the same liveliness. There is probably a way of checking if the requested reader QoS could be supplied by the corresponding writer, and if not, use a "lower" QoS, all thou I haven't tried it yet.
In the on_liveliness_changed callback method I simply evaluated the alive_count in the from the LivelinessChangedStatus.
/Kristofer