Rosnode that will “listen” for std_msgs/Float64 type data and “publish” this data to the joint of the planar robot

asked 2020-09-14 11:05:06 -0500

Jabrail Chumakov gravatar image

updated 2021-04-24 02:33:36 -0500

miura gravatar image

Hello. I just started to learn ROS. So there is a task to "create a rosnode that will “listen” for std_msgs/Float64 type data and “publish” this data to the joint of the planar robot. The node should send the command to move if the any new incoming value is higher than the previous one." I want to code this node in Python, so here is what I have done so far:


import rospy, math, sys from std_msgs.msg import Float64

def movejoint1(): val = input("Value for Joint 1:\n")
pub = rospy.Publisher('/robot/joint1_position_controller/command', Float64, queue_size = 10) rospy.init_node('movejoint1', anonymous = True) rate = rospy.Rate(1) # 1 Hz

while not rospy.is_shutdown():
  old_value = 0
    while float(val) > old_value
      rospy.loginfo(str)
      pub.publish(str)
    val = input("Value for Joint 1:\n")
      else:
        rospy.loginfo(old_value)
        pub.publish(old_value)
    val = input("Value for Joint 1:\n")

    rate.sleep()

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

So the aim is to move the planar robot while the next value higher than previous one. But its not working properly. Can you help me to fix the problem?

edit retag flag offensive close merge delete