How to project the value of joystick operating amount on the prompt in teleoperating.

asked 2019-06-24 17:07:18 -0500

K.K gravatar image

Dear ROS user

I want to project the value of Joy Stick operating amount on the prompt. I use 2PC, PC1 connects joystick and PC2 doesn't connect it and PC1 and PC2 connect each other in wireless enviroment.

PC1 has the node which is written for sending the value of operating amount, PC2 has the node which has receive and show the value on the prompt.

I launch roscore at PC1side and check the condition with rqt_graph. As the result, PC1 and PC2 connect crrectly, but PC2 doesn't show the value on the prompt. I can't identify the cause.

If someone know how to solve it, please tell me.

I will write PC1 , PC2 setting of IP adress in bashfile , publisher(PC1) node and subscriber(PC2) node.

(PC1)node

import rospy 
from sensor_msgs.msg import Joy
from geometry_msgs.msg import Twist

class JoyTwist(object):
    def __init__(self):
        self._joy_sub = rospy.Subscriber('joy', Joy, self.joy_callback, queue_size=1)
        self._twist_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)

    def joy_callback(self, joy_msg):
        if joy_msg.buttons[0] == 1:
         twist = Twist()
         twist.linear.x = joy_msg.axes[1] * 0.5
         twist.angular.z = joy_msg.axes[0] * 1.0
         self._twist_pub.publish(twist)

if __name__ == '__main__':
    rospy.init_node('joy_twist')
    joy_twist = JoyTwist()
    rospy.spin()

(PC2)node

#!/usr/bin/env python

import rospy
from std_msgs.msg import String

from sensor_msgs.msg import Joy
from geometry_msgs.msg import Twist

class JoyTwist(object):
    def callback(twist):
        rospy.loginfo(twist.angular.z)

    rospy.init_node('JoyC_subscribe')
    sub = rospy.Subscriber('cmd_vel', Twist, callback)
    rospy.spin()

PC1 IP adress setting

export ROS_HOSTNAME=192.168.3.4
export ROS_MASTER_URI=http://192.168.3.4:11311

PC2 IP adress setting

export ROS_HOSTNAME=192.168.3.16
export ROS_MASTER_URI=http://192.168.3.4:11311
edit retag flag offensive close merge delete