Pros Potentiometer Motor Controller

For this years game, we are using a reverse double four bar lift to place cubes in towers. In order keep the lift from twisting due to external problems, (gear slip, robot impact, etc.) we added a potentiometer to each side of the lift to track each side individually. I would like to use an async position controller in Pros achieve this, however, I cannot identify how to structure the controller builder.

Potentiometer rightLiftAngle(rPot);

auto leftLiftControl = AsyncPosControllerBuilder().withMotor(lLift).withSensor(lPot).build();

The names ‘lLift’ and ‘lPot’ are global identifiers to the ADI port numbers. How do identify that this port is a potentiometer, or is the fact that I only specify one port in the sensor field enough information to identify the sensor type?

PROS Potentiometer class is derived from the RotarySensor.

https://okapilib.github.io/OkapiLib/classokapi_1_1RotarySensor.html
https://okapilib.github.io/OkapiLib/classokapi_1_1AsyncPosControllerBuilder.html

This may be the code you are looking for:

Potentiometer rightLiftAngle(rPot);
auto pot_ptr = std::make_shared(rightLiftAngle);

auto  leftLiftControl = AsyncPosControllerBuilder().withMotor(lLift).withSensor(pot_ptr).build();

leftLiftControl->tarePosition(); // set cutrrent position as "zero"

leftLiftControl->setTarget(...);
rightLiftControl->setTarget(...);

while( !leftLiftControl->isSettled() &&
       !rightLiftControl->isSettled() )
 pros::task::delay(10);

More ClosedLoopController help:
https://okapilib.github.io/OkapiLib/classokapi_1_1ClosedLoopController.html

2 Likes

Yeah you need to pass a shared pointer to the builder, not the potentiometer or the port.

auto leftLiftControl = AsyncPosControllerBuilder()
  .withMotor(lLift).withSensor(std::make_shared<Potentiometer>(lPotPort)).build();
4 Likes

This makes sense, thanks for the help.