Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • AI Scripts for the cyber:bot

AI Scripts for the cyber:bot

Request Efficient Code


Did You Know: Many Ways to Repeat

After the AI learned what it needed to from Navigation with the cyber:bot, you might have expected it to use a for… loop to repeat the same maneuver four times.  But instead, it repeated the forward-left maneuver four times!  It would be better to write it as shown here:


Your Turn

Do you think maybe Bing Chat can be prompted to do a better scripting job?  

  • Examine the chat and test the AI generated script below.

User

That’s a pretty long script.  Couldn’t you use a loop to get that done in fewer lines?

Bing Chat

Searching for: Python script cyber:bot travel in a square

Generating answers for you…

Yes, you can use a loop to make the script more concise. Here is a modified version of the script that uses a for loop to repeat the forward and right turn movements four times:

Python

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

from cyberbot import *
import time

# Define the duration of the forward and right turn movements
forward_duration = 1.25 # seconds
turn_duration = 0.85 # seconds

# Repeat the forward and right turn movements four times
for i in range(4):
    # Roll forward for 1250 ms
    bot(18).servo_speed(75) # Left wheel counterclockwise
    bot(19).servo_speed(-75) # Right wheel clockwise
    time.sleep(forward_duration)

    # 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(turn_duration)

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

This script defines the duration of the forward and right turn movements using variables, then uses a for loop to repeat the movements four times. The range(4) function generates a sequence of numbers from 0 to 3, which are used as the loop variable i. The loop repeats the forward and right turn movements four times, then stops the servos.

I hope this helps!

Learn more:

1. learn.parallax.com

 

  • Once again, save a copy of your current work.
  • Rename your script ai-forward-right-stop-loop, and replace the text with the new chatbot script provided above.
  • Connect the cyber:bot, run the script, and verify that it works.
  • If you have access to Bing Chat, try your hand at making it write a script.  Be as descriptive as you can in your initial request to make it write the script in one or two iterations instead of three.

Printer-friendly version
Give Feedback on the Script
Prev

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress