Now that we know Bing Chat can make a script for the cyber:bot to roll forward and turn, let's see if it can expand upon that.
- Read the chat interactions.
- Does it look like the modified script will work?
- Is this really the best way to write this script?
User
Assuming this results in forward followed by a 90 degree turn, modify the script to make the cyber:bot travel in a square.
Searching for: cyber:bot travel in a square
AI Chatbot
Searching for: Python script cyber:bot travel in a square
Generating answers for you…
To make the cyber:bot travel in a square, you can modify the previous script to include four movements: forward, right turn, forward, and right turn. Here is the modified Python script:
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) # 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) # 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) # 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) # 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
Try the Expanded Script
For more information on how to write scripts to make the cyber:bot navigate, see Navigation with the cyber:bot.
- Read the chat interactions.
- Does it look like the modified script will work?
- Is this really the best way to write this script?
- Change the script name to ai-forward-right-stop-x4
- Click Save to keep a copy of your work.
- Replace the script with the expanded version shown above.
- Connect your cyber:bot to USB.
- 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.
- Unplug the cyber:bot from USB, then set the PWR switch to 2.
- Test the cyber:bot robot’s navigation.
- After tuning, can it make the cyber:bot travel in a square?