MODi CSV-Scratch
Last updated
Was this helpful?
Last updated
Was this helpful?
MantisCode is a browser-based software, that’s based on the Scratch programming language. With MantisCode, you can connect to MantisEDU sensors for data collection and other experiments.
Using MantisCode does not require any software to be installed. The user must simply 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.
From the home page, click on Mantis Sensors to access the sensor of interest.
To get access to the sample lessons and examples for the MODI sensor, follow the Mantis Modi links
This example load and save the data to a CSV file.
Once the program is loaded, click on the green flag to start.
The Mantis MODI sensor allows you to build and program using Scratch, a block-based programming language that is easy to learn and use. With the MODI, you can explore the world of robotics and learn how to code, while having fun building and controlling your robot.
One of the unique features of the MODI is its Bluetooth connectivity. With Bluetooth, you can wirelessly connect to the sensor and retreive it's values in real time.
To connect with the Modi, you will need to use the connection sprite that is included in the project.
Once you press the green flag, the screen will change to say Scanning of Device.
Once you press the connection button on the Modi, the Device will start to broadcast to allow for the program to connect. Upon a successful connection, you program will update to say “Connected.”
The MODI sensor plays a crucial role in the Mantis Rover, measuring distance, gyro, and acceleration values with each reporting cycle. This functionality is integral as it enables the robot to detect obstacles and navigate around them effectively.
When you first connect this sensor, the program automatically saves the values to variables in scratch.
After connecting, the values are saved below.
They are also printed to the main sprite’s window
In this example, the MODI connects, and continuously write the values to the screen. Connect your MODI and give it a try!
CSV stands for "Comma Separated Values," and as the name suggests, it is a file format where data is separated by commas. This makes it easy to import and export data between different software programs.
CSV files can be created using spreadsheet software, such as Microsoft Excel or Google Sheets, and can contain rows and columns of data. Each row represents a record, and each column represents a field of data. For example, you could have a CSV file that lists the names, ages, and favorite colors of a group of people.
Why are CSV files important? Well, they are commonly used in many industries, including finance, healthcare, and research, to store and analyze large amounts of data. Being able to work with CSV files is a valuable skill that can help you in many future endeavors, whether it be for school projects or in your future career.
The File logger sprite constructs the CSV File by first writing the header values, using this block of code.
This block outputs a row such as,
“Time, AccelX, AccelY, AccelZ, GyroX, GyroY, GyroZ, Distance”
Next, the row values are written, which contain the current sensor values.
This outputs a row with data such as,
“0,0.24,0.16,-4.89,0.05,-0.09,-0.01,1.11”
After connecting, press, the “f” key will prompt to download a file with the latest values.
Example of the data in the CSV can be view by opening the file in a text editor, or word processing application.
Example of file contents opened in a text editor.
Example file opened in Microsoft Excel
Now that you have these values, you can use them to calculate the Velocity and Acceleration
Calculate velocity using the following formula:
Velocity = (Distance2 - Distance1) / (Time2 - Time1)
This formula calculates the average velocity between two consecutive distance measurements. Repeat this calculation for each pair of distance and time values to obtain a series of velocity values.
Calculate acceleration using the following formula:
Acceleration = (Velocity2 - Velocity1) / (Time2 - Time1)
This formula calculates the average acceleration between two consecutive velocity measurements. Repeat this calculation for each pair of velocity and time values to obtain a series of acceleration values.
Note: If your distance values are recorded at regular time intervals (e.g., every second), you can assume a constant time interval between measurements. In such cases, you can omit the time intervals and use a fixed time interval value in the calculations.
The full program can be accessed here, .
Use excel, to calculate the acceleration and distance values plot them on a graph. Here is a sample video showing this process, ().