View Full Version : Team 1288 Initial Python Code release
This is the first year team 1288 is using python for our robot. Here is our initial code going into the competition.
We only scratched the surface of what we can do with python and hope to greatly improve our coding process in the years to come!
TimTheGreat
11-03-2015, 23:16
First off, congrats. Python is a great language choice since it's so easy to use.
I went through your code because it is always fun to see how teams do stuff differently, and I noticed a few things.
self.cameraFour = wpilib.USBCamera(b'cam3')
Did you mean to put b'cam3'?
Also, the code for gyro rotation seems awfully long. 1418 did this last year and the way we did it was
angleOffset = target_angle - self.return_gyro_angle()
if angleOffset < -1 or angleOffset > 1:
self.rotation = angleOffset * self.angle_constant
self.rotation = max(min(0.5, self.rotation), -0.5)
self.angle_constant was used to keep the rotation speed low. It was .04. The max(min()) code keeps the rotation in between -.5 and .5 as an extra safety precaution. Then we just pass self.rotation into the mecanum drive method to rotate.
We only scratched the surface of what we can do with python and hope to greatly improve our coding process in the years to come! Either now while you're waiting for competition or during the offseason rewrite your code. It is a great way to learn, as you often think of a better way to do something. Also, look at other python teams and their code from previous years.
PS: Don't forget to add yourselves to the 2015 RobotPy Roll Call (https://github.com/robotpy/robotpy.github.io/blob/master/community.md)
TimTheGreat
11-03-2015, 23:34
You guys aren't using github are you?
virtuald
12-03-2015, 01:02
Good stuff! Glad to see more people making use of python :)
You might find that your autonomous state machines will be easier to create/read/adjust if you use the StatefulAutonomous (http://robotpy-wpilib-utilities.readthedocs.org/en/latest/robotpy_ext.autonomous.html#robotpy_ext.autonomous .stateful_autonomous.StatefulAutonomous) stuff in robotpy-wpilib-utilities.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.