New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For IterativeRobots, teleopPeriodic is running ~720 times per second #251

Closed
vanjac opened this Issue Jan 12, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@vanjac
Contributor

vanjac commented Jan 12, 2017

I wrote this to test the timing for teleopPeriodic:

import wpilib

class TestRobot(wpilib.IterativeRobot):
    
    def robotInit(self):
        self.count = 0

    def teleopPeriodic(self):
        if self.count % 50 == 0:
            print("1 second")
        self.count += 1

if __name__ == "__main__":
    wpilib.run(TestRobot)

In 5 seconds, "1 second" was printed 72 times. So it seems like teleopPeriodic is being called ~720 times per second, instead of ~50 according to the documentation.

To make sure it wasn't Driver Station sending packets too quickly, I also wrote this:

import wpilib

class TestRobot(wpilib.IterativeRobot):
    
    def robotInit(self):
        self.joystick = wpilib.Joystick(0)

    def teleopPeriodic(self):
        print(self.joystick.getX())

if __name__ == "__main__":
    wpilib.run(TestRobot)

And ran it while moving the joystick quickly. The rate didn't slow and same values were printed multiple times in a 50 Hz cycle before switching to the next one. So maybe it just isn't properly waiting for a new packet before running teleopPeriodic again.

@virtuald

This comment has been minimized.

Show comment
Hide comment
@virtuald

virtuald Jan 12, 2017

Member

Hm, that's definitely a problem. All of the waiting stuff is in the DriverStation class... there's a thread that calls hal.waitForDSData, maybe it's returning too quickly?

Oh ha, self.waitForDataPredicate isn't being reset.

Member

virtuald commented Jan 12, 2017

Hm, that's definitely a problem. All of the waiting stuff is in the DriverStation class... there's a thread that calls hal.waitForDSData, maybe it's returning too quickly?

Oh ha, self.waitForDataPredicate isn't being reset.

@twinters007

This comment has been minimized.

Show comment
Hide comment
@twinters007

twinters007 Jan 13, 2017

Contributor

Out of curiosity, what made you question the timing?

Contributor

twinters007 commented Jan 13, 2017

Out of curiosity, what made you question the timing?

@b-mck

This comment has been minimized.

Show comment
Hide comment
@b-mck

b-mck Jan 13, 2017

@twinters007 We were actually testing timing for some dead-reckoning code. To further test we logged joystick input in TeleopPeriodic and saw dozens of identical updates where there should have been one.

b-mck commented Jan 13, 2017

@twinters007 We were actually testing timing for some dead-reckoning code. To further test we logged joystick input in TeleopPeriodic and saw dozens of identical updates where there should have been one.

@vanjac

This comment has been minimized.

Show comment
Hide comment
@vanjac

vanjac Jan 13, 2017

Contributor

I can work on a pull request for this

Contributor

vanjac commented Jan 13, 2017

I can work on a pull request for this

@virtuald

This comment has been minimized.

Show comment
Hide comment
@virtuald

virtuald Jan 13, 2017

Member

I have a fix, pushing it now actually.

Member

virtuald commented Jan 13, 2017

I have a fix, pushing it now actually.

@virtuald virtuald closed this in 50e172a Jan 13, 2017

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