|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
Re: Python: button no attribute to 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
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
Quote:
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. |
|
#5
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
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.
|
|
#6
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
Quote:
Code:
Robot Drive... Output not updated often enough. |
|
#7
|
||||
|
||||
|
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) Code:
self.robot_drive.setSafetyEnabled(False) Code:
self.teleopPeriodic() Code:
wpilib.Timer.delay(.01) |
|
#8
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
Quote:
|
|
#9
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
When you say 'rejects the code', what do you mean? Is there an error message, or some other indicator that is telling you this?
|
|
#10
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
The Robot code indicator is red on the Driver Station and there is no errors that show up.
|
|
#11
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
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
|
|
#12
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
Quote:
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. |
|
#13
|
||||
|
||||
|
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. |
|
#14
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
Quote:
Code:
TypeError: unorderable types: complex() > float() |
|
#15
|
||||
|
||||
|
Re: Python: button no attribute to wpilib ?
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?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|