Xdriver model does not have xArcade()

use pros okapi factory to create a PID chassis controller with Xdrive model.

auto xdrivechassis= chassControllerFacotory::create (
1,-2,-3,4,
pid1,
pid2,
pid3,
gearset::green,
{1,1} )

it does create a chassisscontroller, however
when try to use
xdriverchassis.xArcade()
compiler says it does not exit.

it seems that the chassiscontroller we created is not xdriver type, more likely a skid type.

my question: how can i create a valid xdriver chassis controller that defines xArcade().

In the first example you create xdrivechassis, and in the second you call xdriverchassis (an r is added in the name)

thank for point out my typo. but my problem is more than that typo as i stated

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.

Hopefully this makes sense and it works for you.

1 Like

thanks a lot.
so i have two ways to get the xArcade()

  1. one is cast the chassis controller class to xdrivechassis class
  2. or get the xdrive model from the chassis controller and run from the model xArcade()

I don’t think the first way will work.
A ChassisControllerPID is not an XDriveModel. It’s a has-a relationship, not an is-a relationship.

i see. thank you very much

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().

ok , this is the problem again .

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?

we are using pros 3.1.6

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.

You should call this method: https://pros.cs.purdue.edu/v5/okapi/api/chassis/controller/abstract-chassis-controller.html#getchassismodel

2 Likes

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.

1 Like

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.