2023 Electric Competition---Sports Target Control and Automatic Tracking System (Question E) Reply to Questions from Netizens

foreword

(1)Before you ask questions in private messages, check to see if your questions are asked here!
(2)
<1> August 3, 2023, at 10:25. Add detailed answers to the third question.
<2> August 3, 2023, at 10:45. Update the problem of servo installation and the implementation of subdivided routes.
<3> August 3, 2023, at 13:50. Update the problem of how to deal with the four angles, OpenMV output PWM.
<4> August 3, 2023, at 14:00. Update system wiring issues.

Netizens ask questions

OpenMV, how to wire the steering gear

Answer:
<1> If the battery and servo are both 5V systems, then the wiring is as follows. The red ones represent VCC, and the black ones represent GND.

insert image description here

OpenMV's PWM output function cannot assign floating point data

Answer:
<1>Yes, so the PWM function output by OpenMV cannot be given floating-point data, which leads to a relatively small adjustable space for the high-level time of the PWM output of OpenMV.
<2> Generally speaking, although the adjustable space is small, the resolution of general servos cannot reach this level. So it has little impact.
<3> But what if there are still some people who insist on having enough adjustable space? Then other master controllers can be used to control the steering gear, and OpenMV outputs position information to the master controller.
<4>Related tutorials: Detailed explanation of OpenMV serial port communication ; OpenMV image processing for MCU communication ;
<5>Practical tutorial with communication protocol added: Detailed code analysis of OpenMV line inspection program in October 2022 (1) ; 2022 October 2019 OpenMV line inspection program (2) - detailed analysis of the main control code ;

What to do after getting the four angles

Answer:
<1> After you get the four corners, you can use it to find a linear relationship. That is, the pixels in the image and the high level of PWM should be in a linear relationship, as shown in the figure below. The specific linear relationship needs to be measured by yourself
<2>Tutorial about OpenMV output PWM: OpenMV output PWM to realize the control of the steering gear
<3>Because there are no two identical things in the world, so these two steering gears are given to them Outputting a PWM synchronously may also cause a straight line to fail. So it is necessary to subdivide the route. For specific implementation ideas, see my subdivision route implementation below .

insert image description here

Realization of subdivision routes

Answer:
<1>The period of a PWM is 20ms, right? Suppose I want to go from coordinate point (5,9) to (7,9). Assume that the actual test results show that the high level time of the PWM of P7 is from 500ms to 1000ms, and the high level time of the PWM of P8 is from 800us to 1300us. (In order to emphasize to those who have no reading ability, here is a hypothesis! Hypothesis! Hypothesis! I have no practical operation!)
<2> Therefore, we can try to increase the PWM high-level time of P7 and P8 at the same time every 20ms 10us. Finally, 20ms * (1000-500) / 10=1S is finished.
<3> However, some people reported that he subdivided in this way, but he still couldn't walk in a straight line. Then you can try, P7 and P8 increase the PWM high level time every 20ms is different. Finally find the right spot.
<4> Note that it is not necessary for P7 and P8 to reach the specified PWM high level time at the same time, some small deviations are invisible to the naked eye!

About the installation position of the steering gear

The two installation methods I saw in the exchange group

insert image description here
insert image description here

The third question is to look for the entire rectangular frame, or to look for the red line inspection part?

Answer:
Find the entire rectangular frame, after finding the rectangular frame. Adjust according to the code below to obtain the xy coordinates of the upper left corner of the rectangle, and then find the appropriate PWM value by yourself. It can be written to death, and someone has done it. But it's better to go to PID

import sensor, image, time

sensor.reset() # 初始化摄像头传感器
sensor.set_pixformat(sensor.RGB565) # 使用 RGB565 彩图
sensor.set_framesize(sensor.QQVGA) # 使用 QQVGA 分辨率
sensor.skip_frames(10) #跳过几帧,让新的设置生效。
sensor.set_auto_whitebal(False) # 因为是颜色识别,所以需要把白平衡关闭
clock = time.clock() # 追踪帧率,影响不大
#__________________________________________________________________
#定义寻找最大色块的函数,因为图像中有多个色块,所以追踪最大的那个
def find_max(blobs):
    max_size=0
    for blob in blobs:
        if blob[2]*blob[3] > max_size:
            max_blob=blob
            max_size = blob[2]*blob[3]
    return max_blob
