Go to Post "PWMed" - Sam N. [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 11-02-2016, 09:23
onenerdyguy onenerdyguy is offline
Registered User
FRC #5929
 
Join Date: Jan 2016
Location: Lake Park, MN
Posts: 42
onenerdyguy is an unknown quantity at this point
Noob question, but would love some advice

So, we're 90% done with our code, and a team member had a question that I honestly didn't have a good answer for.

Why do we have things broken out in commands/subsystems/etc files instead of just making one giant robot.py file?

My initial answer is to make it easier to split up the coding as well as making sure that one failure in a system won't bring the bot down, but as we've coded more we find that if you screw up in a subsystem or a command, it'll bring down when that code iniatializes anyways.

Help me out?
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2016, 09:49
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: Noob question, but would love some advice

It's much easier to manage and organize. If you have a robot.py file that is 10k lines long, how much time is it going to take to find where you initialized the joysticks?

If you have it under /robot/joysticks/joystick_left.py, you know exactly where it is, and is likely 20 or 30 lines long in total.

Also, imagine you have more than one programmer, you can give each programmer a subsystem to work with. The changes they make are isolated to their subsystem and don't affect the code of other people's code / subsystems.

Code management is a primary reason.
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2016, 10:02
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: Noob question, but would love some advice

Everything that RyanN said.

Honestly, command based programming in RobotPy is not very pythonic, and I find that it takes a lot of boilerplate to get even simple things done. There are definitely ways to address some of it -- in particular, we probably should have better support for not crashing the whole bot if one of your commands is broken. However, I don't use Commands et al, so I haven't messed with its internals that much.

This season, I've introduced an experimental framework called MagicBot that is simpler to use than command based programming and has builtin stuff to ensure that a wayward component doesn't bring the entire bot down in a competition -- but it's not quite as full featured yet (in particular, no support yet for sequential state machines like CommandGroups -- but maybe I'll do that this weekend).

The documentation explains some of my philosophy for structuring robot code, you may find it useful. http://robotpy-wpilib-utilities.read.../magicbot.html
__________________
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
  #4   Spotlight this post!  
Unread 11-02-2016, 10:04
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,736
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Noob question, but would love some advice

While the small programs we use on these robots may not really require it (back in the day on IFI's old system, pretty much everything we did was in one file!), it is a really, really good industry practice to teach your students. It's called separation of concerns, where you literally separate the different areas. It helps with debugging - if your problem is with your climbing mechanism, you can ignore the files related to shooting or driving, for example. It helps with code understanding - someone new can come in and grasp the general structure and fhedive into details much quicker than they can with a single big file. It helps with collaboration- if you use a repository (like git) to store your code and sync it across multiple people, you have less collisions checking things in, because people are working on different files. This is especially important in the "real world" where you may have a team of 20-50 people working on a single program that's literally hundreds of thousands of line long (or more!), When totaled.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #5   Spotlight this post!  
Unread 11-02-2016, 11:30
onenerdyguy onenerdyguy is offline
Registered User
FRC #5929
 
Join Date: Jan 2016
Location: Lake Park, MN
Posts: 42
onenerdyguy is an unknown quantity at this point
Re: Noob question, but would love some advice

Alright, cool, these are exactly the answers I was after.

I agree with everything said here. The figured there was no technical limitation, as all the test files we've put on the bot are single file monsters, but this confirms it.

Thanks!
Reply With Quote
  #6   Spotlight this post!  
Unread 11-02-2016, 11:38
onenerdyguy onenerdyguy is offline
Registered User
FRC #5929
 
Join Date: Jan 2016
Location: Lake Park, MN
Posts: 42
onenerdyguy is an unknown quantity at this point
Re: Noob question, but would love some advice

Quote:
Originally Posted by virtuald View Post
Everything that RyanN said.

Honestly, command based programming in RobotPy is not very pythonic, and I find that it takes a lot of boilerplate to get even simple things done. There are definitely ways to address some of it -- in particular, we probably should have better support for not crashing the whole bot if one of your commands is broken. However, I don't use Commands et al, so I haven't messed with its internals that much.

This season, I've introduced an experimental framework called MagicBot that is simpler to use than command based programming and has builtin stuff to ensure that a wayward component doesn't bring the entire bot down in a competition -- but it's not quite as full featured yet (in particular, no support yet for sequential state machines like CommandGroups -- but maybe I'll do that this weekend).

The documentation explains some of my philosophy for structuring robot code, you may find it useful. http://robotpy-wpilib-utilities.read.../magicbot.html
I'm really liking the look of that magicbot setup. It seems to be more of a middle ground and more of a python way of doing things, which is exactly where we are struggling. The kids found the way we had them coding commands/subsystems/etc to be extremely intensive due to the amount of repetitive boilerplate and frankly, led to tons of silly little errors.

I'm going to have to give this a shot on our practice bot, to see if it's worth looking at for off season training. Honestly, if it was week 3 instead of now and it tested stable, we might look at rolling it out to competition.
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