PROS/Okapi Motion Profiling Crash

I’m in the process of switching to PROS+Okapilib, and when I added an AsyncMotionProfileController to my code, it just stopped working.

//Drive motors (md<side><number>)
Motor mdl1 = -11;
Motor mdl2 = -19;
Motor mdr1 = 3;
Motor mdr2 = 14;

MotorGroup DriveLeft({mdl1,mdl2});
MotorGroup DriveRight({mdr1, mdr2});

std::shared_ptr<ChassisController> Chassis = ChassisControllerBuilder()
  .withMotors (
    DriveLeft,
    DriveRight
  )
  .withDimensions(
    AbstractMotor::gearset::blue,
    {{3.25_in, 7_in}, imev5BlueTPR * (5.0 / 3.0)}
  ).build()
;

std::shared_ptr<AsyncMotionProfileController> ChassisMotionController = AsyncMotionProfileControllerBuilder()
  .withOutput(Chassis)
  .buildMotionProfileController()
;

When I remove the declaration for ChassisMotionController, it works fine (I’m not actually referencing it anywhere yet), but with the AsyncMotionProfileController, it gets stuck on a black screen, not even entering initialize, where my lvgl menus are created. Has anyone else experienced this issue?

This happens when something throws an exception when begin constructed in global scope. We can’t show exceptions in this case, so you get the behavior you see. Set ChassisMotionController in initialize instead of using a global builder to see what exception it’s throwing (It’ll be printed to the console and the screen on the latest kernel version).

3 Likes

Please do not build any OkapiLib objects globally. Move those into initialize or competition_initialize.

1 Like

If you don’t mind explaining, why not?

For this exact reason. If building the object throws or segfaults, PROS can’t help you see why (because it happened before PROS could set up the stuff that helps you see why). Additionally, constructing these objects globally makes it much harder to configure logging if you need to debug something down the line.

1 Like

That makes a lot of sense.

In general, global objects are evil - you have little to no control over their construction and destruction order, so when you have a complex system with interdependent subsystems, you’ve got no guarantees which systems are up at what point in time.

1 Like

Ok so I moved the construction of the AsyncMotionProfileController and the DriveController into initialize(), and now it hangs when it gets to that

LVGL starts, but since it hangs, it never gets to the point of drawing my menu.

Please run the program with the PROS Terminal open and see what it reports.

1 Like

I figured it out. I needed to set withLimits.

2 Likes