AI cyber:bot Script

Let’s try a script that’s a little different from the overview.  It’s a little easier to manage on a table.  Here, we will make the cyber:bot roll forward for 1.25 seconds, then turn in place for 0.85 seconds.  At the time of this writing, ChatGPT has trouble with this, so we are using Bing Chat.

  • Read the chat interactions below.
    • Does it look like the script will work?
    • Did you notice the warning about needing the cyberbot module?  
    • This AI can also search the web, did the resource it supplied look helpful?

User

Write a Python script to make the cyber:bot robot roll forward for 1250 ms, then rotate right in place for 850 ms.

Bing Chat

Searching for: cyber:bot robot roll forward for 1250 ms, then rotate right in place for 850 ms

Searching for: Python script cyber:bot robot roll forward for 1250 ms, then rotate right in place for 850 ms

Generating answers for you…

Here is a Python script that makes the cyber:bot robot roll forward for 1250 ms, then rotate right in place for 850 ms:

Python
AI-generated code. Review and use carefully. More info on FAQ.

from cyberbot import *
import time

# Roll forward for 1250 ms
bot(18).servo_speed(75) # Left wheel counterclockwise
bot(19).servo_speed(-75) # Right wheel clockwise
time.sleep(1.25)

# Rotate right in place for 850 ms
bot(18).servo_speed(75) # Left wheel counterclockwise
bot(19).servo_speed(75) # Right wheel counterclockwise
time.sleep(0.85)

# Stop the servos
bot(18).servo_speed(None)
bot(19).servo_speed(None)

This script uses the cyberbot library to control the robot’s servos. The bot(18) and bot(19) calls are used to control the left and right wheels, respectively. The servo_speed function is used to set the speed and direction of each servo. The time.sleep function is used to pause the script execution for the specified duration.

I hope this helps!

Learn more:

1. learn.parallax.com

Use the AI Generated Script

  • Right-click cyberbot-template-with-blink.hex and save it to your computer. (This template is available from the tutorial Add modules to your micro:bit .)

cyberbot-template-with-blink.hex

  • Open it with the micro:bit Python Editor.
  • Replace the default template script with the script generated by the chatbot.
  • Set the script name to ai-forward-right-stop.
  • Click Save to keep a copy of your work.
  • Make sure battery pack has 5 good AA batteries and is plugged into the cyber:bot board.
  • Set the PWR switch to 0.
  • Connect the cyber:bot’s micro:bit to USB.
  • Click Send to micro:bit to load it into the cyber:bot.

Tests

  • Unplug the cyber:bot from USB, then set the PWR switch to 2.
  • If the cyber:bot doesn’t start immediately, press and release the reset button under the micro:bit next to the USB connector.
  • Test the cyber:bot robot’s navigation.  

Did the cyber:bot roll forward and turn right as expected?

Which would be quicker for tuning the right turn to 90 degrees, asking the AI to do it, or just testing and updating time.sleep values?