Programming Cortex on RobotMesh - Autonomous/Sensors

I am trying to use RobotMesh with the old Cortex Clawbots. My goal is to (teach my students to) create a code that allows the robot to move autonomously using sensors using Blockly. I would like to make a maze and use the bumper sensor to get through the maze, like the first maze challenge on vex VR.

There’s a lot of very basic stuff I can’t figure out. Here are some of my questions:

  1. How do you make the robot turn? Do you need to create a function for this? How do you use the shaft encoders to control how far it turns? I would like to make (approx) 90 degree turns
  2. How do you wire the shaft encoders? There are 2 3-prong wires connected to each encoder, and I don’t know what the two wires do/go and therefore (I figured this part out) have no idea how to put this in in robotmesh correctly
  3. Once you have a code written, how to you execute the code/tell the robot to start it?

I guess these are my main questions right now. I definitely have a lot more questions but I am a bit overwhelmed by all I don’t know that I I’m not even sure what to ask.

Hi Estith.

The simplest and crudest way to do this is by starting the motors, waiting some time, and turning them off again. Something like this:

motor_2.run(60)
motor_9.run(-60)
sys.sleep(1)
motor_2.off()
motor_9.off()

Then change the number in the sys.sleep call with some trial and error until you get somewhere near a 90 degree turn. You can copy and paste that code every time you want to turn (boo) or put it in a function, like you suggested:

def turn():
    motor_2.run(60)
    motor_9.run(-60)
    sys.sleep(1)
    motor_2.off()
    motor_9.off()

(As usual, the indentation is required in Python)

It is possible to include the optical shaft encoders, but it would require moving some stuff around on the Clawbot chassis.

Note that time-based or encoder turns will have a certain amount of slop. It may be difficult to navigate a lengthy maze with them. If you have the discontinued Yaw Rate Gyroscope you could use it here.

Once the code is written, click the “Run” button to run it. You must have Robot Mesh Connect installed. If it is not installed, you will need admin permissions on the computer you’re using to install it. Click the “Install RMC Plugin…” link in the top right for instructions.

image

2 Likes

Thank you so much!

Is there a way to integrate this code into the blockly approach? I’m trying to make it as simple as I can for my students with very little coding experience. In my (very limited) experience, it looks like you can either do written code or blockly but not both nvm I figured out how to make a function on blockly

2 Likes