#__________________________________________________________________
while(True):
	clock.tick() # 跟踪快照()之间经过的毫秒数。
	img = sensor.snapshot() # 截取一张图片
	blobs = img.find_blobs([black_threshold])  #识别黑色阈值
	max_blob = find_max(blobs)  #调用上面自定义函数,找到最大色块
	max_blob.x()  #返回识别区域左上角的x坐标
	max_blob.y()  #返回识别区域左上角的y坐标
	max_blob.w()  #返回识别区域的宽度
	max_blob.h()  #返回识别区域的长度

Is the laser installed on OpenMV? Will there be a deviation?

Answer:
<1> Definitely, at first I thought that only one OpenMV is enough. Later, it was found that the colors of the tracking lasers for the exercise questions and the basic questions were different. So you need to use two OpenMVs, and the lasers are fixed on the OpenMV.
<2> The placement of the laser and the camera will definitely cause deviations, so you need to adjust the PWM by yourself

The first question and the second question servo control is unstable

Answer:
It is really not possible to use PID, it is a pseudo-code and needs to be fine-tuned.

from pid import PID
from pyb import Servo  #从内置pyb导入servo类,也就是舵机控制类

pan_servo=Servo(1)  #定义两个舵机,对应P7引脚
tilt_servo=Servo(2) #定义两个舵机,对应P8引脚

pan_servo.calibration(500,2500,500)
tilt_servo.calibration(500,2500,500)
max_blob = find_max(blobs)  #调用上面自定义函数,找到最大色块
pan_error = max_blob.cx()-img.width()/2    #获取中心位置x坐标
tilt_error = max_blob.cy()-img.height()/2  #获取中心位置y坐标
pan_output=pan_pid.get_pid(pan_error,1)/2
tilt_output=tilt_pid.get_pid(tilt_error,1) #上面两个都是进行PID运算,
print("pan_output",pan_output)
pan_servo.angle(pan_servo.angle()+pan_output) #将最终值传入两个舵机中,追踪目标
tilt_servo.angle(tilt_servo.angle()-tilt_output)# 因为两个舵机方向和摆放位置不同,所以一个是+一个是-

Communication between OpenMV and the master

Answer:
See my OpenMV column

Servo jerk problem

Answer:
<1> Take an oscilloscope to test whether the PWM output of OpenMV is normal.
<2> The multimeter test whether the wiring is normal, if the multimeter shows that there is no problem, then solder it again.
<3> If the above two tests pass, it means that the servo is broken

About K210, OpenART mini, OpenMV code problem

Answer:
I tried it just now and found that OpenART mini can run directly on OpenMV. All suggestions, everyone, first take the ready-made code of Baidu Netdisk and try to run it. If a bug is prompted, comment the part with the bug. Should be doable.

Do you have the full code?

Answer:
<1>There is no information about K210! No! No! Read the words carefully!
<2>OpenMV does not have complete codes, all codes are in the blog!
<3> The blog video does not count the OpenMV used, it is OpenART mini, read the words carefully! The code is in the Baidu network disk I shared!

Why should OpenMV control the steering gear, can't the master control the steering gear?

Answer: Yes, but for OpenMV control, the official PID control code has been provided. We just need to adjust the P value. And if we use the main controller to control the steering gear, we still need to adjust the PID by ourselves, and it is better to use the ready-made one.

How much v does the steering gear need or 12v is directly given to him, and the single-chip microcomputer is 12v to 5v, right?

Answer:
<1> The steering gear depends on how many V you choose. If your steering gear VCC requires 12V, then supply 12V voltage. But I recommend regular mg90s servos, and sg90 servos are also fine.
<2> The power supply of the single-chip microcomputer depends on the VDD requirement of your single-chip microcomputer. If it is MSP430, STM32, the general power supply is 3.3V. If you are using STC89 series microcontroller, you need to supply 5V voltage.
<3> The GND of the steering gear, battery, OpenMV, and single-chip microcomputer must be connected together. This is where the system needs to be powered to provide a reference voltage.

There is only one OpenMV, not enough pins, right?

