Auton Problems

Hi, and Happy New Year. I have made an autonomous code using a P loop (I think?) and the robot keeps turning right when I start the code when I want it to move straight, Any help is Appreciated. Also, I have no idea how to find the kp of the bot and the kp in the code is probably wrong

auton.iqblocks (33.0 KB)

Okay, so.

First off, I am not near a computer to be able to check out your file, if it’s not otherwise solved I will try later tonight to look.

  1. Likely you have the wrong motor reversed (and the one that isn’t reversed should be). Try changing that first.

  2. Kp/i/d values are very specific to robots, and tuning them tend to be a little bit of voodoo. The thing about Kp is that it’s the minimum amount of input that’s going to go into your motor commands, so inches, millimeters, or degrees could have very different Kp values. Biggest thing to know is that a small Kp value will get you closer to your target without overshooting, but you’ll take longer to get there. Larger Kp will get you to your target faster, but your ‘steps’ are bigger, and therefore you’re more likely to shoot past your target.

To give you a starting point, I very recently just implemented a full distance and heading ‘drive straight’ block in IQ, and had degrees of motor encoder as the distance measurement. My Kp value was around 0.55, with I and D in the 0.015 range. You will have to adjust and play around with it to find what works for your robot (and even your chosen velocity).

2 Likes

Hello, I really appreciate the response, and I understand that you could not check the code. I have not d or i and used the two caution tape gyro precise turning and Pstraight videos for the base of my code

I realize you don’t have Ki or Kd in this case, just relating the larger picture for other folks who might be reading this post (or searching it in the future).

First things first, swap your drive motor reversals, it’s the most likely thing causing it to go wrong. If that’s not it, check that all your math is implemented properly. Our kids use the CTR Drive Straight and Precise Turn code, and it occasionally requires some debugging for some strange setup, but it definitely works.

Incidental question, @jpearman, is there a spec on gyro accuracy for Gen 1 gyro and Gen 2 brain gyro? I see in the description of the Gen 1 gyro that it’s a 16-bit value, which should mean roughly 0.005 degrees of accuracy (360 degrees/65535 bits, for those reading along at home :slight_smile:), but then it mentions filtering, and all of the VexCode functions look to return values as a float. It’s really idle curiosity, but also an opportunity to talk through with students how the sensor “tells” the brain what it knows.

1 Like

If you are using the Caution Tape video, set the drive distance to something long so the motors run for a while, hold the robot in the air and twist it away from the desired heading. Are the ‘outside’ wheels moving faster to try and get you back on heading? If so, your motor directions are correct. If the ‘inside’ wheels are moving faster that means your motor directions are reversed. The easiest way to fix this is switching the ‘left motor’ and ‘right motor’ on the Caution Tape code.

It is great that you are learning and trying to implement this, but remember that the robot should reflect the skill level of the team. If you are going to use this P-loop that you saw the code block for block online, you should have a very detailed and complete knowledge of what you are looking at, not just using a ready made complete code. Study it. Ask questions. Good luck.

He is referring to the Caution Tape Robotics (CTR) drive straight code. The same that you are using

1 Like

Thank you for the reply, and as an update, the gyro code makes the both move forward when its supposed to make it turn

Let’s take it back to basics here.

Instead of using the drive straight block, with the setup above, a simple two block program of ‘Spin leftMotor forward’ and ‘Spin right motor forward’ should make the robot drive forward. If it does not, reverse the left motor and un-reverse the right motor. Now it should drive forward.

Once you have that working, then your setup is no longer the issue, and from there you can look at it as a code issue, if the above does not already fix it.

1 Like

Ok, I am sorry about this but I am going to have to ask another dumb question. Do I delete the Pstraight code and then add it to the main code (by main code I refer to the tiny piece of code that starts with ¨When Brain Check Button Pressed¨) or just add it to the main code regardless?

To answer this latest question, disconnect the other blocks you have under the “When Brain Check Button pressed”, and just put in two drive forward blocks.

I have taken a look at your setup from what you originally posted, and you definitely have both left and right motors turning in opposite directions. Either your left motor or your right motor needs reversed (and it will depend on whether you’re direct-driven, or if you have an even or odd number of gears). In the end, reverse one, issue spin forward commands for both, and if it drives forward, your motor setup is good. If it drives backwards, then un-reverse the one you had done, and reverse the other motor.

1 Like

I do not understand, I have changed the code a little bit to what I think you meant and the robot moves backwards at an angle, though less than before (changed code attached) Would it help if I sent a video of the bot?
autonreal one.iqblocks (30.6 KB)

You still have not reversed one of your drive motors.

I’m going to assume your left motor does not need to be reversed, but your right motor DOES NEED TO BE REVERSED. This is because the motor is effectively flipped when it’s mounted on the right side, so forward spins the OPPOSITE direction compared to the left motor. Go in and make this change:

image

And then this is what I meant for the simple test code; it will make the robot drive in one direction until you stop it, but try this:

image

If you do both of these things, and it goes backwards, then change right motor to be ‘Normal’ and change left motor to be ‘Reverse’.

2 Likes

Ok so, I did what you said, and it does in fact move forward but only when I use the left drive rightdrive , and spins when I use the Pstraight myblock code. I also cannot control how far it goes

I am at work now, so I cannot look at your updated blocks file until later. If the drive straight block is trying to turn, then make sure your inputs make sense and try manually working through the math to make sure you’re getting your intended output (motor velocity percentage) that is reasonable.

1 Like

I will also try to help troubleshoot this tonight, but will reiterate that this clearly seems to be beyond the skill level of the team at the moment and would encourage you to pursue other options in auton code that may be more within your current grasp.

Well, I agree in your earlier post that the robot itself should be equal to the skill level of the robot. Nobody on our team is actually a ¨coder¨ but even if I cannot use this CTR code for our bot, I would at least like to know the issue

So, I took another look at your code and I see the problem. However, you need to be the one to look through it to find your error. Re-examine the code you used from CTR, and check that everything is assigned as it should be.

1 Like

I understand that I need to find the error, and I appreciate you sticking with me and helping me so far. I was just confused when you said check what is assigned. Do you mean the motor ports?

It’s hard to place a spec on returned gyro angle.

For the old gen 1 gyro, it’s true we return values from the gyro to brain with 16 bit precision, but there’s no way it has 0.005 deg accuracy. It’s an old product, I didn’t work on firmware for that one, so don’t have much familiarity with internal details.

The new products use a sensor with 3 axis accelerometer and 3 axis gyro, we use the same part in many products. The raw data is run through a sensor fusion algorithm to produce values for roll, pitch and yaw (internally it’s actually stored as a quaternion). Absolute heading/rotation is derived from that. We have specs for the raw gyro/accelerometer values, but not one for the resultant heading.

In all cases I would not expect an accuracy of much more than 0.1 degrees.

5 Likes

The error is in the block code itself, in the drive straight block. You need to make sure that all the motors you’re trying to move are the right ones.

1 Like