Webots Attribute Error while getting the robot references - python

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

Related

Syntax for curl commands in Python

I'm developing Python scripts for the automated grading of assignments using CanvasAPI, an API wrapper in Python for the Canvas learning management platform. In studying the documentation, I can successfully issue curl commands in Python for a few parameters. For example, this conversion below is for grading a single submission:
Curl command per the Canvas API docs:
PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id
with
submission[posted_grade]
Turns into this via the CanvasAPI Python wrapper:
edit(submission={'posted_grade': 'grade'})
Where I'm running into difficulties is the more complex parameter for rubrics. Using the same PUT request as above, the syntax in the documentation is as follows:
rubric_assessment[criterion_id][points]
For which I have:
edit(rubric_assessment[{'id': 'criterion_9980'},{'points', '37'}])
However, I get the following error:
Traceback (most recent call last):
File "C:\Users\danie\AppData\Local\Temp\atom_script_tempfiles\2021528-29488-1eagfyw.k8hw", line 39, in <module>
submission = assignment.get_submission(10370)
File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\site-packages\canvasapi\assignment.py", line 203, in get_submission
response = self._requester.request(
File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\site-packages\canvasapi\requester.py", line 255, in request
raise ResourceDoesNotExist("Not Found")
canvasapi.exceptions.ResourceDoesNotExist: Not Found
I suspect I'm fouling up the syntax somewhere along the line. Any suggestions? All help much appreciated.

Object Leds has no attribute animate_stop (ev3dev2 library)

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()

Python: Why is my Slack-Bot not working in CMD?

I'm trying to code a Slack-Bot which is asking for lunch and is taking orders for lunch.
I'm working with this tutorial.
My problem is: I'm trying to run my script in CMD (yes, windows!) but I receive this error:
C:\Users\Dave\PycharmProjects\lunchbot>python lunchbot.py
Traceback (most recent call last):
File "lunchbot.py", line 167, in <module>
if slack_client.rtm_connect(with_team_state=False):
TypeError: rtm_connect() got an unexpected keyword argument 'with_team_state'
This is the part of the code that's not working correctly:
if __name__ == "__main__":
if slack_client.rtm_connect(with_team_state=False):
print("Lunchbot is ready to go!")
starterbot_id = slack_client.api_call("auth.test")["user_id"]
while True:
command, channel = parse_bot_commands(slack_client.rtm_read())
if command:
handle_command(command, channel)
time.sleep(RTM_READ_DELAY)
else:
print("No connection.")
What actually confuses me is every time I'm trying to run this code in my IDE everything is fine. Does anybody have an idea of what could be wrong?
There is a known issue with the websocket-client and Slack. It's buggy and has been a problem for some time now. I wonder if your Pycharm environment is pointing to a different version and hence why it is working.
I would try to force the value of the websocket-client with a known working version.
websocket-client==0.40.0 for example:

Can't install trigger network automation tools

I read in the howto documentation to install Trigger, but when I test in python environment, I get the error below:
>>> from trigger.netdevices import NetDevices
>>> nd = NetDevices()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 913, in __init__
with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 767, in __init__
production_only=production_only, with_acls=with_acls)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 83, in _populate
# device_data = _munge_source_data(data_source=data_source)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/__init__.py", line 73, in _munge_source_data
# return loader.load_metadata(path, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/trigger/netdevices/loader.py", line 163, in load_metadata
raise RuntimeError('No data loaders succeeded. Tried: %r' % tried)
RuntimeError: No data loaders succeeded. Tried: [<trigger.netdevices.loaders.filesystem.XMLLoader object at 0x7f550a1ed350>, <trigger.netdevices.loaders.filesystem.JSONLoader object at 0x7f550a1ed210>, <trigger.netdevices.loaders.filesystem.SQLiteLoader object at 0x7f550a1ed250>, <trigger.netdevices.loaders.filesystem.CSVLoader object at 0x7f550a1ed290>, <trigger.netdevices.loaders.filesystem.RancidLoader object at 0x7f550a1ed550>]
Does anyone have some idea how to fix it?
The NetDevices constructor is apparently trying to find a "metadata source" that isn't there.
Firstly, you need to define the metadata. Second, your code should handle the exception where none is found.
I'm the lead developer of Trigger. Check out the the doc Working with NetDevices. It is probably what you were missing. We've done some work recently to improve the quality of the setup/install docs, and I hope that this is more clear now!
If you want to get started super quickly, you can feed Trigger a CSV-formatted NetDevices file, like so:
test1-abc.net.example.com,juniper
test2-abc.net.example.com,cisco
Just put that in a file, e.g. /tmp/netdevices.csv and then set the NETDEVICES_SOURCE environment variable:
export NETDEVICES_SOURCE=/tmp/netdevices.csv
And then fire up python and continue on with your examples and you should be good to go!
I found that the default of /etc/trigger/netdevices.xml wasn't listed in the setup instructions. It did indicate to copy from the trigger source folder:
cp conf/netdevices.json /etc/trigger/netdevices.json
But, I didn't see how to specify this instead of the default NETDEVICES_SOURCE on the installation page. But, as soon as I had a file that NETDEVICES_SOURCE pointed to in my /etc/trigger folder, it worked.
I recommend this to get the verifying functionality examples to work right away with minimal fuss:
cp conf/netdevices.xml /etc/trigger/netdevices.xml
Using Ubuntu 14.04 with Python 2.7.3

NuPIC one_hot_gym tutorial swarm attribute error

I'm trying to follow the tutorial at:
https://github.com/numenta/nupic/tree/master/examples/opf/clients/hotgym/prediction/one_gym
I'm right at the beginning but running the very first python script gave me an error:
Traceback (most recent call last):
File "swarm.py", line 105, in <module>
swarm(INPUT_FILE)
File "swarm.py", line 97, in swarm
modelParams = swarmForBestModelParams(SWARM_DESCRIPTION, name)
File "swarm.py", line 68, in swarmForBestModelParams
modelParams = permutations_runner.runWithConfig(
AttributeError: 'module' object has no attribute 'runWithConfig'
So I don't see anyone else complaining about this error so I'm assuming its something I'm doing (or overlooking) can you help me understand whats going on?
The contents of swarm.py are here:
https://github.com/numenta/nupic/blob/master/examples/opf/clients/hotgym/prediction/one_gym/swarm.py
I imagine you probably cloned NuPIC before you watched and ran the tutorial. The tutorial requires you to have the latest codebase. Pull the latest from master, rebuild NuPIC and try it again.
Even if you've updated the codebase and you can see the runWithConfig function, you will still need to re-run the build process as described in the README.md.

Categories