pibot:lesson3
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
pibot:lesson3 [2021/07/09 16:49] – Added cellbg colors to wiring tables to match wire colors jstruebel | pibot:lesson3 [2022/10/20 19:53] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Objective ====== | ||
+ | |||
+ | This lesson will show you how to make the PiBot avoid obstacles in front of it. First it will show you how to add the ultrasonic distance sensor to the PiBot. Then it will show you how to program the PiBot to avoid obstacles that are in front of it. Finally it will describe how the electronics let the PiBot " | ||
+ | |||
+ | ====== Parts Required ====== | ||
+ | |||
+ | The parts below are required to complete this lesson. Note that all parts except the styrofoam blocks and optional hardware are included in the [[https:// | ||
+ | |||
+ | - Assembled PiBot from [[: | ||
+ | - HC-SR04 Ultrasonic Distance Sensor | ||
+ | - OSOYOO Ultrasonic Distance Sensor Holder | ||
+ | - Micro Servo Motor and Hardware | ||
+ | - 20cm Female to Female Jumper Wires | ||
+ | - Styrofoam Blocks that are at least 5in tall and 2in thick | ||
+ | - Hardware | ||
+ | - M1.5x8mm Screws | ||
+ | - M1.5 Hex Hex Nuts | ||
+ | - M2.2x8mm Self Tapping Screws | ||
+ | - M2x4mm Self Tapping Screws | ||
+ | - Optional Hardware | ||
+ | - M1.4x8mm Hex Cap Screws | ||
+ | - M1.4 Hex Hex Nuts | ||
+ | - M1.6x8mm Hex Cap Screws | ||
+ | - M1.6 Hex Hex Nuts | ||
+ | |||
+ | ====== Hardware Assembly ====== | ||
+ | |||
+ | <WRAP round important> | ||
+ | |||
+ | <WRAP round tip>When installing items with multiple screws or nuts, leave them loose until all are installed and then tighten to ensure that you can get them all inserted</ | ||
+ | |||
+ | - Install the Micro Servo Motor on the top chassis with 2pcs M2.2x8mm self tapping screws from the hardware kit as shown below\\ \\ <WRAP round tip> | ||
+ | - Install the Ultrasonic Distance Sensor to the Holder with 4pcs M1.5x8mm screws and M1.5 hex nuts as shown below\\ \\ <WRAP round tip>The M1.4x8mm hex cap screws and nuts or the M1.6x8mm hex cap screws and nuts can be used instead of the M1.5x8mm screws and nuts if desired or necessary</ | ||
+ | - Install the Ultrasonic Distance Sensor Holder to the Micro Servo Motor with 1pc M2x4mm self tapping screw as shown below\\ \\ <WRAP box>{{ : | ||
+ | - Connect the Micro Servo Motor to the PCA9685 compatible board as shown below\\ \\ <WRAP round tip> | ||
+ | ^ Micro Servo Motor ^ PCA9685 Module | ||
+ | | @-brown:GND (Brown) | ||
+ | | @-red:5V (Red) | ||
+ | | @-orange: | ||
+ | </ | ||
+ | - Connect the Ultrasonic Distance Sensor to the PCA9685 compatible board and Raspberry Pi board as shown below\\ \\ <WRAP round tip>Pull the wires one at a time to separate them from the wire bundle</ | ||
+ | ^ Ultrasonic Distance Sensor | ||
+ | | @-red: | ||
+ | | @-purple: | ||
+ | | @-orange: | ||
+ | | @-black: | ||
+ | </ | ||
+ | - Setup some styrofoam blocks to create obstacles for the PiBot\\ \\ <WRAP round tip>Use some walls of the room to create a box with the styrofoam blocks that the PiBot can drive around in</ | ||
+ | - Turn the PiBot on and place it so that some of the styrofoam blocks are in front of it | ||
+ | |||
+ | ====== Software ====== | ||
+ | |||
+ | Select the appropriate link below for instructions to setup the software on the PiBot and an exploration of how it works. | ||
+ | |||
+ | * [[: | ||
+ | * [[: | ||
+ | |||
+ | ====== Electrical Description ====== | ||
+ | |||
+ | The HC-SR04 Ultrasonic distance sensor has 2 ultrasonic transducers. One transducer acts like a speaker to send out ultrasonic pulses and the other one acts like a microphone to receive the pulses that bounce back. The ultrasonic pulses are sounds that are above the frequencies that humans can hear, so to us it is silent. Humans cannot hear sounds above $20kHz$ and the HC-SR04 sends out ultrasonic pulses at $40kHz$. | ||
+ | |||
+ | When the $10\mu s$ trigger pulse is given to the HC-SR04, it sends out 8 pulses of $40kHz$ sound using the speaker transducer. When it finishes sending out the pulses, it sets the echo pin high and waits to hear any reflections that might bounce back from something in front of it. When it receives an echo, it sets the echo pin low, and if no echo is received it has an internal timer that will set the echo pin low after $38ms$. | ||
+ | |||
+ | The time that the echo pin is high can be used to determine how far from the transducer an object is located. Since the distance to the object is just the speed of the sound multiplied by the time it takes to get there we can use that formula to calculate the distance to the object. This is the formula that is provided in the [[https:// | ||
+ | |||
+ | \begin{equation}Distance (m) = {Time (s) \times 343 (m/s) \over 2} \label{eqn1}\end{equation} | ||
+ | |||
+ | The trigger and echo pins are connected to the Raspberry Pi GPIO so that the Raspberry Pi can control when a measurement is started and detect the time that the echo pin is high. | ||
+ | |||
+ | The PiBot uses the Micro Servo Motor to turn the Ultrasonic Distance Sensor so that it can detect if any objects are to the left or right of it in addition to straight in front of it. The micro servo motor uses a PWM signal that tells it what angle to turn to. This is similar to how PWM works to control the motors as described in [[: | ||
+ | |||
+ | The micro servo motor uses high times between $1ms$ and $2ms$ to represent the angles between $0^{\circ}$ and $180^{\circ}$ where $1ms$ is $0^{\circ}$ and $2ms$ is $180^{\circ}$. The PWM signal generates a high pulse based on the value passed to the set_pwm function on the Raspberry Pi. Each count of that value is equivalent to $4.069\mu s$ when the frequency is set to $60Hz$ as shown in equation \ref{eqn2} below. This means that each count is equal to $0.732^{\circ}$ of rotation on the servo as can be seen from equation \ref{eqn3} below. | ||
+ | |||
+ | \begin{equation} | ||
+ | \begin{split} | ||
+ | Count (s/ | ||
+ | & = {1/60(Hz) \over 4096(cnt)}\\ | ||
+ | & = 4.069(\mu s/cnt) | ||
+ | \end{split} | ||
+ | \label{eqn2} | ||
+ | \end{equation} | ||
+ | |||
+ | \begin{equation} | ||
+ | \begin{split} | ||
+ | Angle (^{\circ}/ | ||
+ | & = {180 (^{\circ}) - 0 (^{\circ}) \over 2 (ms) - 1 (ms)} \times 4.069 (\mu s/cnt)\\ | ||
+ | & = 0.7324 (^{\circ}/ | ||
+ | \end{split} | ||
+ | \label{eqn3} | ||
+ | \end{equation} | ||
+ | |||
+ | [[: | ||
+ | |||
+ | |||