Go to Post What about marriages ended by FIRST. I know that by Presidents Day my wife is not real happy with me :) - IndySam [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 04-22-2018, 09:32 AM
cpeppler cpeppler is offline
Registered User
AKA: Charlie Peppler
FRC #5459 (Tigers)
Team Role: Mentor
 
Join Date: Mar 2018
Rookie Year: 2017
Location: South Hamiltion, MA
Posts: 16
cpeppler is an unknown quantity at this point
Extending RobotPy/wpilib for a new motor controller

Dear Python development people at ChiefDelphi,

I would like to use Python wpilib to run a robot based on a Raspberry Pi. The standard wpilib has class support for FRC standard motor controllers (Talon, etc).

Is there a proper way to extend the wpilib to support Pi native motor controllers (typically lower power DC/Stepper/Servo motors)? I know there are several, but I started off with the MotorHAT from Adafruit, that comes with a Python library, so I have access to the source code for speaking to the board itself.

I would like to approach this in a way that fits in with the overall WPIlib philosophy, either deriving a class from an existing one...perhaps a sibling class to an existing motor controller class.

The goal is to create a low cost Pi based platform for training new students in the off season, then transfer those skills to the RoboRIO prior to build season.

Any input and direction would be appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 04-22-2018, 10:26 AM
cpeppler cpeppler is offline
Registered User
AKA: Charlie Peppler
FRC #5459 (Tigers)
Team Role: Mentor
 
Join Date: Mar 2018
Rookie Year: 2017
Location: South Hamiltion, MA
Posts: 16
cpeppler is an unknown quantity at this point
Re: Extending RobotPy/wpilib for a new motor controller

In going through the wpilib documentation, I looked at both the Jaguar (edu.wpi.first.wpilibj.Jaguar) and Talon classes. They are both derived from edu.wpi.first.wpilibj.PWMSpeedController. I also saw an I2C class used for communicating with an I2C bus (which the Pi has).
  • Does the pure Python wpilib have the PWMSpeedController and I2C classes?
  • If I were to derive a Python class from PWMSpeedController, can I pull code from the Adafruit library, use the I2C class, and get this to run in a manner consistent with the larger RobotPy methodology (robot initialization, working with Joystick/network tables, PID, etc.)
  • Am I looking in the right place?
Reply With Quote
  #3   Spotlight this post!  
Unread 04-22-2018, 02:15 PM
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #6367 (), FRC #7240 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,382
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: Extending RobotPy/wpilib for a new motor controller

Pasting from my prior post about this:

RobotPy's WPILib can run on any platform that a Hardware Abstraction Layer (HAL) exists for. Currently, two exist:
  • One for running on the RoboRIO that talks directly to the hardware present on the RoboRIO
  • Another for running in simulation that talks directly to a large dictionary that stores the running robot parameters

To do what you want, you would need to create a HAL for a RPi. Creating a new HAL wouldn't be particularly difficult, but I suspect it would be a lot of effort. The difficult part would be providing an equivalent to the driver station (or writing your own interface that allows the current DS to talk to it).

[endquote]

We have documentation similar to the Javadocs at http://robotpy.readthedocs.io/projec...atest/api.html ... so you can see what we do and do not have (spoiler: we have everything Java has).

Everything in WPILib is tightly bound to the HAL API. For example, the simulation HAL API can be found at https://github.com/robotpy/robotpy-w...l/functions.py

You could create your own HAL package that implements the right functions that do the right things and the the current wpilib could be usable without modifications. You just might find that the number of things needed to be implemented would be higher than you would like.
__________________
Maintainer of RobotPy (Python for FRC) & WPILib Contributor
Creator of pyfrc (Robot Simulator + utilities for Python), pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript), and lots more...

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

Last edited by virtuald : 04-22-2018 at 02:22 PM.
Reply With Quote
  #4   Spotlight this post!  
Unread 04-22-2018, 02:21 PM
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #6367 (), FRC #7240 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,382
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: Extending RobotPy/wpilib for a new motor controller

Also, here's a concrete example of what happens with the Talon.set call:
  1. talon inherits from PWMSpeedController, and configures the various PWM timing things it needs to work
  2. PWMSpeedController.set calls PWM.setSpeed which calls hal.setPWMSpeed
  3. In simulation, this is the function that gets called. On the RoboRIO, the HAL C API function of the same name gets called.

