# Caution Tape Coding Lessons

Caution Tape Robotics is proud to present the first 2 videos in our educational mini series “Caution Tape Learning”.

These videos aim to give students and educators alike a leg up in their programming, enabling all teams around the world to take their programming skills to the next level!!!

The first 2 videos cover how to use a p-straight function with a gyro, and how to properly write gyro turn functions. These videos are live now on our youtube channel, and the links can be found below.

We would love to hear what other topics you would like us to cover in future “Caution Tape Learning” Videos!!!

1. Drive straight with proportional control - https://www.cautiontape.ca/vex-iq-robot-drive-straight-with-vexcode-blocks/

2. Precise turn with VEX IQ gyro - https://www.cautiontape.ca/program-vex-iq-precise-turn-with-vexcode-blocks/

19 Likes

well, Ty!
(ps do you know how to fix extremely slow turning even with a high battery percentage?)

1 Like

Thanks! I tried it out and added this bit to make the distance on higher velocities more reliable and it worked great!

``````	setMotorSpeed(lDrive,-velocity);
setMotorSpeed(rDrive,-velocity);
sleep(250);
setMotorSpeed(lDrive,0);
setMotorSpeed(rDrive,0);
``````

Also in blocks (I don’t have vexcode blocks downloaded, so I bodged it up with clips from the video and snips from vecode vr):

5 Likes

I feel like this question has an obvious answer, but how do you go backwards? I can only go forwards.

Negative velocity, I believe.

2 Likes

I’ll try that, thanks.

Also, I don’t know how to tune the P loop. Can someone please explain how to tune it?

Distance should be pretty obvious, just the degrees that you want each motor to turn. Heading is also self explanatory, Keep your current rotation, so it doesn’t change its heading. For velocity and kP, if your robot is overshooting as it corrects you want to lower them. If its going too slow and can move faster accurately then increase them. Also, for distance you can convert inches to degrees for other projects that you already started, with Distance(in inches) *25.4/200 * 360. 25.4 is converting inches to millimiters, dividing by 200 is for calculating how many turns your motors have to make, and then times 360 is changing turns to degrees. If your drivetrain isnt 1:1 then change the divide by 200 accordingly. For example, ours is a 2:1 so we divide by 400 because it covers twice as much distance per turn.

4 Likes

Yeah, I only meant kp.

For future videos, maybe expanding adding the ID to make autonomous even more accurate.

2 Likes

basically, you want largest Kp with minimal overshooting. it’s a trial and error process. it’s a painful process. But eventually, your hard work and patience will pay off.

6 Likes

That’s great. We would like to see team to improve based on the basic code. Our intention is to help the new team who knows nothing about PID to have to starting point, there is a lot room to improve after this.

5 Likes

It turns out that it is actually negative velocity and negative distance.

2 Likes

These videos are great! Thank you so much for your contributions to the community! I am prepared to see some nutty autons in the next few weeks! I have a couple of questions and suggestions though
Why do you only get the heading of the left drive motor, and not both motors in the PStraight loop? It would probably best to get both headings and divide by two, I would think.
Also, in your future videos, can you zoom in a bit more on the important part of the code? Sometimes it was a little hard to see.

Otherwise, great video, and this seems like it will be a great series!

3 Likes

Would this code and enough trial and error be enough to create an accurate autonomous or is there something else we need?

1 Like

It is correct that doing that will be more accurate for distance, but the video is for proportional Control, so we simply focus more on the kp part. BTW, the full code snippet is in the blog.

6 Likes

There are always room to make it better. But we do intend to create some sample auton at the end of season to show everybody what you can achieve with simple code like this.

5 Likes

Okay, sounds good!!! BTW, can you make a tutorial on how to tune a PID controller, because that has been quite annoying for me.

2 Likes

Tuning the Kp and momentum on a full size bot (the weight and wheelbase differences from a small bot make a difference) , would be a great follow up video in this series.

Thank you, this is just the kind of next step that one of my teams was very much looking for.

3 Likes

Can anyone verify that omni-wheels are also 200mm circumference? We made an excel sheet last night to convert the distances from motor degrees to inches and there was significant error.

As a result, we will likely empirically make a distance chart that is tuned to our robot instead of relying on what the calculations say it should be.

1 Like