Thread: Usb camera
View Single Post
  #1   Spotlight this post!  
Unread 06-03-2016, 23:18
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 361
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Usb camera

The quick and easy way to align is to just turn until the target is in the center of the frame.
I'm not familiar with GRIP, but there should be a function that gives you the center of the object you are looking at.
Initially we tried using PID for alignment but the inherent issues with our robot's large drive dead zone and the lag in vision processing drove us to ditch pid and do our own two-phase constant rate turn.
First, we turn quickly until the target is within 20% around the center. Then, we turn slowly until we just pass the target and immediately stop there. This results in pretty decent alignment.

Here's some psuedocode for you
Code:
slow_zone = 0.2
slow_speed = 0.5
fast_speed = 1
repeat until (error = abs(target_center - image_width / 2)) < acceptable_error
  sign = target_center > image_width / 2 ? -1 : 1 // which direction to turn
  if error < slow_zone
    arcadedrive(0, slow_speed * sign)
  else
    arcadedrive(0, fast_speed * sign)
end
Good luck implementing this!
Reply With Quote