limit fps

Discussion related to "under the hood" OpenMV topics.
Mura
Posts: 4
Joined: Thu Oct 10, 2019 7:39 am

limit fps

Postby Mura » Thu Oct 10, 2019 8:06 am

Hi!
If I run the following program, there will be a 1 second lag in servo startup after receiving data.
So I would like to lack the limit on the fps output to the screen. please tell me. Thank you.

Code: Select all

import time,pyb,sensor,image,micropython
from pyb import Pin,UART,Timer,Servo
from servo import Servos
from machine import I2C
sensor.reset()                      
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QVGA)  
sensor.skip_frames(time=4000)    
clock = time.clock()                
####################################################################################################
MotorA=Pin('P1',Pin.OUT_PP,Pin.PULL_NONE)
MotorB=Pin('P2',Pin.OUT_PP,Pin.PULL_NONE)
i2c = I2C(sda=Pin('P5'), scl=Pin('P4'))
servo = Servos(i2c, address=0x40, freq=50, min_us=250, max_us=2800, degrees=180)
uart = UART(1, 115200, timeout=5)
####################################################################################################
#tim = Timer(1, freq=50)
#ch1 = tim.channel(1,Timer.PWM,pin=Pin("P7"),pulse_width_percent=1)
####################################################################################################
x=90
y=90


while(True):
    img =  sensor.snapshot()
    print(clock.fps())
    servo.position(7,x)
    servo.position(6,y)
    Data=0;
    Data=uart.readchar()
    if(Data!=0):
      if(Data==1):
        x+=1
      elif(Data==2):
        x-=1
      elif(Data==3):
        y+=1
      elif(Data==4):
        y-=1
      elif(Data==5):
        x=90
        y=90
        MotorA.value(True)
        MotorB.value(False)
      elif(Data==6):
        x=90
        y=90
        MotorA.value(False)
        MotorB.value(True)
    else:
      x=75
      y=90
Attachments
servo_1.py
(1.16 KiB) Downloaded 2 times
pca9685_1.py
(1.91 KiB) Downloaded 2 times
camera_main.py
(1.91 KiB) Downloaded 2 times
User avatar
kwagyeman
Posts: 3335
Joined: Sun May 24, 2015 2:10 pm

Re: limit fps

Postby kwagyeman » Thu Oct 10, 2019 11:08 am

I don't understand "lack the limit on the fps output to the screen". Can you elaborate?
Nyamekye,
Mura
Posts: 4
Joined: Thu Oct 10, 2019 7:39 am

Re: limit fps

Postby Mura » Thu Oct 10, 2019 11:30 am

Well.
I want to receive data from Arduino and control the servo motor with that data while outputting video on my PC.
However, with the current program, there is a 1 second lag when moving the servo motor after receiving data from Arduino.
So,I want to Reduce processing to CPU.

Sorry for the poor English.I am Japanese and don't understand English well…
User avatar
kwagyeman
Posts: 3335
Joined: Sun May 24, 2015 2:10 pm

Re: limit fps

Postby kwagyeman » Thu Oct 10, 2019 11:35 am

Okay, i don't see anything that would create the lag in the code. Anyway, what do you mean by reduce processing to the CPU? You can add delay methods that make it run slower.
Nyamekye,
Mura
Posts: 4
Joined: Thu Oct 10, 2019 7:39 am

Re: limit fps

Postby Mura » Thu Oct 10, 2019 12:03 pm

I would like to limit the video fps displayed on my computer as a way to reduce the processing to the CPU.
I want to move the servo as soon as communication from Arduino comes.
User avatar
kwagyeman
Posts: 3335
Joined: Sun May 24, 2015 2:10 pm

Re: limit fps

Postby kwagyeman » Thu Oct 10, 2019 2:12 pm

I see, um, there's no way to lower the IDE poll rate except to disable the frame buffer such that it doesn't display anything.

...

You can redo your code loop such that you call snapshot() not each time through the loop. This will reduce the processing on your PC. So, just only call snapshot every 4 times through the loop.
Nyamekye,
Mura
Posts: 4
Joined: Thu Oct 10, 2019 7:39 am

Re: limit fps

Postby Mura » Thu Oct 10, 2019 11:14 pm

OK! Thanks!

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests