My Problem:
When I started the modified Script (appended at the End) of the “Stay on table”-Bot with the NXT-Sensor instead of the EV3-Sensor, I get the following Error:
%Run StayOnTable_Ehr.py
Start
Traceback (most recent call last):
File “/home/pi/Ae/Roboter/Modelle/13_StayOnTable/StayOnTable_Ehr.py”, line 75, in
dist = us.getDistance()
File “/home/pi/Ae/Roboter/Interface/NXTUltrasonicSensor.py”, line 74, in getDistance
return BP.get_sensor(self.port)
File “/usr/local/lib/python3.5/dist-packages/brickpi3-0.0.0-py3.5.egg/brickpi3.py”, line 707, in get_sensor
raise SensorError(“get_sensor error: Invalid sensor data”)
brickpi3.SensorError: get_sensor error: Invalid sensor data
What is wrong?
Where can I find the other Classes for the older Sensors?
The words change their character based on the “characters” surrounding them.
Things like asterisks, (*), hash marks, (#), and others can be “magic” and cause the formatting to change.
If you want to create a “block of unformatted text”, sometimes called a “code block”, you start it with three back-ticks, (```), on a line by themselves, and then add three more after the last line in your code block.
Let me snip your text and see what I can do with it:
I put three back-ticks before the “#!/usr/bin/python” part, and three more back-ticks on the line directly after the “brickpi3.SensorError: get_sensor error: Invalid sensor data” line.
Another formatting tip:
If you want to use a “magical” character, (things like “#”, “&”, “*”, “`”, (or others I don’t remember), as actual printable characters you must “escape” them with the “backslash” (\). In order to show the backslash, I have to type it twice (\\) so that it “escapes” itself and is shown.
So, now let’s look at that code. . .
#!/usr/bin/python
class lego infrared sensor
file: LegoInfraRedSensor.py
Author: Th. Kaffka, Cologne, Germany
Date: 21.10.2020
modifiziert von Andreas Ehrhard
11.07.2023
import brickpi3
BP = brickpi3.BrickPi3()
class NXTUltrasonicSensor:
def init(self, port):
self.port = port
BP.set_sensor_type(port, BP.SENSOR_TYPE.NXT_ULTRASONIC)
def del(self):
pass
def getPort(self):
return self.port
def getDistance(self):
return BP.get_sensor(self.port)
Which seems to result in:
%Run StayOnTable_Ehr.py
Start
Traceback (most recent call last):
File “/home/pi/Ae/Roboter/Modelle/13_StayOnTable/StayOnTable_Ehr.py”, line 75, in
dist = us.getDistance()
File “/home/pi/Ae/Roboter/Interface/NXTUltrasonicSensor.py”, line 74, in getDistance
return BP.get_sensor(self.port)
File “/usr/local/lib/python3.5/dist-packages/brickpi3-0.0.0-py3.5.egg/brickpi3.py”, line 707, in get_sensor
raise SensorError(“get_sensor error: Invalid sensor data”)
brickpi3.SensorError: get_sensor error: Invalid sensor data
Thank you for the answer!
I try to be more exactly:
It would be wonderful to use all the NXT-sensors and motors with the BrickPi3.
It is important, because I have 15 old NXT-Sets at my school. Most of the Controller are brokenand I wanna use it sustainable with python instead of throwing them away.
It is a school-Project. I’m an Informatik-Teacher and want to show how to use the old NXT-Hardware instead of throwing it away.
All I need is a Class for each Sensortype of the NXT-Education-Set.
On your homepage (see How To Program the LEGO Robot BrickPi3 in Python Programming Language) is written, that the NXT-Sensor are supported. That was one of the reasons to buy som BrickPi (3 at the moment) to test it.