Team973 / 2019-inseason

Deep Space code of FRC Team 973: The Greybots
https://team973.github.io/2019-inseason/html/
9 stars 0 forks source link

Runtime handling implementation for dual action stick swap in and out #31

Closed AddictArts closed 5 years ago

AddictArts commented 5 years ago

See branch driver_live_dual_action_support

Here is what we have:

* Robot is an observer for all types, Poofs, XBox, and Dual Action with members (Instances)

* Ports separate them and Robot does the same for all, 0, and 1 (Poofs / Xbox), 2, and 3 (Dual Action)

* Teleop for example, its HandleDual... uses the port to perform the same button handling for driver and operator. This was simple, because it is part of the dispatcher class and not duplicating code.

What remains ...

* Mode(s) periodic getting the raw axis for x and y plus quick turn and slow gear.

This new version can accomplish the remains at runtime. I implemented a base class for Poofs, DA, and XBox which inherits from Joystick. This was so that we could use polymorphism to handle the call to GetRawAxisWithDeadband from the periodic to get stick x and y. I also implemented a POD struct for the button assignment. So, the base looks like this:

class ObservableJoystickBase : public Joystick {
public:
    /**
     * Abstract Base class for the Observable...Joystick objects.
     */
    explicit ObservableJoystickBase(uint16_t port);
    virtual ~ObservableJoystickBase();

    /**
     * Get the value of the given axis with deadband.
     * @param axis Specifies the axis to get the value of.
     * @param fSquared Specifies whether the joystick input should be squared.
     * @param threshold Specifies the deadband threshold.
     */
    virtual float GetRawAxisWithDeadband(int axis, bool fSquared = false,
                                         double threshold = 0) = 0;

    /**
     * Get a const reference to the Common mapping for the type of joystick.
     */
    virtual const JoystickBase::JoystickCommon &GetJoystickCommon() = 0;
};

Teleop etc gets a ObservableJoystickBase, instead of the concrete class DualAction... or XBox...

Runtime

Now Robot could use detection to change which instance Teleop uses or it could use the "start" button on the Dual Action if we don't have a detection method.

AddictArts commented 5 years ago

We were able to test and found we could switch between the two types of sticks. The robot "disables" if you don't when usb stick is changed. When the DualAction is plugged in you press "start" and that enables the stick, pressing "back" disables it switching to default stick config. I needed to update handling the common buttons, so each type has a COMMON in their namespace, a "map". This is returned as a reference in the subclass implementation of GetJoystickCommon.

constexpr JoystickBase::JoystickCommon COMMON{
    DualAction::LeftXAxis,   DualAction::LeftYAxis,    DualAction::RightXAxis,
    DualAction::RightYAxis,  DualAction::LeftBumper,   DualAction::RightBumper,
    DualAction::LeftTrigger, DualAction::RightTrigger,
};
AddictArts commented 5 years ago

I've updated the branch it is ready for testing