首先来讲讲我是怎么表示每次要击打的数字。云台单侧的8个led单独表示数字1,2,3,4,5,6,7,8如下图所示
云台8个led灯全亮加上底盘右侧装甲板led灯亮表示数字9。
云台右侧led灯全亮加上底盘右侧加前方的装甲板led灯亮表示数字0
下面展示最终的效果视频。 我将100内斐波那契数列的所有数字的十位和个位拆开并存在一个列表里如:一个斐波那契数列[3,5,8,13,21,34,55,89]拆分成[3,5,8,1,3,2,1,3,4,5,5,8,9]然后按顺序依次击打。个位十位重复的数则击打两次。如:55则击打标签5两次。每次击打完成后会提示音效。
import random
list_MarkerList = RmList()
Fibonacci = [random.randint(1,5), random.randint(1,5)]
num_List = []
pid_Auto_Yaw = rm_ctrl.PIDCtrl()
pid_Auto_Pitch = rm_ctrl.PIDCtrl()
variable_X = 0
variable_Y = 0
index = 0
def System_Init():
led_ctrl.set_top_led(rm_define.armor_top_all, 69, 215, 255, rm_define.effect_always_off)
led_ctrl.set_bottom_led(rm_define.armor_bottom_all, 69, 215, 255, rm_define.effect_always_off)
robot_ctrl.set_mode(rm_define.robot_mode_free)
vision_ctrl.enable_detection(rm_define.vision_detection_marker)
vision_ctrl.set_marker_detection_distance(3)
media_ctrl.zoom_value_update(2)
pid_Auto_Yaw.set_ctrl_params(55,0,10)
pid_Auto_Pitch.set_ctrl_params(35,0,10)
gimbal_ctrl.recenter()
time.sleep(2)
def Fibonacci_Sequence():
while Fibonacci[len(Fibonacci) - 1] < 100:
Fibonacci.append(Fibonacci[len(Fibonacci) - 1] + Fibonacci[len(Fibonacci) - 2])
del Fibonacci[len(Fibonacci) -1 ]
for i in range(len(Fibonacci)):
if Fibonacci < 10:
unitPlace = Fibonacci % 10
num_List.append(unitPlace)
else:
tenPlace = int(Fibonacci / 10 % 10)
num_List.append(tenPlace)
unitPlace = Fibonacci % 10
num_List.append(unitPlace)
def Find_Target(num):
global variable_X
global variable_Y
list_MarkerList = RmList(vision_ctrl.get_marker_detection_info())
if list_MarkerList[1] > 1:
for count in range(2,len(list_MarkerList),5):
if list_MarkerList[count] == num + 10:
variable_X = list_MarkerList[count + 1]
variable_Y = list_MarkerList[count + 2]
pid_Auto_Yaw.set_error(variable_X - 0.5)
pid_Auto_Pitch.set_error(0.5 - variable_Y)
gimbal_ctrl.rotate_with_speed(pid_Auto_Yaw.get_output(),pid_Auto_Pitch.get_output())
else:
gimbal_ctrl.rotate_with_speed(0,0)
def Operation():
global index
if num_List[index] == 0:
led_ctrl.set_top_led(rm_define.armor_top_right, 69, 215, 255, rm_define.effect_always_on)
led_ctrl.set_bottom_led(rm_define.armor_bottom_front, 69, 215, 255, rm_define.effect_always_on)
led_ctrl.set_bottom_led(rm_define.armor_bottom_right, 69, 215, 255, rm_define.effect_always_on)
elif num_List[index] == 9:
led_ctrl.set_top_led(rm_define.armor_top_right, 69, 215, 255, rm_define.effect_always_on)
led_ctrl.set_bottom_led(rm_define.armor_bottom_right, 69, 215, 255, rm_define.effect_always_on)
else:
led_ctrl.set_single_led(rm_define.armor_top_right, num_List[index], rm_define.effect_always_on)
Find_Target(num_List[index])
if abs(variable_X - 0.5) < 0.01 and abs(0.5 - variable_Y) < 0.01:
time.sleep(1)
media_ctrl.play_sound(rm_define.media_sound_shoot)
led_ctrl.set_top_led(rm_define.armor_top_all, 69, 215, 255, rm_define.effect_always_off)
led_ctrl.set_bottom_led(rm_define.armor_bottom_all, 69, 215, 255, rm_define.effect_always_off)
index += 1
if index >= len(num_List):
index = len(num_List)-1
def start():
System_Init()
Fibonacci_Sequence()
while True:
Operation()