Showing posts with label vex robot. Show all posts
Showing posts with label vex robot. Show all posts

Monday, 22 February 2021

VR robot in a maze - from Blocks to Python

Recently I produced a post about playing with Vex Robotics VexCode VR blocks and the Maze Playground.



The post finished with me saying I would like to play with Python and do a Python version of it. Well it is actually very easy to do it.




You can do it in two stages from the block code. First click on the <> icon (lighted in the figure above and it gives a further view producing Python code that changes as you change the blocks. The last stage is to convert to a text project (button at the bottom right of the screen.



Example of the code.
myVariable = 0

def when_started1():
global myVariable
drivetrain.drive_for(FORWARD, 100, MM)
while not down_eye.detect(RED):
drivetrain.drive_for(FORWARD, 5, MM)
if right_bumper.pressed():
drivetrain.drive_for(REVERSE, 30, MM)
drivetrain.turn_for(LEFT, 20, DEGREES)
drivetrain.drive_for(FORWARD, 20, MM)
else:
if left_bumper.pressed():
drivetrain.drive_for(REVERSE, 30, MM)
drivetrain.turn_for(LEFT, 120, DEGREES)
drivetrain.drive_for(FORWARD, 10, MM)
else:
drivetrain.turn_for(RIGHT, 10, DEGREES)
drivetrain.drive_for(FORWARD, 10, MM)
wait(5, MSEC)

vr_thread(when_started1())

The code in action


This is possibly a nice transition tool going from block-based programming to text-based.

Related posts


All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author h any association with. Twitter @scottturneruon

Remote Data Logging with V1 Microbit

In an earlier post  https://robotsandphysicalcomputing.blogspot.com/2024/08/microbit-v1-datalogging.html  a single microbit was used to log ...