Just about everything in wpilib that interfaces with hardware works that way.
__________________
Maintainer of RobotPy (Python for FRC) & WPILib Contributor
Creator of pyfrc (Robot Simulator + utilities for Python), pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript), and lots more...

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-22-2018, 04:48 PM
cpeppler cpeppler is offline
Registered User
AKA: Charlie Peppler
FRC #5459 (Tigers)
Team Role: Mentor
 
Join Date: Mar 2018
Rookie Year: 2017
Location: South Hamiltion, MA
Posts: 16
cpeppler is an unknown quantity at this point
Re: Extending RobotPy/wpilib for a new motor controller

Dustin,

Thanks so much for taking the time to reply. I understand much better now what is involved, and the tight binding between RobotPy and the RoboRio specific HAL. You're right, the time and effort seems to make it impractical to rebuild a HAL for the Pi (much more than I had bargained for).

It appears that Kauai Labs has a board and HAL that seems to provide a full environment for the Pi. $159 for the board is a bit more than buying a $22 DC motor board, but counting the time to make the software work, it might be a more practical approach.

I just apt-get installed the vmxpi-hal.

Any chance this would work with RoboPy? (Shot in the dark!)
Reply With Quote
  #6   Spotlight this post!  
Unread 04-27-2018, 10:34 PM
cpeppler cpeppler is offline
Registered User
AKA: Charlie Peppler
FRC #5459 (Tigers)
Team Role: Mentor
 
Join Date: Mar 2018
Rookie Year: 2017
Location: South Hamiltion, MA
Posts: 16
cpeppler is an unknown quantity at this point
Re: Extending RobotPy/wpilib for a new motor controller

virtuald,

I think I've figured out how I'm going to do this. I've tested RobotPy on the Raspberry Pi, and except for motor controllers based on the RoboRio HAL, it can work with networktables.

I think I accidentally started following in the footsteps of team 2733 (Pigmice) who developed a driver station in Python. I was able to talk from their driver station to a RasPi python program using RobotPy through networktables. I then just called a Python library provided by Adafruit (for their MotorHAT motor control board). So far so good. Should have a little mobile teleoperated bot shortly.

So far, so good. Looking forward to getting deeper into RobotPy. We're looking at doing a hackathon using the Pi for some new incoming students, to prep them for FRC competition next season.

Thanks for your work!
Reply With Quote
  #7   Spotlight this post!  
Unread 04-27-2018, 10:44 PM
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #6367 (), FRC #7240 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,382
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: Extending RobotPy/wpilib for a new motor controller

Good luck! If anything you're working on would be useful to the greater FRC community, please let us know and/or submit a pull request to one of the RobotPy repos. More community involvement is key to the continued growth of python usage in FRC.

WPILib distributes an excellent tool called OutlineViewer which also allows you to view everything stored in NetworkTables. It's distributed with the Eclipse plugins, or you can download it separately at http://first.wpi.edu/FRC/roborio/mav.../OutlineViewer

I'm sure you've seen this already, but there is documentation about how NetworkTables works also.

One thing that I'm working on at the moment is more realistic physics simulations of the robot via the pyfrc simulator, you may find them useful. I'm hoping to put together a working elevator example that will have 'gravity' and such.
__________________
Maintainer of RobotPy (Python for FRC) & WPILib Contributor
Creator of pyfrc (Robot Simulator + utilities for Python), pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript), and lots more...

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 05-02-2018, 12:22 PM
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 546
slibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond repute
Re: Extending RobotPy/wpilib for a new motor controller

We're working on something very similar, porting WPI Library to work w/the VMX-pi which is a Raspberry Pi HAT that has CAN, lots of IO and a navX-sensor on it. Send me a PM if you want to trade notes.
Reply With Quote
  #9   Spotlight this post!  
Unread 05-16-2018, 02:03 PM
cpeppler cpeppler is offline
Registered User
AKA: Charlie Peppler
FRC #5459 (Tigers)
Team Role: Mentor
 
Join Date: Mar 2018
Rookie Year: 2017
Location: South Hamiltion, MA
Posts: 16
cpeppler is an unknown quantity at this point
Re: Extending RobotPy/wpilib for a new motor controller

