Autonomous PI Robot Tutorial - Part II
In this Tutorial we are continuing where we left in Part I
Now let's peek into Logic Implementation for robot anonymous Motion.
Now let's peek into Logic Implementation for robot anonymous Motion.
First
we will create infinite loop and read the sensor readings:
distincmsleft,
distincmsleft1, distincmsstraight, distincmsright1, distincmsright =
GetSensorReadings()
Now
we will detect if there is any obstacle in front first:
Case 1:
if distincmsstraight < distance_obstacle:
If there is any
obstacle in front, we should stop the robot and then look for left and right
readings. If the there is obstacle on left – turn right and vice versa. If
there is no obstacle on either side, we are prioritising right turn here which
is handled in else case. Below code does the trick:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 22 | if distincmsstraight < distance_obstacle: Brake() if distincmsleft < distance_obstacle or distincmsleft1 < distance_obstacle: Brake() for x in range ( 1 , 3 , 1 ): Right() time.sleep( 0.1 ) Brake() elif distincmsright < distance_obstacle or distincmsright1 < distance_obstacle: Brake() for x in range ( 1 , 3 , 1 ): Left() time.sleep( 0.1 ) Brake() else : Brake() for x in range ( 1 , 3 , 1 ): Right() time.sleep( 0.1 ) Brake() |
case 2:
1
| elif distincmsleft < distance_obstacle or distincmsleft1 < distance_obstacle: |
Check
if there is obstacle on left – if there is any obstacle turn right which is
handled by below code:
1
2
3
4
5
| Brake() for x in range ( 1 , 3 , 1 ): Right() time.sleep( 0.1 ) Brake() |
case 3:
Check
if there is obstacle on right – if there is any obstacle turn left which is
handled by below code:
1
2
3
4
5
6
| elif distincmsright < distance_obstacle or distincmsright1 < distance_obstacle: Brake() for x in range ( 1 , 3 , 1 ): Left() time.sleep( 0.1 ) Brake() |
case 4:
If
none of above master cases are observed – simply move forward for 0.5 second
and then again perform the same operation again!
|
Putting
it all together:
|
Final
Outcome
Types
of projects that you can build with above setup:
There
are endless possibilities as using this for experimentation and learning. But
below are top 10 inspiration that will help you to broaden vision:
- Wireless Computer controlled
robot.
- Add sensors and make it
autonomous. Need extra sensors.
- Line follower with IR
sensor. Need extra sensors.
- Mobile controlled robot via
bluetooth.
- Setup local server on PI and
control it via browser.
- IOT machine – control via
cloud.
- Enhance fleet management system
via sensors. Need extra sensors.
- Add camera and track things.
Will need PI camera.
- Room cleaner robot. Need extra
vacuum and sensors.
- Voice controlled robot. Will
need microphone attached.
So, get the hardware-
PlugIn Internet- Start Making
GOD BLESS.WORK HARD
Comments
Post a Comment