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
#71
Hi all.  Smile

I am currently creating a SB program that should display a small window with buttons on the screen.
This will be the panel for manual control of the robot.
The user will be able to control the robot's movement by clicking the mouse on the buttons on this panel.  Cool
Reply
#72
OK,

So this is not a programmed AI, but a human user control - what is your thinking for this - why not just use the arrow keys directly which are already available for human control?
Reply
#73
(02-14-2025, 05:20 PM)litdev Wrote: OK,

So this is not a programmed AI, but a human user control - what is your thinking for this - why not just use the arrow keys directly which are already available for human control?

I am writing this program to improve my experience with web application. Also, I am writing this program to explore how the robot executes commands.

And I like using the keyboard less than clicking the mouse on a fancy control panel.  Rolleyes
[-] The following 1 user Likes AbsoluteBeginner's post:
  • litdev
Reply
#74
Hi, I have been testing a time parameters (18, 1030 in this case) and it shows a good (although not 100% right) results (C#):

while(true)
{
     string jsonMaze = SendWebRequest(urlGet); // getData
     // Calculate action (AI) ...
     SendWebRequest(urlSet + "&animate=" + dirs[moveDir]);  // 0, 90, 180, 270
     Timer.Sleep(18);                                           // fetch (50-60fps) from web page should take action in this interval
     SendWebRequest(urlSet + "&animate = -1");  // prevent additional fetch the same previous animation
     Timer.Sleep(1030);                                       // waiting end of animation
}
Reply
#75
You are in the details here and I think trying to do what the code is already trying to do. 

The full source with php is https://github.com/litdev1/maze3D2. VSCode is viewer I reccomend for JS and PHP - can also do limited debugging there or add console.info output and host as a test code somewhere on web.

In particular look at the variables globalThis.readyToSend and globalThis.readyToReceive in the JS and the fetch call to php (mode 1) that resets current move (animate=-1) that is confirmed before we poll again ( readyToSend ) or accept a previous return message ( readyToReceive ).

PS

Also note that a consequence of this is that 'get' is not updated until an animation fully completes so if your delay isn't long enough then the get data will not be updated to the new position and you will be sending a command based on the position before the animation finishes.

Bottom line - need to wait long enough for animation to finish and update new position - no need for animate = -1 or any other actions.

This is my test code based on the partial code you sent - http://litdev.uk/apps/maze3D/WebAccess.zip note the issues when Sleep is too short appears to be fully consistent with discussion above as far as I can see, and I use the settings name 'Steve'.
[-] The following 1 user Likes litdev's post:
  • stevantosic
Reply
#76
litdev, many thanks for sharing code! I would it study a bit carefully.

Quote:Also note that a consequence of this is that 'get' is not updated until an animation fully completes so if your delay isn't long enough then the get data will not be updated to the new position and you will be sending a command based on the position before the animation finishes.

I agree and just have written a version of code which is slower (comparing previous got json data from server with the current one in case of not been updated) but more stable (repeat last action).

st
Reply
#77
Hi all.  Smile

Today I finally tested the robot manual control program that Chat and I made.
During the test I saw two runtime errors.
  1. When I send the command "forward=1", the robot often moves 1.5 or 2 steps.
  2. When I send the command "animate=...", then after performing the turn the robot makes a step. But I don't need this step.
Please tell me where to look for the problem? Huh
Reply
#78
Networking on Maze3D web page (with server) is a very intensive and working in sync with game loop (50fps). Generally, it will be nice to have option in settings page for networking ("fps"): 1,5,10 or 50. This feature could eliminate network consuming between web page and server. The workflow:
Maze 3D web page -> game loop (~20ms) : 1. fetch (request + DB + response) -> calculations and start animation(s) -> 2. fetch(request + DB + response).
Reply
#79
AB,

Several things here:

1] I introduced a bug whereby the server side was allowed to asynchronous - I have reverted this and uploaded the correction - this is the main cause of the "multiple forward" steps.
2] Make sure that you leave sufficient Program.Delay after the animate, rotate or forward commands that it has fully completed.
3] The animate command is intended to do a rotation and movement to a new cell, to just do a rotation, use the rotate command.

Please let me know how this goes as some of the issues are clearly my fault as I try to make it efficient within the limits of my ISP provider.
[-] The following 1 user Likes litdev's post:
  • AbsoluteBeginner
Reply
#80
(02-17-2025, 06:55 PM)stevantosic Wrote: Networking on Maze3D web page (with server) is a very intensive and working in sync with game loop (50fps). Generally, it will be nice to have option in settings page for networking ("fps"): 1,5,10 or 50. This feature could eliminate network consuming between web page and server. The workflow:
Maze 3D web page -> game loop (~20ms) : 1. fetch (request + DB + response) -> calculations and start animation(s) -> 2. fetch(request + DB + response).

I will look into this, not so much the underlying fps loop that is handled by Babylon and client, initially I will add option to reduce the polling frequency.

EDIT

Added this option to settings - AB's issue was disappointing that I can't run the PHP async as this would lower the load overall.
[-] The following 1 user Likes litdev's post:
  • stevantosic
Reply


Forum Jump:


Users browsing this thread: 34 Guest(s)