Robotics StackExchange | Archived questions

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

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]'

Asked by ESSAM on 2022-09-08 02:40:25 UTC

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.

Asked by ravijoshi on 2022-09-08 21:49:15 UTC

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.

Asked by ESSAM on 2022-09-08 21:54:31 UTC

Answers

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.

Asked by ravijoshi on 2022-09-08 22:02:42 UTC

Comments