Hagler 2019. 3. 11. 18:59
#!/usr/bin/env python
# license removed for brevity

import rospy
from std_msgs.msg import UInt16MultiArray
from std_msgs.msg import UInt16

pub = rospy.Publisher('control',UInt16MultiArray,queue_size=10)
cmd_vel = UInt16MultiArray()
cmd_vel.data = [0,0]

def callback1(msg):
rospy.loginfo(msg.data[0])
cmd_vel.data[0] = msg.data[0]
cmd_vel.data[1] = msg.data[1]

pub.publish(cmd_vel)

def callback2(msg):
cmd_vel.data[0] = 32
cmd_vel.data[1] = msg.data
if cmd_vel.data[1] > 100 or cmd_vel.data[1] < 70:
cmd_vel.data[0] = cmd_vel.data[0] + 3
#cmd_vel.data[1] = cmd_vel.data[1] * 0.9
rospy.loginfo(cmd_vel)
pub.publish(cmd_vel)

def motor_control():
rospy.init_node('motor_control',anonymous=True)
rospy.Subscriber("roscar_teleop_cmd_vel",UInt16MultiArray,callback1)
rospy.Subscriber("angle",UInt16,callback2)
pub.publish(cmd_vel)
rospy.spin()

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