I had built a bug robot (V1.0) that is palm size with battery powered. When I want to improve it to be more smart with more AI, I got stucked. I found it hard to fit a big camera with too much power and size and also a burning CPU to process the big images.
Then I met the PAJ6100U6 from Pixart. PAJ6100U6 is comprised of a low-power global shutter QVGA sensor with a 90-degree (diagonal) FOV reflowable optical lens.
- QVGA Global Shutter Sensor
- Ultra low power
- Binning and Skipping modes
- ROI (Region of Interest) functionality
- Designed with reflowable optics
- Highly integrated design
For more details of the camera, please go here.
This means I can have flicker-free images when the bot moves. The battery can work for long time since it is below 1mA. The QVGA can be enough for me.
I will try to use this camera for my new robot, making it smarter!
First step, I will use OpenMV to track the ball and then tell the robot to learn how to chase the ball (via UART)
import sensor, image, time
from pyb import UART
import ustruct
import pyb, time
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 1000)
clock = time.clock()
uart = UART(3, 115200, timeout_char=1000)
led = pyb.LED(3)
#usb = pyb.USB_VCP()
#while (usb.isconnected()==False):
while(True):
clock.tick()
img = sensor.snapshot()#.lens_corr(1.8)
led.off()
#img.gaussian(2
circles = img.find_circles(threshold = 3500, x_margin = 50, y_margin = 50, r_margin = 50,r_min = 10, r_max = 90, r_step = 10)
c_max = None
r_max = 0
for c in circles:
img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
#print(c, c.x(),c.y(),'%d,%d'%(c.x(),c.y()))
if r_max < c.r():
r_max = c.r()
c_max = c
if c_max:
led.on()
print(c_max)
uart.write(ustruct.pack("<hhhh", 0x55AA, c_max.x(), c_max.y(), 0xAA55))
print("FPS %f" % clock.fps())
Step2, I will connect the robot with OpenMV to move with PID control.
void run_with_openmv(pid_t *pid)
{
uint8_t tmp = uart_get();
uint16_t x=160,y;
if (tmp == 0xAA) {
tmp = uart_get();
if(tmp == 0x55) {
uint8_t tm1 = uart_get();
uint8_t tm2 = uart_get();
x = (uint16_t)tm1+(((uint16_t)tm1)<<16);
y = uart_get() + ((uint16_t)uart_get()<<16);
}
}
float next_motor = pid_process(pid, 160, 320-x);
motor_start(SPEED + (int16_t)next_motor, SPEED - (int16_t)next_motor);
}
The code was pushed to openmv branch:https://github.com/nanfang2000/zigbug_fw/tree/openmv
Comments