FtcRobotController icon indicating copy to clipboard operation
FtcRobotController copied to clipboard

Change the hardwareMap.get syntax

Open RibsTheGreat opened this issue 7 months ago • 2 comments

The syntax for hardwareMap.get is super weird when you have to say DcMotor.class. Why don't you just make it DcMotor?

RibsTheGreat avatar May 21 '25 02:05 RibsTheGreat

Unfortunately I believe there isn't really a better way to do that. hardwareMap.get<DcMotor>("motor") would be preferable, but because of type erasure that's impossible, so the only way to actually pass in the class data is the current syntax. I would love to be wrong, though.

zachwaffle4 avatar May 21 '25 12:05 zachwaffle4

There are some device mapping structures in HardwareMap that you can use, it looks a bit nicer. For example:

hardwareMap.dcMotor.get("motor");
hardwareMap.servo.get("servo");
hardwareMap.crservo.get("servo");

Here's all of them: https://github.com/OpenFTC/Extracted-RC/blob/ce0a67af28c966c7a166ae51765e115a853734fc/RobotCore/src/main/java/com/qualcomm/robotcore/hardware/HardwareMap.java#L80-L105

Other than that there's not much flexibility and it comes down to a language limitation.

bubner avatar Jun 15 '25 01:06 bubner