You are correct, a ChassisController or ChassisModel does not contain xArcade.
However, there is a way to access it, because it exists as part of of the XDriveModel that the controller contains if you initialize it with 4 motors.
The way to access it is a bit complicated, and you probably won’t understand it until you learn about polymorphism, which is an advanced C++ concept.
Here is how to access xArcade() from a ChassisController:
auto chassis = ...; // create the controller
auto xModel = std::dynamic_pointer_cast<XDriveModel>(chassis.getModel());
Then you can do
xModel->xArcade(...);
Basically, you know that your controller contains an XDriveModel, but the problem is that it is stored using polymorphism and so the code can’t tell the difference between any type of model. Since xArcade only exists in the XDriveModel, you have to explicitly tell the code that the chassis model is of type XDriveModel instead of the abstract ChassisModel which does not contain xArcade.
Yeah, the only reason ChassisController inherits from ChassisModel is because the controller extends the same interface as the model. However, since it’s actually a has-a relationship, the controller overrides each function and delegates to the internal model. Basically it only inherits the model’s interface but is not a model.
I believe in the latest, unreleased version of okapi (v4), this inheritance has been removed and all model commands need to be sent through getModel().
first the pros document does not show getModel() exists. if we call chassis.getModel(), compiler says not existing. do we have input arguments when call getModel()?
second, the prosv5 compiler suggests to use chassis.model instead. however it still says the member model is protected, flagging an error.
third , we try to make an identical XdriveModel by calling constructor or factory. that seems only solution now. Question is that there are two models, will it cause problem? Aslo, we can set PIDs, but there are no interface to set scale.
we are lost. Does anyone ever used XdriveModel before? any sample code?
my understanding is that ChassisControllerPID has a member of model, which can be either skid or xdrive. They are the same type but different objects. So it is not a polymorphism. we can only use xArcade from model , not from chassis.
all chassis are derived from abstract chassis controller, which does not define xArcade(). Therefore no one can really use xArcade( ) from chassis class. So the xdrive model is just a orphan class. its xArcade function is not used by any chassis.
Yeah, sorry I forgot to check if getModel in v4 existed in v3. It does, but under the name getChassisModel.
The rest of what I said should work.
Having multiple chassis is an easy way to lead to problems, it is best to only have one.
Like I said, the ChassisModel that the chassis controller contains is an XDriveModel if you give the factory 4 motors. You just need to cast it to access xArcade.
thanks a lot.
finally, it works!
it is cool that xArcade can do 3D motion, 2d x-y translation plus rotation.
Hopefully, when we do profiling movement, it can do 3d profiling as well.