Python Ros - 将正弦波映射到电机的另一种方法

时间:2015-10-27 16:07:32

标签: python ros sine

目前我在ROS中运行的电机正确映射了正弦波,我可以通过" rqt_plot"功能在终端。代码就像是为了获得理想的效果:

    pub = rospy.Publisher("/tilt_controller/command", Float64, latch=True)

global cmd
cmd = 5.0
global count 
count = 0
global count2
count2=0
def state_callback(msg):
    #rospy.loginfo(msg)
    #print msg.current_pos
    global cmd
    global count
    global count2
    period = 50
    M = 2
    count = count +1
    if count==10:
        count = 0
        count2 = count2+1
        if count2 == period:
            count2 =0
        cmd = M*math.sin(((2*math.pi)/period)*count2)
        #cmd = cmd*(-1)
        pub.publish(cmd)

    #rospy.sleep(2.0)



def led_control_demo():

    rospy.init_node('led_control_demo')

    #rospy.Subscriber("/motor_states/pan_tilt_port", MotorStateList, motor_callback)

    rospy.Subscriber("/tilt_controller/state", JointState, state_callback)

    rospy.spin()

if __name__ == '__main__':
     #rospy.init.node("led_control_demo")
     led_control_demo()

尽管代码相当准确地映射了正弦波,但我正在寻找可能提高其准确度的替代方法,但已经碰壁了。任何人都可以建议或想到一种替代方法,以更准确地将我的动态像素电机映射到正弦波。希望这很清楚,谢谢你。

0 个答案:

没有答案