我想将两个超声波传感器(HCSR-04)和一个电机连接到树莓派3 [英] I want to connect two ultrasonic sensors(HCSR-04) and a motor to raspberry pi 3

查看:647
本文介绍了我想将两个超声波传感器(HCSR-04)和一个电机连接到树莓派3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将两个超声波传感器(HCSR-04)和一个电机连接到树莓3上。在这里,我想通过检测两个传感器测量的距离来控制电机。



1.首先,在启动时,我的电机应该以恒定速度运行。 2.在检测到障碍物(例如50cm以上)时,电机应自动减速。 3.第二个传感器用作停车传感器,仅向驾驶员发出警报。



我知道如何连接两个传感器,但我无法将它们与电机用于速度控制。我想在python中使用上面的代码。 Plz帮助。



我尝试过:



不要知道如何用传感器输出控制电机

I want to connect two ultrasonic sensors(HCSR-04) and a motor to raspberry pi 3. Here, i want to control the motor by detecting the distance measured by the two sensors.

1.First , on startup, my motor should run on constant speed. 2.On detection of the obstacle(Eg. above 50cm), then the motor should automatically slow down. 3.The second sensor is used as a parking sensor which alerts the driver only.

I know how to connect the two sensors, but I am unable to interface them with motor for speed control. I want the code for above in python. Plz help.

What I have tried:

Don't know about how to control motor with sensor's output

推荐答案

对不起,这里没有人根据要求编写代码。



如果您遇到一些现有代码,我们可以提供帮助。



为您提供一点帮助:



您需要传感器和电机的编程接口(读取传感器数据并向电机写入命令),并且必须实现调节算法。



首先需要示例代码(如果存在),或者你必须根据数据表和使用的通信(I2C,SPI,串口,直接IO端口访问;无论什么适用)。



对于算法,您必须定义规则规则,然后在代码中实现它们。这最终只能由你完成,因为微调规则(或至少是规则参数)通常需要用硬件测试它们。



执行所需的任务一步步。使用传感器开始示例并编写显示值的程序。然后编写一个程序,通过传递适当的控制值(例如在命令行上)来控制电机。一旦你可以控制硬件,就开始考虑调节算法和实现。
I'm sorry, but no one here is writing code on request.

We can help if you got stuck with some existing code.

To help you a little bit:

You need the programmatic interfaces to the sensors and the motor (read sensor data and write commands to the motor) and must implement a regulation algorithm.

For the first you need example code (if it exists), or you have to implement it based on the datasheets and the used communication (I2C, SPI, serial, direct IO port access; whatever applies).

For the algorithm you have to define the regulation rules and then implement them in code. This can be done finally only by you because fine tuning of the rules (or at least the regulation parameters) usually requires testing them with the hardware.

Perform the required tasks step by step. Start for examples with the sensors and write a program that displays the values. Then write a program that controls the motor by passing appropriate control values (e.g. on the command line). Once you can control the hardware, start thinking about the regulation algorithm and implementation.


这篇关于我想将两个超声波传感器(HCSR-04)和一个电机连接到树莓派3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