Go to Post Plugging your own design when people are recognizing others, especially when you are such a seasoned member of the forums just doesn't cut it anymore. - J Flex 188 [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
  #1   Spotlight this post!  
Unread 23-03-2014, 11:27
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
pyfrc autonomous framework teaser

Continuing some work from the last few years with Team 2423's code, I've been developing generic python modules that will allow python teams to develop autonomous modes that have the following characteristics:
  • Dynamic detection of autonomous modes at runtime
  • Automatic support of selection of which autonomous mode to use via SmartDashboard
  • Supports simple built-in tuning of autonomous mode parameters via SmartDashboard
  • Easy to create autonomous modes that support state machine or time-based operation
  • Autonomous modes that are easy to read and understand

Team 1418 has been using this framework this year with great success, and at some point in the near future I'll be releasing it as part of pyfrc. New features in pyfrc will allow this (and other useful libraries) to be installed directly to the robot.

Here's one of Team 1418's autonomous modes that can score two balls.

Code:
try:
    import wpilib
except ImportError:
    from pyfrc import wpilib

from common.autonomous_helper import StatefulAutonomous, timed_state

class TwoBall(StatefulAutonomous):
    
    MODE_NAME = 'Two balls'
    DEFAULT = True   
    
    def __init__(self, components):
        super().__init__(components)
        
        self.register_sd_var('drive_speed', 0.5)
        
    def on_enable(self):
        super().on_enable()
        
    def update(self, tm):
        if tm > 0.3:
            self.catapult.pulldown()
            
        super().update(tm)
    
    @timed_state(duration=1.2, next_state='drive', first=True)       
    def drive_wait(self, tm, state_tm):
        '''Wait some period before we start driving'''
        self.intake.armDown()
        
    @timed_state(duration=1.4, next_state='launch')
    def drive(self, tm, state_tm):
        '''Start the launch sequence! Drive slowly forward for N seconds'''
        self.drive.move(0, self.drive_speed, 0)
        self.intake.armDown()
    
    @timed_state(duration=1, next_state='go_back') 
    def launch(self, tm):
        '''Fire and keep firing for 1 seconds'''
        self.catapult.launchNoSensor()
        
    @timed_state(duration=2.9,next_state='drive2') 
    def go_back(self):
        '''Go back to get the next ball'''
        self.drive.move(0, -1*self.drive_speed, 0)
        self.intake.ballIn()
            
    @timed_state(duration=2.5, next_state='launch2')
    def drive2(self, tm, state_tm):
        '''Once we get it, drive forward'''
        self.drive.move(0, self.drive_speed, 0)
        self.intake.ballIn()
    
    @timed_state(duration=1) 
    def launch2(self, tm):
        '''And shoot!'''
        self.catapult.launchNoSensor()
        self.intake.ballIn()

Seems too simple to work? Well, here's a video of this autonomous mode in the Virginia Regional scoring both balls in team 1418's last qualifying match.
__________________
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
 


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

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