Skip to content

obstacleDistance() from robotdriver.ts returns NaN #87

Description

This only happens once after initializing the robot but causes some bugs for some programs.
For example, the next code works fine:

robot.onObstacleDistanceChanged(function () {
distance = robot.obstacleDistance()
    if (scanning) {
        if (distance > 15) {
            scanning = 0
            robot.motorTank(30, 30)
        }
    } else {
        if (distance < 15) {
            robot.motorTank(-30, -30)
            robot.motorTank(0, 0)
            robot.motorTank(-25, 25)
            basic.pause(1000)
            scanning = 1
            robot.motorTank(25, -25)
        } else {
            robot.motorTank(30, 30)
        }
    }
})
let scanning = 0
let distance = 0
robot.dfRobotMaqueen.start()

But if I invert the conditional, that single frame where it is NaN makes it such that the robot starts spinning at the beginning of the program.

robot.onObstacleDistanceChanged(function () {
distance = robot.obstacleDistance()
    if (scanning) {
        if (distance > 15) {
            scanning = 0
            robot.motorTank(30, 30)
        }
    } else {
        if (distance > 15) {
            robot.motorTank(30, 30)
        } else {
             robot.motorTank(-30, -30)
            robot.motorTank(0, 0)
            robot.motorTank(-25, 25)
            basic.pause(1000)
            scanning = 1
            robot.motorTank(25, -25)
           
        }
    }
})
let scanning = 0
let distance = 0
robot.dfRobotMaqueen.start()

If I'm not wrong, this could be fixed changing line 45 of the file drivers/kalmanfilter1d.ts to if (isNaN(this.x) || isNaN(this.cov)) {.
I do not make a pull request because I don't know how to test this libraries.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions