Multiple Driving/Turning using Gyro

I’m trying to develop a code for my students that will allow them to drive through a maze using distances via wheels, turns via gyro, and wall sensing using range finder. I can seem to get my code to work to drive a specific distance and then turn a specific degree, but after that, nothing works. We’re using ModKit, so any sample code doing something similar (multiple driving/turning) would be much appreciated! I’m no coding expert…but I attached what I have so far.


Hi Steve,
I would not use the specific distance and the distance sensor as there may be a conflict between the two. I’d suggest just going with the distance sensor.
As a starter, try the attached. This is for a simple drive forward until 100mm from the wall and then turn left 90 degrees and repeat. Few things to note:

  1. The calibration routine at the start takes 3 seconds or so to complete, I put a 5 second wait in to cover it
  2. The reason the While loop for the gyro is < 90 or > 350 is that if the robot veers slightly to the right, the angle will become 359 degrees and therefore would be erronously great than 90 and end the turn early. This way, even if the robot goes 9 degrees off to the right, it’ll still turn to 90 degrees to the left from the original point of calibration
  3. the robot turns the first 60 degrees at a faster speed and the rest at a much slower speed, this makes the turn more accurate. If you turn the full 90 degrees at full speed, the inertia carries you past the 90 degree marker.

And of course, with the new free offline version of Modkit, I can actually share the program with you, not just screenshots! Although I did have to put it in a zip file otherwise the forum rejects it… (1.05 KB)




This is great! Can I ask you one more question? Let’s forget the distance sensor and say I want my students to have their robot drive a specific distance, say 150 mm, then turn 90, then drive 200 mm, then turn right 30, drive forward for 50 mm, turn right 45…etc. etc. What would that look like?

And yes! Thank you for the sample code, +1 to ModKit and VEX for making it available for free!

I can’t think of a good way to do that with Modkit Steve. The attached will work, but it is horribly clunky, especially with no copy and paste! Modkit need to get that sorted. Maybe my brain is tired and I can’t think logically, but this was the best way I could think to do what you asked.

Chris (2.15 KB)