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


Forum Jump:


Users browsing this thread: 2 Guest(s)