Go to Post Things that get said on the field should stay on the field. - Bongle [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, 19:24
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is offline
Not Allowed Near Power Tools
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 149
nickbrickmaster is an unknown quantity at this point
I2C Error on read() or write()

I'm trying to use the ITG3200 gyro on the AndyMark breakout board (am-2314). I translated some code I found from Java to Python, which you can find on PasteBin below, along with the original.

I'm getting the below error when both using my custom ITG3200 class and the ADXL345_I2C class.

Code:
Traceback (most recent call last):
  File "/home/lvuser/py/robot.py", line 268, in <module>
    wpilib.run(MyRobot)
  File "/usr/local/lib/python3.5/site-packages/wpilib/_impl/main.py", line 101, in run
    retval = options.cmdobj.run(options, robot_class, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/hal/main.py", line 11, in run
    return robot_class.main(robot_class)
  File "/usr/local/lib/python3.5/site-packages/wpilib/robotbase.py", line 178, in main
    robot.startCompetition()
  File "/usr/local/lib/python3.5/site-packages/wpilib/iterativerobot.py", line 78, in startCompetition
    self.robotInit()
  File "/home/lvuser/py/robot.py", line 252, in robotInit
    self.subsystems['drive'] = DriveSubsystem()
  File "/home/lvuser/py/robot.py", line 39, in __init__
    self.gyro.init()
  File "/home/lvuser/py/ITG3200.py", line 142, in init
    if not self.testConnection():
  File "/home/lvuser/py/ITG3200.py", line 236, in testConnection
    return self.getDeviceID() == 0b110100
  File "/home/lvuser/py/ITG3200.py", line 246, in getDeviceID
    return self.getRegisterBits(RA_WHO_AM_I, DEVID_BIT, DEVID_LENGTH)
  File "/home/lvuser/py/ITG3200.py", line 268, in getRegisterBits
    containingByte = self.getRegisterByte(register)
  File "/home/lvuser/py/ITG3200.py", line 265, in getRegisterByte
    return self.readI2C(register, 1)[0]
  File "/home/lvuser/py/ITG3200.py", line 83, in readI2C
    return self.i2c.read(register, count)
  File "/usr/local/lib/python3.5/site-packages/wpilib/i2c.py", line 145, in read
    return self.transaction([registerAddress], count)
  File "/usr/local/lib/python3.5/site-packages/wpilib/i2c.py", line 84, in transaction
    dataToSend, receiveSize)
  File "/usr/local/lib/python3.5/site-packages/hal/functions.py", line 407, in i2CTransaction
    raise IOError(_os.strerror(C.get_errno()))
OSError: Success
The gyro works in Java using the original, but I find it strange that the accelerometer produces the same error. I've verified the addresses and the other numbers.

My translated code:
http://pastebin.com/CKr5prZs

Original:
https://github.com/bussell/SparkFun6...roITG3200.java

RobotPy is 2016.2.0 on robot and driver station.
Is this a bug in robotpy or am I messing up somewhere?

Thanks for the help.
__________________
I have approximate knowledge of many things.

FRC 3184: 2014-, FTC 10648: 2015-
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2016, 00:48
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,040
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: I2C Error on read() or write()

Quote:
Originally Posted by nickbrickmaster View Post
RobotPy is 2016.2.0 on robot and driver station.
Is this a bug in robotpy or am I messing up somewhere?

Thanks for the help.
It very well could be a bug in RobotPy, the i2c interface isn't particularly well tested -- though, I was able to talk to the NavX device via I2C without any issues.

What value are you passing in for 'port' to the I2C constructor? I ask because I see that in HAL it checks to see if port < 0, and returns -1 if so -- which wouldn't set errno (and perhaps why you're seeing the 'success' message). I'll add a check for that so it can't happen in the future...

This error also reminds me of this bug that someone reported for WPILib.
__________________
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 12-02-2016, 00:56
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,040
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: I2C Error on read() or write()

Also, once this works, it'd make for a nice pull request to robotpy-wpilib-utilities. Just saying.
__________________
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 12-02-2016, 01: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,040
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: I2C Error on read() or write()

Another thought. The java I2C function does not throw if there's an error, it just returns true. Can you add some error checking to the java code (maybe throw an exception if it returns false from i2c.read?), rerun it, and see if you get an error?
__________________
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 12-02-2016, 08:11
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is offline
Not Allowed Near Power Tools
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 149
nickbrickmaster is an unknown quantity at this point
Re: I2C Error on read() or write()

Thanks for the suggestions. The port is I2C.Port.kOnboard. I don't have access to the robot at the moment, but I'll test the Java code later.
__________________
I have approximate knowledge of many things.

FRC 3184: 2014-, FTC 10648: 2015-
Reply With Quote
  #6   Spotlight this post!  
Unread 12-02-2016, 21:36
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is offline
Not Allowed Near Power Tools
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 149
nickbrickmaster is an unknown quantity at this point
Re: I2C Error on read() or write()

Thanks for the help. Turns out that I had connected the board incorrectly, and that the data I was getting from Java was random noise, which I did not get in Python because I never ran initialize() in Java.

Again, thanks for the help. I got the gyro working. It still throws an error every once in a while (but good data otherwise), which the code catches and replaces with an array of zeroes. I'd like a better solution, and to get to the bottom of the I2C errors, but that is a project for later. I'll definitely add it to robotpy-wpilib-utilities once decoding and calibration is all figured out.
__________________
I have approximate knowledge of many things.

FRC 3184: 2014-, FTC 10648: 2015-
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 19:52.

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