Quote:
Originally Posted by slibert View Post
We're working on something very similar, porting WPI Library to work w/the VMX-pi which is a Raspberry Pi HAT that has CAN, lots of IO and a navX-sensor on it. Send me a PM if you want to trade notes.
I have been thinking about getting the VMX-pi for weeks now. I wanted to do a summer project that would be fun for new students coming up from the Lego world (*cough* and for me *cough*).

I realize I needed to upgrade the mechanicals (I'm using legacy Legos now), and didn't want to spend a lot of money. I started thinking about the low cost Radio Control (RC) world. I ended up ordering a VMX-pi from Kauai labs, and a $40 RC 4WD rock climber from Amazon.

My goal will be to blend the two. Because the 4WD can go outside, it should be able to exercise all the navigational and IMU capabilities of the VMX-pi.

One of the tricks will be to bring a mobile Wifi hotspot outdoors under battery power, so the driver can use networktables instead of RC.

I'm assuming it should not be hard to retrofit the wiring for the steering servo and the speed control for the (I'm assuming) DC motors for the drive. I'll need to modify the body to be able to hold the electronics and camera (could be a good Solidworks/3d printing project for a student). The offroader already has a spring suspension, so much of the shock/vibration _should_ be dampened, but we may have to add some additional dampening for the electronics enclosure (or drive slowly ;-).

I should end up with a low cost mobile platform to which I can add additional sensors, and the kids and I should have fun with it.

It'll take me a bit to get all that working, but if I can mesh that with the software work to mesh the VMX pi HAL with with wpilib, pretty much all the skills developed should be transferable to the next FRC season.
Reply With Quote
  #10   Spotlight this post!  
Unread 05-23-2018, 12:14 PM
tcorrigan5 tcorrigan5 is offline
Registered User
AKA: Tom Corrigan
FRC #5878 (Great Lakers)
Team Role: Mentor
 
Join Date: Feb 2017
Rookie Year: 2016
Location: Mackinac Island, MI
Posts: 10
tcorrigan5 is an unknown quantity at this point
Re: Extending RobotPy/wpilib for a new motor controller

What robot bases are people looking at for use with Raspberry Pi? Iím looking at the GoPiGo and the Bogie Runt Rover. What else is worth looking at?
Reply With Quote
  #11   Spotlight this post!  
Unread 05-23-2018, 01:16 PM
cpeppler cpeppler is offline
Registered User
AKA: Charlie Peppler
FRC #5459 (Tigers)
Team Role: Mentor
 
Join Date: Mar 2018
Rookie Year: 2017
Location: South Hamiltion, MA
Posts: 16
cpeppler is an unknown quantity at this point
Re: Extending RobotPy/wpilib for a new motor controller

I ordered a $30 4WD Rock Crawler off of Amazon. My plan is to reverse engineer the motors (DC for drive and servo for steering), and RC receiver, and retrofit them with a VMX-pi, Pi combo.

Pretty low cost, and by inserting the robot control system in between the receiver and the motors (drive and steering), its a great platform for testing out IMU, pitch/roll/yaw (as you crawl over rocks), and in a networked environment, drive it with a base station and networktables. Have some fun with the kids at the same time!
Reply With Quote
  #12   Spotlight this post!  
Unread 05-23-2018, 02:18 PM
Nyxyxylyth Nyxyxylyth is offline
Registered User
AKA: Neal Manson
FRC #1481 (The Riveters)
Team Role: Mentor
 
Join Date: Mar 2013
Rookie Year: 2013
Location: Southfield, MI
Posts: 103
Nyxyxylyth is a splendid one to beholdNyxyxylyth is a splendid one to beholdNyxyxylyth is a splendid one to beholdNyxyxylyth is a splendid one to beholdNyxyxylyth is a splendid one to beholdNyxyxylyth is a splendid one to beholdNyxyxylyth is a splendid one to beholdNyxyxylyth is a splendid one to behold
Re: Extending RobotPy/wpilib for a new motor controller

I'm trying to port WPILib to a BeagleBone Blue, which has nice motor/servo outputs, encoder inputs, and an IMU on board:
https://beagleboard.org/blue

Pretty challenging so far, but I'm enjoying the wild ride.
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 11:08 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi