Repository navigation
Object tracking with NXT Cam V4 for LEGO Mindstorms #792
Description
Activity
Pybricks is not the same as ev3dev-lang-python. You can't use both at the same time. To use ev3dev-lang-python, change the shebang to
#!/usr/bin/env python3and replace all of the Pybricks code with the ev3dev-lang-python equivalent.from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4 from ev3dev2.sensor.lego import TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor from ev3dev2.motor import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, LargeMotor, MediumMotor from ev3dev2.sound import Sound from ev3dev2.display import Display from time import sleep
do you mean like this?
Yes, that looks right.
I gave it another try with your correction, now it shows ImportError: cannot import name 'I2C'.
Where did you get the code? There is no
I2Cclass. Maybe you meantI2CSensor?My main problem is that I am struggling to set up a communication with NXT cam since there is only poor information on the internet.
Now I tried this code:#!/usr/bin/env python3 from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4 from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D from ev3dev2.port import LegoPort from time import sleep i= 1 from smbus import SMBus bus = SMBus(4) # NXTCam-v5 plugged into input port 2, /dev/i2c-in2 -> i2c-4 address = 0x01 bus.write_byte_data(address, 0x41, 0x42) # set object tracking mode num = bus.read_byte_data(address, 0x42) # get number of tracked objects data = bus.read_i2c_block_data(address, 0x43 + i * 5, 5) print("color: ", data[0]) print("x coordinate upper left corner: ", data[1]) print("y coordinate upper left corner: ", data[2]) print("x coordinate lower right corner: ", data[3]) print("x coordinate lower right corner: ", data[4])
But it shows up the following error:
Traceback (most recent call last): File "/home/robot/anothercamtest/main.py", line 13, in <module> bus.write_byte_data(address, 0x41, 0x42) # set object tracking mode OSError: [Errno 16] Device or resource busy ---------- Exited with error code 1.To be able to use SMBus with an I2C sensor, you must set the mode of the port to "i2c-other" first.
I am just trying to realize a simple program where for example a motor is being moved, when the teached object is detected by the camera. Just to check if the camera is even working. I didn't find any information do you maybe experimented with the camera?
Hello,
I am trying to program an object tracking robot with lego mindstorms using the python language. However I am not able to communicate with the NXT cam.
I tried this code but it keeps bringing up the error : no module named 'ev3dev2'