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]'
I am having a hard time understanding the question and the details. However, I feel that you should go through the ROS Tutorials first.
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.