Simulating an Obstacle Avoidance Robot Using Python | From Scratch

Sdílet
Vložit
  • čas přidán 8. 09. 2024

Komentáře • 34

  • @thePavuk
    @thePavuk Před 18 dny

    Real Ultrasonics sensors has few additional parameters
    1) typical sampling frequency is 50Hz so they won't update in real time. If robot moves with speed 1m/s toward wall, it moves 2cm before update. It's even more significant during rotation.
    2) ultasonic sensors has high noise. Usually +/- 2cm for cheap one with 250cm range.
    3) They can have issue... Same model of US usually works on same frequency = you has to trigger sensors one by one because they interfere with each other.

  • @alanperez7551
    @alanperez7551 Před 5 měsíci +1

    If you did all right and still having and error try this:
    "File" -> "Invalidate Caches / Restart" -> "Invalidate and Restart".
    This restart the old cache and validates the added modules like:
    import pygame etc...

  • @hobby_coding
    @hobby_coding  Před 2 lety +9

    i hope you enjoyed this , don't forget to leave a like if you did. 😊😊
    🗃️ source code : ko-fi.com/s/1a38e1563b

    • @hobby_coding
      @hobby_coding  Před 2 lety

      @@sharefyusuf5769 in the discription box

    • @akashbhagabati5519
      @akashbhagabati5519 Před rokem

      i am getting an error at the main file. in the line " if event.type == pygame.QUIT():" the error is shown that "int' object is not callable. I have checked for any typing errors but there are not any. Please help

  • @tomersidis1225
    @tomersidis1225 Před 2 lety +2

    Nice work! Your tutorial is informative and creates an easy to follow simulation of using an ultrasonic sensor for obstacle avoidance. It would be excellent if you could extend this tutorial and expand on sensor based motion planning, such as by combining this simulation with your RRT tutorial.

    • @hobby_coding
      @hobby_coding  Před 2 lety

      sure, nice idea.

    • @profmoek7813
      @profmoek7813 Před rokem

      @@hobby_coding thanks for the great tutorials on SLAM. I HAVE SO MANY unanswered questions about kahman filter. Please can you 🙏 make tutorial on that

  • @senaysew8231
    @senaysew8231 Před 2 lety +2

    Man, you forgot uploading the 2nd part of lane detection. Have been waiting for 5 months 😂😂😂👍🤐

  • @profmoek7813
    @profmoek7813 Před rokem

    Thanks alot sir for the information. I learnt a lot from the SLAM Lecture series. Please you indicated as part of the series extended kalman filter. Please I have been waiting for that tutorial. I really need to see your perspective and implementation of the filter as I have so many unanswered questions, which I hope I will get the answers from the tutorial. Thanks for the great video. They really changed my perspective of what I thought I knew before

  • @manishsaini2172
    @manishsaini2172 Před 2 lety +2

    Robot's ultrasonic sensor is rotating the opposite direction when robot takes turn. For instance, for the first obstacle (first wall), robot turns around 90 degree clockwise but ultrasonic sensor turns 90 degree anticlockwise which as a result makes the ultrasonic sensor heading towards the backside of robot instead of front side. Please help me to resolve this issue. @Algobotics

  • @simplymohan
    @simplymohan Před rokem

    Nice tutorial

  • @red_orangetech1738
    @red_orangetech1738 Před 2 lety

    Hey,just jumped in here ,Are these series going to to reach a point of really making an autonomous robot? I'm understanding we are only doing simulations and not the actual thing, please clarify for me, would like to follow the series of videos if that's what we are heading to,a real life autonomous robot with slam, thanks.

  • @QuangDong1010
    @QuangDong1010 Před rokem

    Can we set a designated point for the robot to find its way there? Thanks u

  • @SACKO0731
    @SACKO0731 Před 2 lety

    Algobotics where does self.map.get_at comes from it seems like that don't work
    in 10:52 the "get_at could'nt" be solved thanks

  • @oliverhudson8821
    @oliverhudson8821 Před 2 lety +1

    I have followed the tutorial and i have an error , i don't understand could you help? Traceback (most recent call last): File "main.py", line 10, in gfx = Graphics(MAP_DIMENSIONS, 'DDR.png', 'ObstacleMap.png') File "/home/runner/Wall-Detection/ROBOT.py", line 83, in __init__ self.map.blit(self.map_img, (0,0)) AttributeError: 'Graphics' object has no attribute 'map_img' . Also i am using repl.it .

    • @hobby_coding
      @hobby_coding  Před 2 lety

      you have to put both of the images in the description in the project folder

  • @blackwidow8447
    @blackwidow8447 Před 2 lety

    Hey, I replicated the whole code, fixed all the errors, but somehow my robot keeps moving in circles, without sensing any obstacles, or moving in any direction :/

  • @kabiratolayemi7570
    @kabiratolayemi7570 Před rokem

    Hi. I followed the code but encountered this error: Graphics() takes no arguments. Any help

  • @raginigupta4857
    @raginigupta4857 Před měsícem +2

    ROBOT.py---->
    import pygame
    import math
    import numpy as np
    def distance(point1,point2):
    point1 = np.array(point1)
    point2 = np.array(point2)
    return np.linalg.norm(point1- point2)
    class Robot:
    def __init__(self, startpos,width):
    self.m2p= 3779.52 #from meters to pixels
    #robot dims
    self.w = width
    self.x= startpos[0]
    self.y = startpos[1]
    self.heading =0
    self.vl = 0.01*self.m2p #meters/s
    self.vr = 0.01*self.m2p
    self.maxspeed = 0.02*self.m2p
    self.minspeed = 0.01*self.m2p
    self.min_obs_dist = 100
    self.count_down = 5 #seconds
    def avoid_obstacle(self,point_cloud,dt):
    closest_obs = None
    dist = np.inf
    if len(point_cloud) > 1:
    for point in point_cloud:
    if dist > distance([self.x, self.y], point):
    dist = distance([self.x,self.y], point)
    closest_obs = (point,dist)
    if closest_obs[1] < self.min_obs_dist and self.count_down > 0:
    self.count_down -= dt
    self.move_backward()
    else:
    #reset count down
    self.count_down = 5
    #move forward
    self.move_forward()
    def move_backward(self):
    self.vr = - self.minspeed
    self.vl = - self.minspeed/2

    def move_forward(self):
    self.vr = self.minspeed
    self.vl = self.minspeed
    def kinematics(self, dt):
    self.x += ((self.vl+self.vr)/2) * math.cos(self.heading) * dt
    self.y -= ((self.vl+self.vr)/2) * math.sin(self.heading) * dt
    self.heading += (self.vr - self.vl) / self.w * dt
    if self.heading>2*math.pi or self.heading
    import math
    import pygame
    from ROBOT import Graphics, Robot, Ultrasonic
    MAP_DIMENSIONS = (600, 1200)
    #the environment graphics
    gfx = Graphics(MAP_DIMENSIONS, 'D:\college\internship\INTERNSHIP TASK\obstacle detection\images\DDR.png', 'D:\college\internship\INTERNSHIP TASK\obstacle detection\images\Obstacle.png')
    #the robot
    start = (200, 200)
    robot = Robot(start, 0.01*3779.52)
    #the sensor
    sensor_range = 250, math.radians(40)
    ultra_sonic = Ultrasonic(sensor_range, gfx.map)
    dt=0
    last_time = pygame.time.get_ticks()
    running = True
    #simulation loop
    while running:
    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    running = False
    dt= (pygame.time.get_ticks()-last_time)/1000
    last_time = pygame.time.get_ticks()
    gfx.map.blit(gfx.map_img, (0,0))
    robot.kinematics(dt)
    gfx.draw_robot(robot.x, robot.y, robot.heading)
    point_cloud = ultra_sonic.sense_obstacles(robot.x, robot.y, robot.heading)
    robot.avoid_obstacles(point_cloud, dt)
    gfx.draw_sensor_data(point_cloud)
    pygame.display.update
    THANK ME LATER😌

  • @dinnyuylfruangu3069
    @dinnyuylfruangu3069 Před rokem

    Great video though am unable to download the image

  • @jhanolaer8286
    @jhanolaer8286 Před 2 lety +1

    what is Vl and Vr?

    • @hobby_coding
      @hobby_coding  Před 2 lety +1

      left and right wheels linear velocities

  • @dharanijagan8032
    @dharanijagan8032 Před rokem

    WHERE DO I GET DDR.PNG','Obstacle.png

  • @xfiretun5934
    @xfiretun5934 Před 2 lety

    Robot keeps on going forward through map without detecting any obstacle .. any help !

    • @blackwidow8447
      @blackwidow8447 Před 2 lety

      Were you able to fix the problem? My robot keeps moving in circles
      :(

    • @vanminhnguyen8402
      @vanminhnguyen8402 Před rokem +1

      @@blackwidow8447 Change color[1], color[2], color[3] to color = (0,0,0)

  • @petagriffed8337
    @petagriffed8337 Před rokem

    this is 2d what about 3d space

  • @lilyvmax6642
    @lilyvmax6642 Před 2 lety +1

    Horrible

  • @welidbenchouche
    @welidbenchouche Před 2 lety +1

    hi bro, amazing content, can i contact you for a small information pleaaaaaaaaase ? i tried to find you on fiver, but couldnt

    • @hobby_coding
      @hobby_coding  Před 2 lety

      hi walid, just send me an email. check the contacts on the channel home page.

    • @welidbenchouche
      @welidbenchouche Před 2 lety

      @@hobby_coding I have just sent you an e mail, please check spam if you can't find it. thanks a lot for your time

    • @hobby_coding
      @hobby_coding  Před 2 lety

      @@welidbenchouche i found it and sent a reply :)