Go to Post I respect what you have to say and I ask that you do the same for me. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 03-02-2013, 22:52
tux tux is offline
Registered User
AKA: Lee Harr
FRC #3842 (Shock-a-Bots)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Rochester, NY
Posts: 91
tux is an unknown quantity at this point
Re: Announcing a new RobotPy tool: fake-wpilib!

I am using fake-wpilib as a handy test before committing or uploading code. Saves me a lot of time since I tend to do dumb things like forgetting to import a function that I started using and mistyping names.

Our code is not class based, so I monkey-patch _wpilib to enable the robot, switch to autonomous mode, then switch to teleoperated.

I have a module called
Code:
get_wpilib.py
All modules that need wpilib say:
Code:
from get_wpilib import wpilib

Code:
try:
    import wpilib
except ImportError:
    import sys
    sys.path.append('../fake-wpilib/lib/')
    import fake_wpilib as wpilib

    import _wpilib
    _wpilib.internal.enabled = True
    def start_auto(tm):
        #print(tm)
        return tm > 2 and tm < 17
    _wpilib.internal.on_IsAutonomous = start_auto

    def start_tele(tm):
        #print(tm)
        return tm > 17 and tm < 30
    _wpilib.internal.on_IsOperatorControl = start_tele


    def wwwait(t):
        #import time
        #time.sleep(0.01)
        _wpilib.fake_time.Wait(t)
    wpilib.Wait = wwwait
wwwait can be used to slow things down if needed...


I also modified the joystick code to return random values. I think of it as "fuzz testing" the robot code.

Code:
    def GetRawAxis(self, axis):
        import random
        return random.uniform(-1, 1)

    def GetRawButton(self, number):
        import random
        return random.choice([True, False])
Works pretty well so far. Saves many reboots!

Thanks for fake-wpilib!
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:24.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi