Vision Based Object Tracker with Pan & Tilt USB Camera
A USB camera mounted on a 2-axis (pan and tilt) servo assembly and connected to the host PC is used to track an object. Vega Aries micro-controller board is used to control the servos of the pan & tilt assembly based on the control signals received from the host PC
Components Used
- Vega Aries v2.0 development board. Alternatively, user may use any Arduino board supported by CASP with little modifications to the target model.
- USB Camera
- SG90 Micro-servo motor x 2
- Pan & Tilt Camera Assembly
- Jumper Wires and suitable USB cables
Introduction
This project demonstrates how to do a visual object tracking with a camera, mounted on a pan & tilt assembly. A USB camera mounted on a 2-axis (pan and tilt) servo assembly and connected to the host PC is used to track an object. A micro-controller board is used to control the servos of the pan & tilt assembly based on the control signals received from the host PC. CASP software is used for complete software implementation on the micro-controller board as well as on the host PC
Quick Start
Step 1. Build the hardware as described in ‘Hardware Development’ section below.
Step 2: Install latest version of CASP along with micro-controller board BSPs from this link: https://aadhuniklabs.com/?page_id=550. Please go through this link: https://aadhuniklabs.com/?page_id=554 for video tutorials on CASP.
Step 3: Download the project from the link. Extract the files and follow the steps mentioned in the ‘Software Development’ section.
Step 4: Some adjustments as described in ‘Adjustments’ section may be required for tuning the software to match your developed hardware.
Step 5: Finally, keyboard and mouse controls if any are described in Control Methodology section.
Step 6: Users are encouraged to modify the model to add new features and to improve the performance. Please write to us at https://aadhuniklabs.com/contact for any queries & suggestions related to this project.
Hardware Development
Vega Aries v2.0 micro-controller board is used to drive the servos. However, any micro-controller board supported by CASP can be used.
A pan & tilt assembly is fitted with two micro-servos. These servos are connected to the PWM pins of the micro-controller board as shown in below Schematics. The micro-controller generates required PWM signals to control these servos.
A USB camera connected to the host PC is used to capture live images and send them to the PC. CASP native model running on the host PC detects the object and outputs suitable control commands to the micro-controller board to control the servos.
Schematics
Software Development
CASP software is used to quickly develop models for micro-controller target and host PC. As such two models are developed to achieve desired objective.
A) Target Model that runs on the micro-controller board consists of
1. Blink logic that indicates the system is running.
2. Digital input block mapped to the on-board push button (BTN0). It is used to manually reset the camera PID controller logic in case the tracking is lost.
3. Pan & Tilt servo blocks are mapped to the pins PWM0 and PWM1 of the micro-controller
4. Serial block along with its associated blocks are used to communicate the above signals to the host PC
Following are the steps to properly program the target board.
1. Connect the target to the host PC via a USB cable.
2. From the host operating system, note the serial port number to which the board is connected to the host PC.
3. Run CASP and load the project ‘target_model’ from the downloaded files.
4. From CASP, open Home->Simulation->Setup Simulation Parameters menu item. Under Target HW->General tabs set ‘Target Hardware Programmer Port’ parameter to the serial port to which the board is connected.
6. Build the model and program the board by clicking on Run button.
B) Native Model that runs on Host PC consists of
1. Camera block that receives live video from the connected USB camera. If multiple cameras are connected, change the camera index parameter of the camera block to select the desired camera.
2. Object tracker block that does the object tracking and outputs the centered X and Y co-ordinates of the tracked object.
3. Image viewer block that displays the captured video, overlapped with a bounding rectangle of the tracked object.
4. Two number of PID controllers and associated blocks to generate required servo angles to rotate the camera so that the tracked object is always at the center of the captured video.
5. GPIO blocks (such as ‘reset’ and ‘servo’ blocks) that maps to the target model via the serial communication channel.
Following are the steps to run the native model on the host PC
1. With the target board connected to the host PC open another instance of CASP and load the ‘native_model’ project from the extracted files.
2. Click on Home->Simulation->Configure Simulation IO menu item.
3. ‘Configure Simulation Hardware’ window will open. Under Native Nodes change the serial port to which the micro-controller is connected by double clicking on the serial port item as indicated in below figure.
4. Click on ‘Connect Device’ button and check the ‘Online Data’ check box. The program should now communicate with the target with cycle time around 4msecs. Target board is now available as endpoint ‘EP0’ to the native model. Native model can use this end point to connect to respective IOs on the target.
5. Click on ‘Save’ button to save the configuration and close the window.
6. Run the model by clicking on the Run button. A simulation panel window should open and communicate with the board.
7. Screen shot of the output simulation panel running on host PC is shown below.
Adjustments
None
Control Methodology
Reset button (BTN0) on the target board may be used to reset the tracking in case the object tracking is lost.