Crossing gaps in the line - a recusive algorithm
1818 2 2019-7-25
Uploading and Loding Picture ...(0/1)
o(^-^)o
MarkusXL
lvl.4
United States
Offline

https://youtu.be/JgAg6PR6XoY

Works pretty well, but a little conservative and shy - you can make the search pattern bolder and more confident and faster!


Code:

pid_Test = rm_ctrl.PIDCtrl()
list_LineList = RmList()
variable_X = 0
variable_Turned = 0
variable_Turn2 = 0
def user_defined_ReFindPath():
    global variable_X
    global variable_Turned
    global variable_Turn2
    global list_LineList
    global pid_Test
    while not len(list_LineList) == 42:
        gimbal_ctrl.yaw_ctrl(variable_Turn2)
        variable_Turned = variable_Turned + 1
        time.sleep(0.5)
        if variable_Turned > 4:
            gun_ctrl.fire_once()
            variable_Turned = 0
            variable_Turn2 = variable_Turn2 * -1
            chassis_ctrl.set_trans_speed(0.2)
            chassis_ctrl.move_with_distance(0,0.1)
            time.sleep(0.5)
            chassis_ctrl.stop()
        list_LineList=RmList(vision_ctrl.get_line_detection_info())
def start():
    global variable_X
    global variable_Turned
    global variable_Turn2
    global list_LineList
    global pid_Test
    variable_Turned = 0
    variable_Turn2 = -5
    robot_ctrl.set_mode(rm_define.robot_mode_chassis_follow)
    pid_Test.set_ctrl_params(330,0,28)
    led_ctrl.set_bottom_led(rm_define.armor_bottom_all, 0, 127, 70, rm_define.effect_flash)
    led_ctrl.set_top_led(rm_define.armor_top_all, 161, 255, 69, rm_define.effect_always_on)
    vision_ctrl.enable_detection(rm_define.vision_detection_line)
    vision_ctrl.line_follow_color_set(rm_define.line_follow_color_blue)
    gimbal_ctrl.set_rotate_speed(30)
    gimbal_ctrl.pitch_ctrl(-20)
    while True:
        list_LineList=RmList(vision_ctrl.get_line_detection_info())
        if len(list_LineList) == 42:
            if list_LineList[2] <= 1:
                variable_X = list_LineList[19]
                pid_Test.set_error(variable_X - 0.5)
                gimbal_ctrl.rotate_with_speed(pid_Test.get_output(),0)
                chassis_ctrl.set_trans_speed(0.3)
                chassis_ctrl.move(0)
                time.sleep(0.05)
        else:
            chassis_ctrl.stop()
            led_ctrl.set_bottom_led(rm_define.armor_bottom_all, 255, 0, 0, rm_define.effect_always_on)
            led_ctrl.set_top_led(rm_define.armor_top_all, 255, 0, 0, rm_define.effect_marquee)
            time.sleep(2)
            user_defined_ReFindPath()

            led_ctrl.set_bottom_led(rm_define.armor_bottom_all, 0, 127, 70, rm_define.effect_flash)
            led_ctrl.set_top_led(rm_define.armor_top_all, 161, 255, 69, rm_define.effect_always_on)



2019-7-25
Use props
David Martin Graff
First Officer
Flight distance : 106566408 ft
  • >>>
United States
Offline

Nicely done - thanks again for sharing!
2019-7-25
Use props
Malibu Aerial
lvl.4
Flight distance : 143898 ft
United States
Offline

Looks good, I'll have to try it.  Thanks for sharing!
2019-7-26
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules