Go to Post CIMs are NEAR indestructible and I <3 them for it. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-01-2015, 17:05
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Python: button no attribute to wpilib ?

Hi! We are trying to use a joystick button with wpilib.buttons.JoystickButton but we keep getting a "buttons has no attribute to wpilib". We really need help on this because we would love to use pneumatics. We are using python and robotpy. Any help would be greatly appreciated!
  #2   Spotlight this post!  
Unread 21-01-2015, 17:14
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,102
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: Python: button no attribute to wpilib ?

You don't actually need to use the JoystickButton object, you can just use joystick.getRawButton() or joystick.getTrigger(), etc.

Otherwise, make sure you import wpilib.buttons, not just import 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
  #3   Spotlight this post!  
Unread 21-01-2015, 18:03
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by virtuald View Post
You don't actually need to use the JoystickButton object, you can just use joystick.getRawButton() or joystick.getTrigger(), etc.

Otherwise, make sure you import wpilib.buttons, not just import wpilib.
For some really annoying reason, I can't have an "If" statement in my code or the Driver Station will not recognize the code. I tried --nc and it shows nothing. Thanks!
  #4   Spotlight this post!  
Unread 21-01-2015, 18:29
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by team-4480 View Post
For some really annoying reason, I can't have an "If" statement in my code or the Driver Station will not recognize the code. I tried --nc and it shows nothing. Thanks!
Are you typing 'If'? Make sure it's lowercase.
if xyz:
blah blah blah
And it might be helpful to put your code in pastebin and share a link so we can take a look at it.
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #5   Spotlight this post!  
Unread 21-01-2015, 18:31
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,102
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: Python: button no attribute to wpilib ?

Quote:
Originally Posted by team-4480 View Post
For some really annoying reason, I can't have an "If" statement in my code or the Driver Station will not recognize the code. I tried --nc and it shows nothing. Thanks!
Highly recommend using the pyfrc simulator then. It will help you find any logical issues with your code. If it runs in the simulator, it has a high chance of running on your robot.
__________________
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
  #6   Spotlight this post!  
Unread 21-01-2015, 18:59
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by virtuald View Post
Highly recommend using the pyfrc simulator then. It will help you find any logical issues with your code. If it runs in the simulator, it has a high chance of running on your robot.
With this code: http://pastebin.com/DRa0hbVy I get this error in the sim
Code:
Robot Drive... Output not updated often enough.
I don't think that would stop the code from being recognized though. Thanks!
  #7   Spotlight this post!  
Unread 21-01-2015, 19:46
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: Python: button no attribute to wpilib ?

So I ran your code and noticed that the error was wpilib.motorsafety... to fix this, under
Code:
self.robot_drive=wpilib.RobotDrive(self.motor1,self.motor2)
insert
Code:
self.robot_drive.setSafetyEnabled(False)
Also, no need for
Code:
self.teleopPeriodic()
. I think Peter Johnson mentioned this. Wpilib will call it on its own. And keep the while loop in teleop, and add
Code:
wpilib.Timer.delay(.01)
inside the loop.
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #8   Spotlight this post!  
Unread 21-01-2015, 23:07
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by TimTheGreat View Post
So I ran your code and noticed that the error was wpilib.motorsafety... to fix this, under
Code:
self.robot_drive=wpilib.RobotDrive(self.motor1,self.motor2)
insert
Code:
self.robot_drive.setSafetyEnabled(False)
Also, no need for
Code:
self.teleopPeriodic()
. I think Peter Johnson mentioned this. Wpilib will call it on its own. And keep the while loop in teleop, and add
Code:
wpilib.Timer.delay(.01)
inside the loop.
So that would be why the Driver Station rejects the code? Thanks a bunch and I will try that tomorrow!!
  #9   Spotlight this post!  
Unread 22-01-2015, 01:28
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,102
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: Python: button no attribute to wpilib ?

Quote:
Originally Posted by team-4480 View Post
So that would be why the Driver Station rejects the code? Thanks a bunch and I will try that tomorrow!!
When you say 'rejects the code', what do you mean? Is there an error message, or some other indicator that is telling you this?
__________________
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
  #10   Spotlight this post!  
Unread 22-01-2015, 09:15
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by virtuald View Post
When you say 'rejects the code', what do you mean? Is there an error message, or some other indicator that is telling you this?
The Robot code indicator is red on the Driver Station and there is no errors that show up.
  #11   Spotlight this post!  
Unread 22-01-2015, 09:31
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by team-4480 View Post
The Robot code indicator is red on the Driver Station and there is no errors that show up.
So that's not the driver station rejecting the code, its the code on the robot breaking. Adding the safety code line should prevent this, and to test just run it in the simulator
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #12   Spotlight this post!  
Unread 22-01-2015, 11:38
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,102
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: Python: button no attribute to wpilib ?

Quote:
Originally Posted by TimTheGreat View Post
So that's not the driver station rejecting the code, its the code on the robot breaking. Adding the safety code line should prevent this, and to test just run it in the simulator
No, do NOT disable the motor safety error. In previous years, the motor safety stuff didn't always work as well as we would have liked previously, but this year it should work without any problems. If one is getting the motor safety error, that means that you aren't feeding the motors often enough.

Looking at the code which was pasted the robot drive motor call is commented out, so it's not feeding it at all -- which means the error message is correct. Once you uncomment it out, the error message goes away.

Additionally, since the OP is using IterativeRobot, no Timer.delay call is required.

I modified your code slightly, and http://pastebin.com/CLDhyuc5 works for me without any problems in the simulator. You'll note that I changed 'aracadeDrive' to 'arcadeDrive', which could be what caused your robot to crash. I don't have access to a robot to run it on.

Also, you don't need the from __future__ import division at the top, that is only needed for python 2.
__________________
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
  #13   Spotlight this post!  
Unread 22-01-2015, 11:42
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,102
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: Python: button no attribute to wpilib ?

Also, looking further, your controller adjustment code is wrong. The values returned from the joystick are in the range [-1, 1], so you don't need to divide by 255.

Additionally, you shouldn't have the 'else: pass' at the end of your statement. If you ever hit that condition, then x1 won't be set, and your code will die with an exception. It should be 'else: x1=??', where ?? is the default value (probably 0?).

Looking around CD, you'll see that most people adjust the joystick curve by squaring the inputs instead of a sequence of if statements as you have there.
__________________
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
  #14   Spotlight this post!  
Unread 22-01-2015, 15:51
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by virtuald View Post
Also, looking further, your controller adjustment code is wrong. The values returned from the joystick are in the range [-1, 1], so you don't need to divide by 255.

Additionally, you shouldn't have the 'else: pass' at the end of your statement. If you ever hit that condition, then x1 won't be set, and your code will die with an exception. It should be 'else: x1=??', where ?? is the default value (probably 0?).

Looking around CD, you'll see that most people adjust the joystick curve by squaring the inputs instead of a sequence of if statements as you have there.
Thanks with your help, we got our buttons to work! When I am using cmath for square root of the getX and getY, I get a...
Code:
TypeError: unorderable types: complex() > float()
Again, I can not thank you enough for your help!
  #15   Spotlight this post!  
Unread 24-01-2015, 00:24
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: Python: button no attribute to wpilib ?

Quote:
Originally Posted by team-4480 View Post
When I am using cmath for square root of the getX and getY, I get a...
Code:
TypeError: unorderable types: complex() > float()
Well the joystick ranges are -1:1, and if you take the square root of -1 you get a complex number (i). What are you using the square root for?
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
Closed Thread


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 02:50.

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