我们正在为 FTC Skystone 制定停车代码,其中颜色传感器正在寻找色调值的变化来停止机器人。大多数情况下它都能工作,但如果我们按下停止按钮,代码就会继续执行,并会出现错误,OpMode 会卡在 stop() 中。除此之外,传感器只会读取五次中的四次,我们不知道还能做什么来让它发挥作用。这是我们的代码:@Overridepublic void runOpMode(){ // Drive train initialization motorFrontRight = hardwareMap.dcMotor.get("FR"); motorFrontLeft = hardwareMap.dcMotor.get("FL"); motorBackLeft = hardwareMap.dcMotor.get("BL"); motorBackRight = hardwareMap.dcMotor.get("BR"); motorFrontLeft.setDirection(DcMotor.Direction.FORWARD); motorFrontRight.setDirection(DcMotor.Direction.REVERSE); motorBackLeft.setDirection(DcMotor.Direction.FORWARD); motorBackRight.setDirection(DcMotor.Direction.REVERSE); // Color sensor initialization sensorColor = hardwareMap.get(ColorSensor.class, "color_sensor"); color2 = hardwareMap.get(ColorSensor.class, "color2"); sensorDistance = hardwareMap.get(DistanceSensor.class, "color_sensor"); // Color Sensor Values float hsvValues[] = {0F, 0F, 0F}; final float values[] = hsvValues;. final double SCALE_FACTOR = 255; telemetry.addData("Status: ", "Initialized"); telemetry.addData(">", "Press Play to start op mode"); telemetry.update(); waitForStart(); while (opModeIsActive()){ // Color Sensor Code Color.RGBToHSV((int) (color2.red() * SCALE_FACTOR), (int) (color2.green() * SCALE_FACTOR), (int) (color2.blue() * SCALE_FACTOR), hsvValues); Color.RGBToHSV((int) (sensorColor.red() * SCALE_FACTOR), (int) (sensorColor.green() * SCALE_FACTOR), (int) (sensorColor.blue() * SCALE_FACTOR), hsvValues); } }
1 回答
缥缈止盈
TA贡献2041条经验 获得超4个赞
我们通过 FTC 论坛了解到 while (step == 0){
if (opModeIsActive()){
到
while (step == 0 && opModeIsActive()){
添加回答
举报
0/150
提交
取消