四十行代码实现robomaster(青少年)自瞄

pid_D = PIDCtrl()

pid_Pitch = PIDCtrl()

pid_pitch = PIDCtrl()

pid_yaw = PIDCtrl()

variable_X = 0

variable_Y = 0

variable_Makerlist = 0

variable_Maker = 0

variable_out = 0

list_Maker = RmList()

list_out = RmList()

def start():

    global variable_X

    global variable_Y

    global variable_Makerlist

    global variable_Maker

    global variable_out

    global list_Maker

    global list_out

    global pid_D

    global pid_Pitch

    global pid_pitch

    global pid_yaw

    media_ctrl.exposure_value_update(rm_define.exposure_value_small)

    vision_ctrl.set_marker_detection_distance(3)

    vision_ctrl.enable_detection(rm_define.vision_detection_marker)

    robot_ctrl.set_mode(rm_define.robot_mode_free)

    pid_yaw.set_ctrl_params(100,0.5,0.6)

    pid_Pitch.set_ctrl_params(120,0.9,0.8)

    while True:

        list_Maker=RmList(vision_ctrl.get_marker_detection_info())

        if list_Maker[1] == 1:

            variable_X = list_Maker[3]

            variable_Y = list_Maker[4]

            pid_Pitch.set_error(variable_X - 0.52)

            pid_yaw.set_error(0.49 - variable_Y)

            variable_out = pid_Pitch.get_output()

            gimbal_ctrl.rotate_with_speed(pid_Pitch.get_output() * 1,pid_yaw.get_output())

            if abs(variable_X - 0.52) < 0.05 and abs(0.49 - variable_Y) < 0.05:

                gun_ctrl.set_fire_count(2)

                gun_ctrl.fire_once()

                time.sleep(1)

        else:

            gimbal_ctrl.rotate_with_speed(0,0)

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值