Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

obstacleDistance() from robotdriver.ts returns NaN #87

Copy link
Copy link

Description

@Bertani545
Issue body actions

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.

Reactions are currently unavailable

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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.