Answer:
<1> I took a brief look at the questions, and I personally think that if you only do basic questions, you only need one OpenMV. If not, you can communicate with the main controller through OpenMV to achieve pin expansion.
<2>Related tutorials: OpenMV serial communication details

Are pid.py and main.py to be written in a py file?

Answer: No one is main.py and the other is pid.py. Both are placed in the root directory of OpenMV. (That is, plug in the directory that OpenMV automatically opens)

insert image description here

We cannot change the code during the evaluation, so what should we do for each question?

Answer:
This must be handled by you yourself, and you must not have a code for each question. I just provide ideas, so you need to integrate these yourself.

Sir, do you have the code?

Answer:
I don't have a real object, but I just did this before, so I provided ideas.No codes! ! !

The difference between stepper motor and steering gear

answer:
I have reached a high degree of cooperation with Baidu and bing. Some questions can be directly searched on Baidu or bing!
Personally recommend using steering gear

After knowing the position of the black frame, how to track it?

Answer:
I hope you read the blog carefully. I have said it all. Read the tutorial on controlling the steering gear with OpenMV: OpenMV outputs PWM to realize the control of the steering gear . Don't ask this question again! ! !

Why did I get an error when I copied the code from the blog?

Answer:
All the pseudocodes I provided are pseudocodes, and you need to make corresponding adjustments yourself. Can't just run! ! !

How many cameras and master controllers should I use? Material recommendation

Answer:
<1> I personally think that only one OpenMV is needed, because OpenMV has an image processing unit, RGB lights, and two servos to control. Whether this is the end result is unclear. Because I have no practice. But I still think that an OpenMV can finish this question.
<2> In addition to an OpenMV, I personally recommend using a distortion-free lens. Purchase link:
https://item.taobao.com/item.htm?spm=a1z10.1-cs.w5003-18207055866.1.6b0b1dc1nPB6IZ&id=601956249175&scene=taobao_shop

I want to use stm32 to control the steering gear, and OpenMV to identify it, is it feasible? Will the workload be a little bigger?

Answer:
<1> is feasible, but as above, I still recommend only one OpenMV. If you insist on using stm32 control, I will not stop it. This is the OpenMV serial communication tutorial: OpenMV serial communication detailed explanation
<2> The workload will be larger. After all, one master control is enough, you insist on two.

E official explanation

1 Question: Can openmv be used for Question E?
Answer: Question E only prohibits laptops and desktops. Other random
2 questions: Can Raspberry Pi be used in the motion tracking system of Question E?
Answer: Same as above.
Question 3: Question E, what is the height relationship between the gimbal and the screen?
Answer: Self-determined.
Question 4: What are the basic requirements for question e? (1) Is the position of the screen always fixed when performing automatic reset?
A: Of course, only the green laser pointer can move.
Question 5: Can the motherboard in Question E use the stm32 Warship Elite mini version? Can the basic requirements in question E be reset after the test is completed?
Question 6: Are there any special requirements for the material of the screen in the moving target control and automatic tracking system for question E?
Answer: White.
Question 7: Question E 1. Is there any requirement for the placement of the camera module, which is not mentioned in the question; 2. Is the screen material of the field test confirmed? Can you provide the material name?
A: The screen can be self-contained. Other custom.
Question 8: Question E: Should the screen and the target paper be packed together when packaging? Or is it provided by the organizing committee for all teams to use uniformly during the test?
A: Bring it by yourself after sealing the box. The competition area does not provide screens and target paper.
Question 9: Are the two laser pointers in Question E always on after the test starts?
Answer: Self-determined.
Question 10: In the first question of the basic part of question E, "Press the button at any position to reset". Do we need to be able to achieve any position by ourselves or do we only need to focus on being able to reset?
Answer: The question has already stated very clearly that the light spot can return to the original point through the reset function at any position.
11Q: Is there any requirement for the height of the screen in question E?
Answer: Self-determined.
Question 12: "Any position can be reset" in the first question of the basic part of question E. We need to write a program to let the laser pointer reach the desired position and then press the button to reset or it doesn't matter which position it is, as long as it can be reset. up?
Answer: The title has already stated very clearly that the light spot can return to the original point through the reset function at any position.
13 Q: Is there a clear boundary between the test field screen and the external environment?
Answer: There is no requirement.

Guess you like

Origin blog.csdn.net/qq_63922192/article/details/132076769