Hello,
I am using ‘openmv cam m7’ at motion detection project. I have to send data with CANBUS to other nodes. But I have getting some error. CAn you help me with this?
# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import sensor, image, os, time, pyb
from pyb import UART, CAN
TRIGGER_THRESOLD = 5
p_x = 320
p_y = 240
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.set_windowing((p_x, p_y))
sensor.skip_frames(time = 2000) # Wait for settings take effect.
sensor.set_auto_whitebal(False)
clock = time.clock() # Create a clock object to track the FPS.
#canbus communication config
can = pyb.CAN(2, CAN.NORMAL)
can.init(pyb.CAN.NORMAL, extframe=False, prescaler=18, sjw=1, bs1=8, bs2=3) #250kb/s
# APB1 = 54MHz, Prescaler 18 et 250kB/s --> 12 time quanta par bit (1 + 8 + 3 = 12)
#uart communication config
uart = UART(1)
uart.init(1152000, bits=8, parity=None, stop=1, timeout=1000, flow=0, timeout_char=0, read_buf_len=64)
#bacground image take and save to sdcard
if not "temp" in os.listdir(): os.mkdir("temp")
sensor.skip_frames(time = 2000)
bgImage = sensor.snapshot() #.save("temp/bg.bmp")
#bgImage.save("temp/bg.bmp")
while(True):
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
img.difference("temp/bg.bmp")
hist = img.get_histogram()
diff = hist.get_percentile(0.99).l_value() - hist.get_percentile(0.90).l_value()
triggered = diff > TRIGGER_THRESOLD
print(clock.fps(), triggered) # Note: OpenMV Cam runs about half as fast when connected
# to the IDE. The FPS should increase once disconnected.