|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#3
|
|||
|
|||
|
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 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
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])
Thanks for fake-wpilib! |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|