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

Create a launch file, but no code for publisher and subscriber

asked 2022-09-08 02:40:25 -0500

ESSAM gravatar image

updated 2022-09-08 21:46:46 -0500

ravijoshi gravatar image

I am new to ROS. I want to create a launch file but could not get code for publisher and subscriber nodes. Below is my code:

#!/usr/bin/env python3

from time import sleep
import numpy as np

import rospy
from std_msgs.msg import Float32

currentPosition = 0.5
pub = None

def moveServo_cb(data):
    global currentPosition, pub

    targetPosition = data.data
    r = targetPosition - currentPosition
    angles = np.array( (range(190)) [0::10]) - 90
    m = ( np.sin( angles * np.pi / 180. ) + 1 ) /2

    for mi in np.nditer(m):
        pos = currentPosition + mi*r
        print ("pos:", pos)
        pub.publish(pos)
        sleep(0.05)

    currentPosition = targetPosition
    print('pos-e:', currentPosition)
    pub.publish(currentPosition)

def listener():
    global pub
    rospy.init_node('servoencoder', anonymous=True)
    rospy.Subscriber('//tilt/smooth', Float32, moveServo_cb)
    pub = rospy.Publisher('/head/tilt', Float32, queue_size=10)
    rospy.spin()

if __name__ == '__main__':
    listener()

I am trying to edit the above code to adapt the following command:

rostopic pub -1 /mavros/rc/override mavros_msgs/OverrideRCIn '[1000,1900,1100,1100,1125,1560,1500,1500,0,0,0,0,0,0,0,0,1500,1500]'
edit retag flag offensive close merge delete

Comments

I am having a hard time understanding the question and the details. However, I feel that you should go through the ROS Tutorials first.

ravijoshi gravatar image ravijoshi  ( 2022-09-08 21:49:15 -0500 )edit

Sorry for not explaining the question very well, but I want to make a launch file for this command (rostopic pub -1 /mavros/rc/override mavros_msgs/OverrideRCIn '[1000,1900,1100,1100,1125,1560,1500,1500,0,0,0,0,0,0,0,0,1500,1500]') , would you please help me doing that.

ESSAM gravatar image ESSAM  ( 2022-09-08 21:54:31 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-09-08 22:02:42 -0500

ravijoshi gravatar image

Since the question was unclear, I am quoting from the comment below.

I want to make a launch file for this command (rostopic pub -1 /mavros/rc/override mavros_msgs/OverrideRCIn '[1000,1900,1100,1100,1125,1560,1500,1500,0,0,0,0,0,0,0,0,1500,1500]')

In your launch file, please use a node in the following manner:

<node pkg="rostopic" type="rostopic" name="arbitrary_name" args="pub /pkg_topic pkg_executable_file/message" output="screen"/>

For more details, please check here.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2022-09-08 02:40:25 -0500

Seen: 33 times

Last updated: Sep 08 '22