![]() |
LemLib
0.4.7
An easy to use and feature-rich PROS template
|
You have made it to the second tutorial! Now that you have LemLib installed, we can start using it. In this tutorial, we will be setting up the chassis.
The chassis has multiple components. LemLib will handle everything for you, but you need to tell it what components you have.
A vital component of any robot is the drivetrain. The drivetrain is what allows the robot to move around the field. LemLib needs to know what motors are in the drivetrain. Lets start by setting up the motors.
In PROS, setting up a motor is trivial. All you need to do is create a motor object, set its port, what cartridge its using, and if it is reversed or not. We need to do this for each motor on the drivetrain. Below is an example:
Now we need to group the left side and right side motors so we can pass it to LemLib. To do this, we can use the pros::MotorGroup
class. Here is an example:
Now that we have the motors set up, we need to tell LemLib about the track width, wheel diameter, and wheel rpm of the drivetrain. Let's start with the track width. The track width is the distance between the left and right drivetrain wheels, as shown in the image below:
We also need to tell LemLib the diameter of the wheels. Wheels typically come in 4 sizes: 2.75", 3.25", 4", and 4.125". After that, we need to tell LemLib the rpm of the wheels. If your drivetrain is not geared, then the rpm of the wheels is the same as the rpm of the motor cartridge. If it is geared, refer to this spreadsheet to find the rpm of the wheels.
Now that we have all the information we need, we can create a lemlib::Drivetrain_t
struct to pass to LemLib. Below is an example:
A crucial component of a consistent autonomous is position tracking, commonly known as odometry. Odometry allows the robot to know where it is on the field. LemLib has built in odometry, and is compatible with most tracking wheel / inertial sensor combinations. To set up odometry, we need to tell LemLib what sensors we are using. Lets start with the tracking wheels.
Tracking Wheels are unpowered wheels that are used to track the movement of the robot. Below is a photo of a typical tracking wheel:
A tracking wheel can rotate freely on a screw joint, and rubber bands pull it down so it makes consistent contact with the field tiles. Tracking wheels can be connected to either an Optical Shaft Encoder or a V5 Rotation Sensor. Both are supported by LemLib.
A gear ratio may be used to increase the resolution of the encoder. If you are using a gear ratio, you need to specify it to the lemlib::TrackingWheel
constructor. Gear ratios are input/output, so if you have a 2:1 gear ratio, the actual ratio is 2.
The first step in setting up the tracking wheels is to create an object for the encoder. Below is an example of how to do this:
Next, we have to create a lemlib::TrackingWheel
object. This contains information about the tracking wheel, such as the diameter and its offset from the tracking center. Below is an example of how to do this:
Hold on, how far away from the tracking center is the tracking wheel? Turns out, its not the straight distance to the center of the robot, but only one component of it. Below is a diagram which shows the relationship between the tracking center and the tracking wheel:
Remember, vertical tracking wheels should have a negative offset if on the left of the tracking center, and horizontal tracking wheels should have a negative offset if behindthe tracking center.
Now, we can put all the tracking wheels together into a struct with lemlib::OdomSensors_t
. This struct will be passed to the LemLib chassis. Below is an example of how to do this:
You don't need all these sensors though. Even if you don't have any, you can still use LemLib. If you don't have a sensor, just set it to nullptr
. Just remember that the more sensors you use, the more accurate the odometry will be.
Lemlib uses 2 PIDs to control the motion of the robot (except for pure pursuit). Every chassis will have different constants however, so you will need to tune them. More about that in the next tutorial. For now, just copy and paste the following code into your main.cpp
file:
Below is everything we have done so far, all passed to the lemlib::Chassis
constructor:
Thats it! You have now set up the chassis. In the next tutorial, we will learn how to use the chassis to move the robot and how to tune the PIDs.