Skip to content

Commit

Permalink
Exit conditions and slew are now more clear (#130)
Browse files Browse the repository at this point in the history
* ⬆️3.1.0, Tutorial Overhaul (#128) (#129)

* Getting ready for 3.1.0.  Missing motion chaining

* Upgraded Docusaurus to 3.4.0

* Up to date with v3.1.0-RC2

* Reformatted drive constructors

* Completed `Getting Started/` and `User Control/` tutorials overhaul

* Added exit conditions, slew.  Cleaned every tutorial page.

* Fixed breaking changes for pros 4

* Started adding support and showcase page, unfished and setup as drafts

* Fixed broken link and updated example auto formatting

* Exit conditions and slew are now more clear
  • Loading branch information
ssejrog authored Jun 11, 2024
1 parent bf05ed0 commit cf3be2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 12 additions & 1 deletion ez-template-docs/tutorials/slew_constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ Most robots will work perfectly fine without slew.  You can visit this page if
## What is it?
Slew is when your motors start at a lower speed and build up to a faster speed.  This can be useful if your robot is prone to tipping, can wheelie easily, or is prone to wheel slip at the start of motions.  

EZ-Template treats the output of slew as a **maximum speed** the PID can output. The output of slew does **not** get set to the motors. If slew is enabled for an extremely small motion, it is very likely that slew will not do anything and your motion will still be as fast as possible.

## Tuning Slew
There are 2 parameters to tune with slew in EZ-Template; the distance to slew for and starting speed.  The robot will accelerate very quickly with a low distance to slew for, regardless of the starting speed.  

There are 2 parameters to tune in EZ-Template.
* Distance to slew for
* The larger this number is, the longer it will take to reach your maximum speed. Making this number smaller will cause the robot to accelerate quickly.
* Starting speed
* The smaller this number is, the slower the robot will start motions. Making this number smaller will cause the robot to accelerate slowly.

There is a push and pull balance between these two variables and you have to find the middle ground.

I will tune slew by running normal motions but having the robot go slower.  The goal is to find the fastest the robot can go without any of the undesirable behaviors described above.  To enable slew you need the `true` parameter at the end of your `x_pid_set()`.  
```cpp
void tuning_slew() {
chassis.drive_pid_set(24_in, 80, true);
chassis.pid_wait();
}
```

Expand All @@ -35,10 +46,10 @@ Now you can lower the distance until the robot is able to successfully reach `DR
```cpp
void tuning_slew() {
chassis.drive_pid_set(24_in, DRIVE_SPEED, true);
chassis.pid_wait();
}
```

## Specifics for Each Motion

### Driving
Sometimes robots aren't symmetrical and can be tippier in one direction than the other.  This can be solved by choosing one of the following functions to place in `default_constants()`.  
Expand Down
12 changes: 9 additions & 3 deletions ez-template-docs/tutorials/tuning_exit_conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ EZ-Template's exit conditions are a little more special than that though.  We r
You can add another layer to this where it'll also check for a larger area.  Now 2 timers will run, one when you're within X of target and one when you're within Y of target.
![](images/big_timeout.gif)

But when the robot enters the smaller exit zone, the big timer will not continue.  This can be seen here.
But when the robot enters the smaller exit zone, the big timer will not continue.  If the big timer was not reset to 0 and we overshot target, big timer would be starting from a very high number and we would exit before correctly confirming the robot has settled. This can be seen here.
![](images/big_timeout_reset_small_timeout.gif)

There are 2 more timers that you can add on as well.  These are intended to be **failsafes** for when the previous two don't trigger fast enough or don't trigger at all.  One timer will start to increase when the velocity of the robot is 0, so if the robot is still for too long it'll exit.  Another timer will start once the robot sees it's pulling on the motors too hard (ie, you're fighting your opponent for a mobile goal), and if it's doing this for too long it'll exit.  
Expand Down Expand Up @@ -67,12 +67,14 @@ chassis.pid_wait_until(24);
```

### pid_wait_quick_chain()
`pid_wait_quick_chain()` is your fastest way of exiting.  The code below is what happens internally.  You will tell the robot to go 24 inches, internally X will get added to target, and `pid_wait_until()` will get called with the target YOU entered.  While being the fastest way of exiting, this should be used with caution as it can lead to inconsistencies.  Make sure your PID is well-tuned and do enough testing that you're confident your results are consistent.  
`pid_wait_quick_chain()` is your fastest way of exiting.  The code below is what happens internally.  You will tell the robot to go 24 inches, internally X will get added to target, and `pid_wait_until()` will get called with the target YOU entered. The code below is what happens for you internally.
```cpp
chassis.pid_drive_set(27_in, 110);  // You really want to go 24in
chassis.pid_wait_until(24);
```

While being the fastest way of exiting, this should be used carefully to avoid inconsistencies.  Make sure your PID is well-tuned and do enough testing that you're confident your results are consistent.  

## Tuning
Ultimately you're tuning for 2 functions; timers and when to start timing for `pid_wait()`, and how much to add to target for `pid_wait_quick_chain()`.  

Expand All @@ -99,7 +101,11 @@ The default constants are already pretty aggressive, you shouldn't have to tune
You should make these numbers as low as you can without causing inconsistencies.  With `pid_wait()` you generally want the robot to be pretty close to stopped before it moves on to the next motion.  

### Tuning pid_wait_quick_chain()
You can tune the amount added to `target` during chained motions.  If this number is too large, you'll carry too much momentum into the next motion and will cause inconsistencies.  The only downside to this number being too small is potential wasted time as it could turn into a normal `pid_wait()` if you don't overshoot your target.  Generally, I would err on this being smaller.  
You can tune the amount added to `target` during chained motions.  

**Larger constants** will carry more momentum into the next motion, making your autonomous faster but potentially hurting consistency. **Smaller constants** will carry less momentum into the next motion, this will still be significantly faster then any other method of exiting but could be slightly less consistent than `pid_wait()`.

If I were making autonomous routines, I would try to use a smaller constant for normal motions and only push a larger constant when an autonomous routine would greatly bennifit from it.


#### Driving
Expand Down

0 comments on commit cf3be2c

Please sign in to comment.