How do you go about closed-loop driving?

Now that the season is over, it’s time to improve. The first thing I wanted to learn was how to program a closed-loop drive base.

Well, the thing that bothered me the most is that, if you go about closed-loop drive and instead of voltage to send to each of the motors in the sides of the chassis like open-looped drive base and instead go about reaching a certain velocity for each side of the chassis based on the input from the joystick, what happens when the chassis can no longer reach that speed (because of low battery voltage or something like that)?

How do I go about utilizing a closed-loop driving?

When you hit 100%, your motor controller isn’t going to be able to put out any more; if you want to be controlling the speed, you need to control it at a notch or two down from your maximum possible speed, at the lowest battery charge you are likely to have while doing it.

The question is, “Why?” Closed loop control is typically used to even out instabilities (e.g. driving straight over rough terrain, or traction control) or to navigate to a known position based on sensor input (e.g. vision targets).

BTW Just making sure that I’m clear about the topic of my thread (maybe I didn’t use the right name of the thing I wanted to ask about).

The thing I’m going for is that e.g. on teleop period, let’s say we’re using tank drive, and we’re going for 1/1 power on the chassis on both sides, that won’t ensure that we’re going straight (both sides of the chassis go at the same speed), I want to be able to fix that live using the code.

This is a fairly simple problem to solve, actually. Say you are using a simple P loop to do this - you capture the gyro angle relative to your desired angle, multiply it by a P constant, and then you check the sign of the result. Based on the sign, you either lower the left or right drive throttle command by that result. Tune the P constant until it is correcting properly.

The next step is incorporating this basic idea into a teleop drive loop where the driver will also intentionally rotate the robot. The easy way is to just apply this loop only when the left and right inputs are within some small margin of each other (depending on your joystick). There’s a lot of different directions you can go from here (e.g. precise angular turning, etc), but this is the most basic “drive straight code” idea.