πAI +(Python)
Description
This flexible activity is designed to teach instructors how to harness large language models (LLMs) like ChatGPT to generate and refine JavaScript code that drives a four-motor robot. Each self-contained activity focuses on a core AI or robotics concept, pairing a clear learning objective with hands-on prompt exercises and real-world testing. Instructors can pick and choose which activities to run and in what order to fit their schedule and learnersβ needs.

Overview
This guide covers:
Generating PWM commands for the ROV.
Understanding how PWM settings affect motor drive and direction.
Running user-generated Python using LLM output based on guided input.
In order to run python, you will need to have an IDE and python compiler. If desired, you can use Visual Studio Code Code on your computer.
Follow this link https://code.visualstudio.com/docs/setup/setup-overview and use the steps related to your operating system.
Once you have the IDE installed, follow these instructions to install python, https://code.visualstudio.com/docs/python/python-tutorial.
Bleak library
This library must be installed first https://github.com/hbldh/bleak
From the command prompt run: Run βpip install bleakβ
RoverLLM.py
The activities in this lesson are based on the contents of this file. When prompted below, you can use the copy feature to save a copy of the file to your device
Activity 1 β LLM Setup for Coding
Objective: Configure the LLM to output code using your ROV-specific API.
Prerequisites:
Open VS Code and make a new Python file called Activity1.py. based on RoverLLM.py
Copy RoverLLM.py to activity1.py
Change the DeviceName (line 5) to match the Device Name of your device.
Prompt to ChatGPT:
This prompt should return back some sample code you can try.
Next Steps
Replace the StartProgram function with the output from ChatGPT
Execute the program in VS Code by click the run python file from the menu bar.

Activity 2 - Sensing & Reactive Behavior
Objective: User Distance to control movement
Prerequisites:
Open VS Code and make a new Python file called Activity2.py. based on RoverLLM.py
Copy RoverLLM.py to activity2.py
Change the DeviceName (line 5) to match the Device Name of your device.
Prompt:
Next Steps
Replace the StartProgram function with the output from ChatGPT
Execute the program in VS Code by click the run python file from the menu bar.

Activity 3 - Random Movements
Objective: generate an algorithm with ordered steps based on user input.
Prerequisites:
Open VS Code and make a new Python file called Activity3.py. based on RoverLLM.py
Copy RoverLLM.py to activity3.py
Change the DeviceName (line 5) to match the Device Name of your device.
Prompt:
Next Steps
Replace the StartProgram function with the output from ChatGPT
Execute the program in VS Code by click the run python file from the menu bar.

Activity 4 β Move in a Square
Objective: Generate a algorithm to move the robot in a square
Prerequisites:
Open VS Code and make a new Python file called Activity4.py. based on RoverLLM.py
Copy RoverLLM.py to activity4.py
Change the DeviceName (line 5) to match the Device Name of your device.
Prompt:
Next Steps
Replace the StartProgram function with the output from ChatGPT
Execute the program in VS Code by click the run python file from the menu bar.

Last updated