Moving robot while tracking with camera questions...

I have the camera functioning correctly and have used LabView as well as the RC camera code to have it track properly from good distances so I am ready to move forward but have run into some questions. I have read countless threads here and can’t get to the bottom of these questions…

  1. If I want to use the camera for autonomous mode, do I need to add #include statements in user_routines_fast.c referencing the camera, tracking, eeprom, and terminal c and h files (as in the user_routines.c file)?

  2. In order to drive motors in autonomous, I am guessing that all I need to do is generate code calling on data sent from the camera to control my drive train pwm’s (13 and 15) in the section that says /* Add your own autonomous code here. */ … Is this correct and what exactly are the variables called for blob size, and pan or tilt positions relative to the target? (or do I need to calculate things like blob size as in terminal.c?)

  3. It looks like underneath the camera code in user_routines.c that all of the pwm’s are reset to neutral (127) and should work as the camera is tracking. Yet, I realize for safety, something has been commented in order to keep us from driving the robot as camera is tracking, and that pwm01 should not be used for the camera and the port 1 y-axis. Can you help me get the robot moving via joystick input (while tracking!) by pointing me to the code I need to consider? Should I just comment out pwm 1-3 joystick mapping so I don’t use them for anything but the camera?

  4. Once I get the robot moving via OI input from the joysticks, I kind of need to repeat part of question 1 because I don’t know where to call the variables that have the info I need to aim my shooter. (i.e. what are the specific names of the variables which tell me target position within the screen as it is tracking, or do I need to define those as done in the printf statements in terminal.c?)

I hope I am not out of line by asking for these clarifications, but I am trying to learn this while burning too many candles in too many areas outside of FIRST… I really want my students to learn this and have the experience of FIRST, but I don’t have the personnel I need to assist me and I feel like I almost have it. I’m missing a little of the big picture because of the way the code is compartmentalized. It is truly awesome seeing what you guys are able to offer, and working through understanding it. Yet, I can’t get to the creative part and it is driving me a little bonkers. I am just one marble short of putting it all together. It must be one of the many I have lost over the past 2 weeks…

Any assistance you could offer would be much appreciated!

Steve Orr
D5Robotics : Team 1293

  1. You might want to #include camera.h which will give the autonomous code access to the T_Packet_Data (camera) variables.

  2. You are correct. The tracking code automatically moves the servos to get the target in the center of the camera’s field of view. The variables that the camera gives you are T_Packet_Data.mx, T_Packet_Data.my, T_Packet_Data.x1, T_Packet_Data.x2, T_Packet_Data.y1, T_Packet_Data.y2, T_Packet_Data.pixels, T_Packet_Data.confidence. mx and my are the coordinates of the center mass of the target. x1, y1, x2, and y2 are the coordinates for the bounding rectangle of the target. pixels is the blob size, and confidence relates to how close the actual target color is to the pre-programmed target color. The servo positions are accessed via PWM. You can use the constants PAN_SERVO and TILT_SERVO to get the positions.

  3. If you map your drive train PWM’s to the joysticks and don’t mess with the PWM’s that control the 2 servos, then you won’t have any problems.

  4. See #2 for the variables.

You might want to use trig fuctions to calculate the horizontal distance of target.

first include <math.h> where ever you want to do the trig calculations.

then look in terminal.c for the pan angle and tilt angle ratios
65/124 degrees for every pan pwm increment and 25/50 degrees for every tilt pwm increment

going to have to make it output 0 degrees when looking completely horizontal
adjust the -124 value

then just set up the equation
target_distance = height/tan(tilt_angle)

height = the vertical distance between the camera on the robot and the green light.

you can just make pwm03 = p1_y for example

you need to uncomment the default() function and remember to comment out the pwm’s being used by the camera

Success!
We now have the camera tracking from very respectable distances and driving at the same time! At first it didn’t work when I inserted the Default_Routine();
statement in between the Getdata(&rxdata); and Putdata(&txdata); statements… because you also have to uncomment the Generate_Pwms(pwm13,pwm14,pwm15,pwm16); before the Putdata(&txdata); command…

So, after a couple of debugging moments, assisted by an upcoming freshman-programming-guru named C.J. got it tracking on the fly!

Next up, autonomous and targeting with our soon to be built shooter.
All the rest of those candles I have burning are still blazing but it is so much more fun when you are able to juggle them and not catch on fire.

I’ll keep you updated on the progress…

Thanks for the help and encouragement!

Take special care when employing the “user-generated” pwm signals (13-16). If your code uses many interrupts (lots of serial activity, gear tooth sensors, rotary encoders, etc.) those pwms can get a little jittery.

What would be the alternatives?

Any of pwm01 through pwm12. :slight_smile: