πŸš—MODi LIDAR Obstacle Avoidance-JavaScript

The user must have access to an internet connected device that runs a modern web browser that supports WebBluetooth. Most modern web browsers support this, with the exception of Safari on MacOS, and Firefox. Google Chrome or Edge are recommended for best results. Mobile browsers are not typically not supported.

MODi LIDAR Avoidance Tutorial

Learn how to command the motors using the Motor Hat provided in your Rover kit, along with the LIDAR sensor on the MODi.

This guide requires no prior programming experience and users should focus more on the concepts being introduced versus getting lost in the minutia of the scripting language.

Overview

In this guide you will learn how to manipulate and control the Rover based on the following basic concepts:

  1. How to generate PWM commands for the ROVER.

  2. Understand how the different PWM settings affect motor drive and direction.

  3. Visualize PWM concepts with an appreciation for generated outputs.

  4. Interpret the sensor command provided by the MODI sensor.

To access the program, simply follow this link https://mantiscode.azurewebsites.net/webble/mthobstacle.html

This Rover GUI code demo contains two files:

mthjoystick.html

o This must be in the same folder as the Java script file

o Contains metadata about the extension and how to configure all the Gui items in the browser.

mthjoystick.js

o This module contains the underlying BLE communications.

o We will be iteratively modifying the functions specific to the Joystick buttons above.

Connect MTH Board

Click on the Bluetooth icon and make sure your device is broadcasting. Once broadcasting, click on the pair button to connect to the board.

Once you have a successful connection, the interface will report that a connection was successful.

After the MTH, now you need to connect you modi sensor. Click the Connect MODi button to initiate the process.

once paird, sensor data will start to show.

Now that both sensors are connected, the montoring features can be used in addtion to the joystick commands.

Mthobstacle.html Breakdown

Let's break down the contents of mthjoystick.html file. This code tells your browser how and where to place everything that you see on the screen demonstrated above. You can copy this code directly into a text editor and make sure to name it with the same convention above.

For starters you can see where the buttons are called out here starting on line 1, five buttons in total.

mthobstacle.js Breakdown

The man-in-the-loop experiment calls for manipulating the drive strength of these buttons and observing the results as you maneuver around the obstacle course that you made. It is important when you learn to code that you appreciate certain aspects of the code while focusing your efforts on the specific regions of concern. All other sections in the mthjoystick.js java script file maintain very low level details of the BLE layer that is beyond the scope of this exercise. Before proceeding further go ahead and copy this code into a text editor in its entirety and save it with the exact naming convention above.

man-in-the-loop exercise

This example builds upon the previus PWMRemote Example.

πŸš—Man-In-The-Loop Obstacle Avoidance Tutorial-JavaScript

In the ongoing exercise, there's a monitoring function named EnableMonitoring. This function sets motor commands according to the distance value acquired from the MODI sensor. Activation or deactivation of this function is accomplished by clicking either the Start or Stop Monitoring buttons.

When Monitoring, the code enables a callback that executes the checkDistanceValue() funtion once every 200ms. When in that function, the code will issue the a stop command if the distance value is below a threshold set on line 2. Otherwise, the code will issue the moveForward() command.

In this experiment, adjust the threshold value and observe the performance of your robot. Additionally, modify the moveForward() command to achieve the desired PWM values for your Rover. Operate the rover in a space with obstacles, and iteratively fine-tune your settings until it can successfully maneuver without collisions.

Last updated

Was this helpful?