ut-robotics / picr21-team-sauna-madis

0 stars 0 forks source link

State handlers are called on each iteration #38

Closed ReikoR closed 2 years ago

ReikoR commented 2 years ago

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/1f4b77ebae64bb29882fd5f36271e09f96811f76/saun/main.py#L159-L163

It would probably be better to have enum for game state and call state handlers based on the enum value.

Other option is to have some variable for active state handler:

active_state_handler = find_ball;

while move_style == MoveStyle.AUTO: 
    active_state_handler()

Also get_ball_cord is called multiple times during each iteration. This can't be good for performance.

image

ReikoR commented 2 years ago

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/cd3e4fc09a54c9e9432e90c289784c3d13cb4e2a/saun/main.py#L120-L139

get_ball_cord/get_basket_cord/get_ballNbasket_cord should be called only once per game state iteration as calling it will cause to wait for new camera frames and different frames contain different information.

uschults commented 2 years ago

It is called once per while loop, which is one game state iteration. The first get_ball_cord() is to make sure the ball is still in view and can go into the while loop to rotate around the ball.

Akustav commented 2 years ago

I think what Reiko tries to say is that all the check methods use this method under the hood:

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/a80c9164e964e816dcf8a4658698719917ffa470/saun/image.py#L61

This method executes: https://github.com/ut-robotics/picr21-team-sauna-madis/blob/a80c9164e964e816dcf8a4658698719917ffa470/saun/image.py#L73

And as the name implies, it waits for a new frame. So if you use get_ball_cord() and get_ballNbasket_cord(), it uses 3 separate framers, so instead of 60 fps, you get 20. You should fetch the frame once, and then process the data of that frame, not get a fresh frame every time.

uschults commented 2 years ago

now uses one frame for both.