We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D maze in browser controlled by Small Basic
#3
Hi,

The idea is a bit similar to the AI control you were developing for rabbit and snake program.  Or imagine that the 3D maze is a world where a robot is lost and you have to write a program to help navigate it.  The motivation is associated with what Stevan Tosic is doing with arduinos and looking for a 3D maze that could run in a browser, but I like the idea of using SB to write the control.

The idea is that there is very little data coming from the robot in the maze, just its position (posX and posZ), the direction it is looking (angle) and the distance in front of it before it sees a wall (dist).  Also there is very little going back to control the robot, just a move, left and right flag (0 or 1) very similar to using keyboard keys.

The SB program I shared gets and updates communication of these with the 3D maze and it is up to you to write a program with just the info above to navigate the robot.  In the program you see my very simple logic (not very good).

Code:
'This is where you put your simulation cotrol logic
'Controller code - set move, left and right to control movement in the maze
'Using feedback posX, posZ, angle and dist
Sub Controller
  'posX: X position in the maze
  'posZ: Z position in the maze (Y is up and always the same)
  'angle: The angle of rotation, degrees in the X/Z plane
  'dist: The forward distance to the nearest object, usually a wall
 
  'move: stop (0) or continuously move forwards (1)
  'left: stop (0) or continuously rotate to the left decreaseing angle (1)
  'right: stop (0) or continuously rotate to the right increasing angle (1)
  If (dist < 0.2) Then
    left = 1
    right = 0
    move = 0
  Else
    left = 0
    right = 0
    move = 1
  EndIf
EndSub

In this case all it does is keep turning left if it sees a wall in from of it (< 0.2m), otherwise it moves straight forwards.

As I said in original post you need LitDev extension 1.2.29.15, then open the 3D maze (link in original post) in a browser and run the SB program (import code also in original post) and see it try to control the robot in the maze.  Then try to do better logic!
[-] The following 1 user Likes litdev's post:
  • AbsoluteBeginner
Reply


Messages In This Thread
RE: 3D maze in browser controlled by Small Basic - by litdev - 01-26-2025, 06:58 PM

Forum Jump:


Users browsing this thread: stevantosic, 4 Guest(s)