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

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

Projects

None yet

4 participants

@vanjac
Contributor
vanjac commented Jan 12, 2017 edited

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
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.

@Twinters007
Contributor

Out of curiosity, what made you question the timing?

@b-mck
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
Contributor
vanjac commented Jan 13, 2017

I can work on a pull request for this

@virtuald
Member

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