a quality of life util lib for pros!
features motor groups, and various util functions.
(thank you evana thomson for the inspiration!)
keejlib is intended to be added to an existing pros project, simply drag the lib folder into your project and add #include lib/lib.hpp
to include the library. everything is under the lib
namespace.
initialize motor groups
pros::Motor mtr1(1, pros::E_MOTOR_GEARSET_06, true);
pros::Motor mtr2(2, pros::E_MOTOR_GEARSET_06, true);
//normal motor group
lib::mtrs motorGroup(std::vector<pros::Motor>{mtr1, mtr2});
//differential motor group (motors need to spin diff velocities)
lib::diffy diffyGroup(std::vector<pros::Motor>{mtr1, mtr2});
differential motor groups must consist of an even amount of motors. when initializing 2n motors, it will consider the first n motors as paired together, and the second n as well. each "pair" of motors can be spun at a different voltage.
motor group usage
motorGroup.spin(127);
diffyGroup.spin(90);
diffyGroup.spinDiffy(127,-100);
motor group methods are as follows:
spin(double volts)
stop(char brakeMode)
('c', 'b', 'h')setBrake(char brakeMode)
reset()
getSpeed()
getRotation()
diffy only:
spinDiffy(double rvolt, double lvolt)
getDiffy()
diffy groups inherit all methods from normal motor groups.
imu
keejlib also has its own imu class in order to get radian heading, and to set an initial heading. (ex. if the robot starts facing left, you can set the initial heading to 90 degrees.)
usage
pros::Imu imu(1);
lib::imu(imu, 0); //second parameter is the initial rotation.
double currHeading = lib::imu.radHeading();
opcontrol
code is pretty self explanatory, example code follows:
//functions to call
std::function<void()> intake = [&] {spin(&robot::sekai,127); };
std::function<void()> puncher = [&] {spin(&robot::sekai,-127); };
std::function<void()> stopSekai = [&] {stop(&robot::sekai, 'c'); };
//keys to listen to
lib::controllerButton L1(glb::controller, pros::E_CONTROLLER_DIGITAL_L1);
//pair keys to a functiom
lib::action onL1(&L1, intake, stopSekai);
lib::action onLimit(&robot::puncherLimit, puncher, stopSekai);
con.init(std::vector<lib::action> actions{onL1, onLimit});
chassis
lib::chassis chass(diffyGroup, imu);
chass.updatePos(2,3);
this is only meant as a template class, add methods as you please. an example drive function is included.
util
keejlib also features various utility functions and classes, most are trivial to use. example usage is as follows (copy and pasted from the default drive function)
void lib::chassis::drive(double target, double timeout, util::pidConstants constants)
{
double error = target;
util::timer timer;
util::pid pidController(constants, target);
chass.reset();
while(timer.time() < timeout)
{
error = target - chass.getRotation();
chass.spin(pidController.out(error));
}
chass.stop('b');
}