ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Karandiru's profile - activity

2020-04-03 04:41:22 -0500 received badge  Famous Question (source)
2020-04-02 11:57:45 -0500 edited question Publishing std_msgs int32 ROS Melodic , I need help

Publishing std_msgs int32 ROS Melodic , I need help Hello, Firstly im just begginer on ROS.My Professor asked me to do

2020-04-02 11:57:45 -0500 received badge  Editor (source)
2020-04-02 11:21:21 -0500 marked best answer Publishing std_msgs int32 ROS Melodic , I need help

Hello,

Firstly im just begginer on ROS.My Professor asked me to do these task;

1-Create two nodes, a chatter which publishes std_msgs and a listener to listen to chatter.

2-The message you are required to send will be assigned for each one separately.

3-The listener should get the message and print it using ROS_INFO function.

I created 2 nodes with following instructions.But i can not go further.

Chatter codes (python) ;

    #!/usr/bin/env python

import rospy
from std_msgs.msg import String

def talker():
    pub = rospy.Publisher('chatter', String, queue_size=1)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        hello_str = "hello world %s" % rospy.get_time()
        rospy.loginfo(hello_str)
        pub.publish(hello_str)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

and listener codes (python) ;

#!/usr/bin/env python
import rospy
from std_msgs.msg import String

def callback(data):
    rospy.loginfo("I heard %s", data.data)

def listener():
    rospy.init_node('listener', anonymous=True)

    rospy.Subscriber("chatter", String, callback)

    # spin() simply keeps python from exiting until this node is stopped
    rospy.spin()

if __name__ == '__main__':
    listener()

Problem here how can i complete task 3 and also i need to replace string std_msgs with int32 data type. On here http://docs.ros.org/api/std_msgs/html...

I get the logic that how the system gonna work.It will be like listener will write massage , this massage will go to chatter and chatter will publish it with int32 data type. But i don't know how to write these codes.Can you help me with writing and replacing these codes.

############################Edit

I changed the data type from string to int32 on C++ file;

    // %Tag(FULLTEXT)%
// %Tag(ROS_HEADER)%
#include "ros/ros.h"
// %EndTag(ROS_HEADER)%
// %Tag(MSG_HEADER)%
#include "std_msgs/int32.h"
// %EndTag(MSG_HEADER)%

#include <sstream>

int main(int argc, char **argv)
{
    // %Tag(INIT)%
    ros::init(argc, argv, "talker");
    // %EndTag(INIT)%

    // %Tag(NODEHANDLE)%
    ros::NodeHandle n;
    // %EndTag(NODEHANDLE)%

    // %Tag(PUBLISHER)%
    ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1);
    // %EndTag(PUBLISHER)%

    // %Tag(LOOP_RATE)%
    ros::Rate loop_rate(10);
    // %EndTag(LOOP_RATE)%

    // %Tag(ROS_OK)%
    int count = 0;
    while (ros::ok())
    {
        // %EndTag(ROS_OK)%

        // %Tag(FILL_MESSAGE)%
        std_msgs::int32 msg;

        std::stringstream ss;
        ss << "Hey " << count;
    msg.data = count;
        msg.data = ss.str();
        // %EndTag(FILL_MESSAGE)%

        // %Tag(ROSCONSOLE)%
        ROS_INFO("%s", msg.data.c_str());
        // %EndTag(ROSCONSOLE)%

        // %Tag(PUBLISH)%
        chatter_pub.publish(msg);
        // %EndTag(PUBLISH)%

        // %Tag(SPINONCE)%
        ros::spinOnce();
        // %EndTag(SPINONCE)%

        // %Tag(RATE_SLEEP)%
        loop_rate.sleep();
        // %EndTag(RATE_SLEEP)%
        ++count;
    }
    return 0;
}
// %EndTag(FULLTEXT)%

And saved it but when i run catkin_make command i get this error ;

   burak@burak:~/catkin_ws$ catkin_make
Base path: /home/burak/catkin_ws
Source space: /home/burak/catkin_ws/src
Build space: /home/burak/catkin_ws/build
Devel space: /home/burak/catkin_ws/devel
Install space: /home/burak/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/burak/catkin_ws/build"
####
####
#### Running command: "make -j8 -l8" in "/home/burak/catkin_ws/build"
####
[ 25%] Building CXX object my_package/CMakeFiles/name_of_node_listener.dir/src/02.cpp.o
[ 50%] Building CXX object my_package/CMakeFiles/name_of_node_chatter.dir/src/01.cpp.o
/home/burak/catkin_ws/src/my_package/src ...
(more)
2020-04-02 05:20:13 -0500 received badge  Notable Question (source)
2020-04-02 05:20:13 -0500 received badge  Popular Question (source)
2020-04-01 11:24:34 -0500 asked a question Publishing std_msgs int32 ROS Melodic , I need help

Publishing std_msgs int32 ROS Melodic , I need help Hello, Firstly im just begginer on ROS.My Professor asked me to do

2020-04-01 11:01:45 -0500 marked best answer Adding lines into CMakeList.txt makes an error. I need help

Hello,

Firstly i need to say im totally beginner on ROS.I managed to install it and my Professor wanted to me complete these tasks;

-Create a ROS package with your name.

-Create two nodes, a chatter which publishes std_msgs and a listener to listen to chatter.

-The message you are required to send will be assigned for each one separately.

-The listener should get the message and print it using ROS_INFO function.

So i managed to create work space , but i stucked at somewhere that wants me to add these lines into my_package/CMakeLists.txt.

lines are ;

add_executable(name_of_node_chatter src/01.cpp) ,
target_link_libraries(name_of_node_chatter ${catkin_LIBRARIES}) , 
add_dependencies(name_of_node_chatter my_package_generate_messages_cpp)

link text

But when i add them into CMakeList.txt like this ; link text

After i save this txt file i try to run catkin_make command on terminal.It gaves me this error ; link text

I don't know what to do , please can you help me to fix this problem.

2020-04-01 11:01:45 -0500 received badge  Scholar (source)
2020-03-31 05:57:43 -0500 received badge  Famous Question (source)
2020-03-28 14:17:36 -0500 received badge  Supporter (source)
2020-03-28 14:11:35 -0500 commented answer Adding lines into CMakeList.txt makes an error. I need help

Hello , First of all thank your for your explanatory answer.But eventho i tried with your instructions , terminal gave

2020-03-25 13:30:14 -0500 commented question Adding lines into CMakeList.txt makes an error. I need help

I can not access to the ubuntu right now that is why i can not copy the errors from terminal.I editted the lines.Problem

2020-03-25 13:26:13 -0500 edited question Adding lines into CMakeList.txt makes an error. I need help

Adding lines into CMakeList.txt makes an error. I need help Hello, Firstly i need to say im totally beginner on ROS.I m

2020-03-25 02:14:16 -0500 received badge  Notable Question (source)
2020-03-24 19:53:39 -0500 commented question Adding lines into CMakeList.txt makes an error. I need help

I guess i made huge mistake , without defining the chatter , i put listener code on CMakeList.txt that is why terminal g

2020-03-24 19:53:02 -0500 answered a question Adding lines into CMakeList.txt makes an error. I need help

I guess i made huge mistake , without defining the chatter , i put listener code on CMakeList.txt that is why terminal g

2020-03-24 19:53:02 -0500 received badge  Rapid Responder (source)
2020-03-24 18:06:24 -0500 received badge  Popular Question (source)
2020-03-23 15:18:55 -0500 asked a question Adding lines into CMakeList.txt makes an error. I need help

Adding lines into CMakeList.txt makes an error. I need help Hello, Firstly i need to say im totally beginner on ROS.I m