Go to Post People... chill. It is week 1. Recall week 1 last year when many teams said "no one is capping with the 2x ball"... "only a few teams are hanging". - Andy Baker [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-11-2012, 02:11
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Announcing a new RobotPy tool: fake-wpilib!

This is a library designed to emulate parts of WPILib (we have not implemented all of it, since we didn't need it) so you can more easily do unit testing of your robot code on any platform that supports python3, without having to have a cRio around for testing. Our team used it last year with our robot code, this is a better packaged version of that same code.

In particular, we use this to quickly run our robot code in all modes before uploading it to the robot, to ensure that there aren't any obvious indentation or syntax errors that might not have been caught otherwise. An example that does this is included, called 'import_test'

Please let us know if you use it, and how we can make it better -- and submit patches to add/fix functionality! We will be updating it as we use it.

Probably during the regular season this will be released in a separate package on the RobotPy website. For now, you can download it via the RobotPy github site at https://github.com/robotpy/fake-wpilib

One thing that we have implemented with it is a pyTkinter-based game for our students to code against -- using this library and a GUI implementation, they can drive their robot code around on a virtual field shown on the screen. We're planning on implementing objects and stuff on the field and interactive sensors and stuff, so that they can learn robot programming even easier without a robot. We have not yet released this code, but probably in the future when it's more complete.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #2   Spotlight this post!  
Unread 07-12-2012, 18:01
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Announcing a new RobotPy tool: fake-wpilib!

I've updated fake-wpilib to include a working version of SmartDashboard (which is identical to the version contained in RobotPy), which you can use with the latest versions of SmartDashboard to test your SmartDashboard ideas on your PC.

By running 'C:\Program Files\SmartDashboard\SmartDashboard.jar ip 127.0.0.1', it will tell the SmartDashboard to connect to your code running on the PC. This is only supported in the SVN version of SmartDashboard, and does not work in the binaries currently released by FRC. This should work in 2013 releases, however.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #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
  #4   Spotlight this post!  
Unread 04-02-2013, 14:29
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Announcing a new RobotPy tool: fake-wpilib!

Glad to hear you've found it useful. I am curious why you're not using a class-based approach, however.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #5   Spotlight this post!  
Unread 04-02-2013, 15:36
nightpool's Avatar
nightpool nightpool is offline
robotRectifier
AKA: Evan
no team (formerly of CORE 2062)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 81
nightpool is on a distinguished road
Re: Announcing a new RobotPy tool: fake-wpilib!

Ehh. I'm not the OP, but everyone has different approaches to programming. Python is built to be multiparadigm and support both object-oriented and functional programming styles equally. In practice Python is mainly OO, but there are still a lot of cases where classes are just not needed.
__________________
Proud alum of CORE 2062.
www.core2062.com
Reply With Quote
  #6   Spotlight this post!  
Unread 04-02-2013, 15:44
nightpool's Avatar
nightpool nightpool is offline
robotRectifier
AKA: Evan
no team (formerly of CORE 2062)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 81
nightpool is on a distinguished road
Re: Announcing a new RobotPy tool: fake-wpilib!

Quote:
Originally Posted by tux View Post
Code:
    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...
Doesn't fake_wpilib already do this? Looking at __init__.py Wait is already tied to fake_time.Wait
__________________
Proud alum of CORE 2062.
www.core2062.com
Reply With Quote
  #7   Spotlight this post!  
Unread 04-02-2013, 17:13
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Announcing a new RobotPy tool: fake-wpilib!

Quote:
Originally Posted by nightpool View Post
Ehh. I'm not the OP, but everyone has different approaches to programming. Python is built to be multiparadigm and support both object-oriented and functional programming styles equally. In practice Python is mainly OO, but there are still a lot of cases where classes are just not needed.
Yes, I am aware that it is not necessary to do it that way -- that's why RobotPy has support for both ways (and perhaps at some point, fake-wpilib will support it too. Maybe someone can submit patches ).

However, it doesn't answer the question of why the OP decided to do it that way, which was the original question.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #8   Spotlight this post!  
Unread 04-02-2013, 17:53
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!

Quote:
Originally Posted by nightpool View Post
Doesn't fake_wpilib already do this? Looking at __init__.py Wait is already tied to fake_time.Wait
Right, but when I was trying to figure out what was going on I wanted things to go slower.

If you uncomment the import and the time.sleep() you can slow down the whole process...
Reply With Quote
  #9   Spotlight this post!  
Unread 04-02-2013, 18:02
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!

Quote:
Originally Posted by virtuald View Post
I am curious why you're not using a class-based approach, however.
None of our students have any programming experience. I think it is simpler to start with a function-based system.

I have introduced a decorator that sets up static variables (sort of like in C) which helps to alleviate the need for global variables that the functional style sometimes requires.


Code:
def static(**kw):
    '''
    Used to create a decorator function that will add an
    attribute to a function and initialize it.

    >>> @static(foo=5)
    ... def bar():
    ...     print(bar.foo)
    ...     bar.foo += 1
    ...
    >>> bar()
    5
    >>> bar()
    6
    '''

    def decorator(f):
        f.__dict__.update(kw)
        return f
    return decorator
Reply With Quote
Reply


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