-
Notifications
You must be signed in to change notification settings - Fork 0
6. Javascript library
The Fossbot Javascript library provides access to all the functions of the fossbot interface, which can be found here. This library was designed to allow users to execute simulator functions directly from their web browsers.

Some functions in the library are asynchronous, meaning they can be executed independently of the main program flow. For example, the move_distance
function needs to "block" execution to move the fossbot the specified distance before allowing the rest of the program to continue. Similarly, GET functions require retrieving results before proceeding with the execution.
To use the asynchronous functions, users should use the await
keyword before executing any line of code that calls an async function in the text area of the Javascript user tab (located at /godotcode
). For more information about the user tabs, please refer to the User Tabs section in this wiki.
Below is a comprehensive list of all the implemented fossbot functions available in the Javascript library:
Move forward/backwards.
-
direction
(optional): The direction to be headed to. Possible values are "forward" (default) and "reverse".
Asynchronous function that moves the robot in the specified direction (default is "forward") for the input distance (in cm).
-
dist
(number): The distance (cm) to be moved by the robot. -
direction
(optional): The direction to be moved towards. Possible values are "forward" and "reverse" (default).
Resets all motors direction to default (forward).
Stop moving.
Asynchronous function that waits (sleeps) for an amount of time.
-
time_s
(number): The time (seconds) to sleep.
Moves the robot forward the input distance (in cm).
-
dist
(number): The distance (cm) to be moved by the robot.
Moves the robot forward by the default distance.
Moves the robot forward.
Moves the robot input distance in reverse.
-
dist
(number): The distance (cm) to be moved by the robot.
Moves the robot default distance in reverse.
Moves the robot in reverse.
Rotates the Fossbot towards the specified dir_id
.
-
dir_id
(number): The direction id to rotate to: - counterclockwise:
dir_id == 0
- clockwise:
dir_id == 1
Rotates the Fossbot 90 degrees towards the specified dir_id
.
-
dir_id
(number): The direction id to rotate 90 degrees: - counterclockwise:
dir_id == 0
- clockwise:
dir_id == 1
Rotates the robot clockwise.
Rotates the robot counterclockwise.
Rotates the robot 90 degrees clockwise.
Rotates the robot 90 degrees counterclockwise.
Returns the distance from the nearest obstacle in cm.
- Returns:
number
- The distance from the nearest obstacle.
Returns true
if an obstacle was detected.
- Returns:
boolean
-true
if an obstacle was detected, elsefalse
.
Plays an MP3 file specified by the input audio_path
.
-
audio_path
(string): The path to the desired MP3 file in Godot.
Gets the reading of a floor-line sensor specified by sensor_id
.
-
sensor_id
(number): The ID of the desired floor-line sensor. - Returns:
number
- The reading of the specified floor-line sensor.
Checks if the line sensor (specified by sensor_id
) is on the black line.
-
sensor_id
(number): The ID of the desired floor-line sensor. - Returns:
boolean
-true
if the sensor is on the line, elsefalse
.
Gets the acceleration of the specified axis
.
-
axis
(string): The axis to get the acceleration from ('x', 'y', or 'z'). - Returns:
number
- The acceleration of the specified axis.
Gets the gyroscope reading of the specified axis
.
-
axis
(string): The axis to get the gyroscope reading from ('x', 'y', or 'z'). - Returns:
number
- The gyroscope reading of the specified axis.
Sets an LED to the input color
.
-
color
(string): The desired color. Possible values are 'red', 'green', 'blue', 'white', 'violet', 'cyan', 'yellow', and 'closed'.
Returns the reading of the light sensor.
- Returns:
number
- The reading of the light sensor.
Returns true
only if the light sensor detects darkness.
- Returns:
boolean
-true
if the light sensor detects darkness, elsefalse
.
Returns true
only if noise is detected.
- Returns:
boolean
-true
if noise is detected, elsefalse
.
Exits the simulator.
- Note: Before exiting, the function waits for 0.1 seconds to ensure all operations complete successfully.
- If the SocketIO connection is active (
this.sio.connected
), the function sends an "exit" message to the server and disconnects.
Stops the timer in the simulator.
Starts the timer in the simulator.
Returns the elapsed time from the start of the simulation in seconds.
- Returns:
number
- The elapsed time in seconds.
Execution tab of javascript library.
With these functions, users can experiment with all the methods available in the fossbot interface right from their web browser! This convenient accessibility enables users to interact with the simulator dynamically, test various scenarios, and gain valuable insights into the capabilities of fossbot.