First of all I want to sorry for my bad English.
I'm trying to use the ev3dev2 library and Visual Studio Code to add python code to my ev3 robot. My problem is that when I try to use the function 'animate_stop' (or 'animate_flash', 'reset', and some others) from the class 'Leds' I get an error saying that the called function isn't an attribute of the object 'Leds' but when I opened the 'led.py' file (which contains the 'Leds' class) I found all the functions that I tried to call.
I have installed ev3dev2 from github and the official SD card image file for the ev3 from its site.
The code:
#!/usr/bin/env pybricks-micropython
from ev3dev2.led import Leds
Leds().animate_stop
The error:
Traceback (most recent call last):
File "/home/robot/ttt/main.py", line 5, in <module>
AttributeError: 'Leds' object has no attribute 'animate_stop'
Try this:
#!/usr/bin/env pybricks-micropython
from ev3dev2.led import Leds
leds = Leds()
leds.all_off()
Related
I am coding a program which uses a Keras model downloaded from Internet (not my own) to recognize hand movements. It's working very well on my laptop, and I have absolutely 0 issue. However, I tried running the same program on my desktop PC, using the exact same Python version (Python 3.8) and with the same Python modules installed, and it crashed. Here's the error message I get :
Traceback (most recent call last):
File "C:/Users/user/GitHub_Repos/H22-GR10-ReconnaissanceMouvement/Main.py", line 41, in <module>
frame= calculsEtAnalyse(frame, listeMarqueurs)
File "C:/Users/user/GitHub_Repos/H22-GR10-ReconnaissanceMouvement/Main.py", line 32, in calculsEtAnalyse
handProcessor.predictionGeste(listeMarqueurs)
File "C:\Users\user\GitHub_Repos\H22-GR10-ReconnaissanceMouvement\HandTracker.py", line 46, in predictionGeste
prediction = handGestureModel.predict([listeMarqueurs])
AttributeError: '_UserObject' object has no attribute 'predict'
[ WARN:0#16.459] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
It seems to indicate that my handGestureModel object doesn't have the .predict command. Here's the "problematic" code :
handGestureModel = load_model('hand_gesture_dataset')
def predictionGeste(self, listeMarqueurs):
prediction = handGestureModel.predict([listeMarqueurs])
IDGeste = np.argmax(prediction)
nomGeste = handGestureNames[IDGeste]
if(nomGeste != self.pastNomGeste):
print(nomGeste)
self.pastNomGeste = nomGeste
I'm not quite sure what to do because, as I've mentionned, this exact same code works flawlessly on my laptop, with the same Python version and the same modules installed. I even re-cloned my GitHub backup to make sure I hadn't broken something on my desktop.
I would like to reproduce the following tutorial, but when I tried to get the robot references theres always this Error:
"AttributeError: 'CartpoleRobot' object has no attribute 'getSelf'"
I rebuild this Tutorial: https://github.com/aidudezzz/deepbots-tutorials/blob/master/robotSupervisorSchemeTutorial/README.md
In other controllers I get similar error messages when I try to get the robot references. I think the error is in the communication between the robot simulation and the controller.
I have tried importing the supervisor and getting the functions via supervisor.get. But here comes another error: "Only one instance of the Robot class should be created"
However, I am new to webots and robotics/informatics in general. Any help would be greatly appreciated!
The whole Error with Traceback:
INFO: robotSupervisorController: Starting controller: python.exe -u robotSupervisorController.py
Traceback (most recent call last):
File "D:\Webots Projekte\controllers\robotSupervisorController\robotSupervisorController.py", line 88, in <module>
env = CartpoleRobot()
File "D:\Webots Projekte\controllers\robotSupervisorController\robotSupervisorController.py", line 16, in __init__
self.robot = self.getSelf() # Grab the robot reference from the supervisor to access various robot methods
AttributeError: 'CartpoleRobot' object has no attribute 'getSelf'
WARNING: 'robotSupervisorController' Controller beendet mit Status: 1
The Code is the same than shown in the Tutorial.
The short section that generates the error:
self.robot = self.getSelf() # Grab the robot reference from the supervisor to access various robot methods
self.positionSensor = self.getDevice("polePosSensor")
self.positionSensor.enable(self.timestep)
If I comment out the first one, the next line returns a similar error
Every answer is highly appreciated! Thanks!
I had the same issue. I use the deepbots-0.1.2 and webotsR2021a.
Try to uninstall the deepbots and then install them using the:
pip install -i https://test.pypi.org/simple/ deepbots
I am trying to open a device file in windows using python. I heard I needed to use win32 API. So I am using that, to open my file I need to perform the following this stackoverflow question : Opening a handle to a device in Python on Windows
import win32file as w32
self.receiver_handle = w32.CreateFile("\\\\.\\xillybus_read_32", # file to open
w32.GENERIC_READ, # desired access
w32.FILE_ATTRIBUTE_READONLY, # shared mode
None, # security attribute
w32.OPEN_EXISTING, # creation distribution
w32.FILE_ATTRIBUTE_READONLY, #flags and attributes
None) # no template file
This results in the handle always returning 0.
Here is the API reference: http://winapi.freetechsecrets.com/win32/WIN32CreateFile.htm
The driver came with a barebones C program to test it and it works flawlessly, so it can't be the driver itself that is not properly working.
What am I doing wrong?
The API should not return zero. It should return a PyHANDLE object. I don't have your device, but opening an existing file works. The 3rd parameter should be w32.FILE_SHARE_READ (or similar share mode value), however:
>>> import win32file as w32
>>> w32.CreateFile('blah.txt',w32.GENERIC_READ,w32.FILE_SHARE_READ,None,w32.OPEN_EXISTING,w32.FILE_ATTRIBUTE_READONLY,None)
<PyHANDLE:280>
If the file does not exist (or any other error), Python should raise an exception based on the GetLastError() code returned by the Win32 API called:
>>> w32.CreateFile('blah.txt',w32.GENERIC_READ,w32.FILE_SHARE_READ,None,w32.OPEN_EXISTING,w32.FILE_ATTRIBUTE_READONLY,None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pywintypes.error: (2, 'CreateFile', 'The system cannot find the file specified.')
If this doesn't help, edit your question to show the exact code you are running and the exact results of running the code.
Keeping it relatively simple. I'm trying to open a fileopenbox to select a file using easygui.
easygui.fileopenbox()
And easyGUI throws this error
'module' object has no attribute 'askopenfilename'
The Stack Trace
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\test.py", line 377, in <module>
easygui.fileopenbox()
File "C:\Python27\lib\site-packages\easygui\boxes\fileopen_box.py", line 103, in fileopenbox
func = ut.tk_FileDialog.askopenfilenames if multiple else ut.tk_FileDialog.askopenfilename
AttributeError: 'module' object has no attribute 'askopenfilename'
Whats going on here?
Nothings changed on my system at all, but it almost looks like for some reason python cant find this tkInter function.
Has anyone come across this?
Thanks!
Edit: An additional screenshot showing that the method is not found
https://gyazo.com/8b9ba0f6c23561d13babe7ce4c8b67a1
Try uninstalling your Easygui and install latest one.
Also try update Python version.
Im working with Agilent IVI drivers in Python 2.7.9 and can't seem to get 'proven' code to work on a particular Windows 7 machine. It executes successfully on other machines.
While this issue seems rather limited to one instrument, it appears to be a broader Python issue, so I turn to Stack Overflow for help. Any help or insight would be great.
The following code
# Import the TLB
from comtypes.client import GetModule, CreateObject
GetModule('AgInfiniium.dll')
# Pull in the coefficients and classes, we'll need those
from comtypes.gen.AgilentInfiniiumLib import *
# Instantiate the driver
OScope = CreateObject('AgilentInfiniium.AgilentInfiniium')
# Make constants of our settings
Address = "TCPIP0::10.254.0.222::INSTR"
resetOScope = False
# Open a connection to the scope
OScope.Initialize(Address,False,resetOScope,'')
# Make a measurement
print OScope.Measurements.Item("Channel1").ReadWaveformMeasurement(
MeasFunction=AgilentInfiniiumMeasurementAmplitude, MaxTime=10)
yields the following error:
Traceback (most recent call last):
File "P:\Aperture\Validation\WMI_BGA_Board\TestMatrixCode\scopeTest2.py", line 29, in <module>
print OScope.Measurements.Item("Channel1").ReadWaveformMeasurement(MeasFunction=AgilentInfiniiumMeasurementAmplitude ,MaxTime=10)
File "C:\Python27\lib\site-packages\comtypes-1.1.0-py2.7.egg\comtypes\__init__.py", line 656, in call_with_inout
rescode = list(rescode)
TypeError: 'c_double' object is not iterable
In my limited debugging attempts, I have seen that this call_with_inout
function tries to convert my Python arguments into arguments for the following C++ function:
public void ReadWaveformMeasurement(
AgilentInfiniiumMeasurementEnum MeasFunction,
AgilentInfiniiumTimeOutEnum MaxTime,
ref double pMeasurement)
It's creating some kind of variable for the pMeasurement pointer that ends up being type c_double, and then complains that it's not iterable.
At this point, this seems like it's local to this machine. I've gone to the extent of uninstalling Python, reinstalling the Agilent driver, and trying two versions of comtypes (1.1.0 and 1.1.1). Yet the problem persists. Any ideas? Thanks.