Go to Post Your robot weight goes up after you release the balloons. Re-inspection! - GaryVoshol [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
View Poll Results: How is your goal tracking working?
We never tried it 3 13.64%
It works perfectly 7 31.82%
It tracks, but there's too many false positives or negatives 0 0%
It tracks, but it's too slow 8 36.36%
The robot can't connect to the camera 4 18.18%
Multiple Choice Poll. Voters: 22. You may not vote on this poll

Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-02-2010, 23:56
nathanww nathanww is offline
Hacker
FRC #1678 (Citrus Circuits)
Team Role: Programmer
 
Join Date: Dec 2008
Rookie Year: 2007
Location: Davis, CA
Posts: 224
nathanww is just really nicenathanww is just really nicenathanww is just really nicenathanww is just really nice
Camera programming progress

Team 1678 started seriously integrating our kicking and tracking systems today and ran into some pretty serious speed issues which we're now optimizing. I was wondering how many people actually have a high-speed, working camera tracking system on their robot.
__________________
Get yer robot source code here!
  #2   Spotlight this post!  
Unread 18-02-2010, 17:17
TPNigl TPNigl is offline
Registered User
FRC #0069 (Team HYPER)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Quincy, MA
Posts: 94
TPNigl is an unknown quantity at this point
Re: Camera programming progress

We've been able to move the servos and get images. We're now trying to get the tracking itself to work, but we're having problems. We posted a thread about it too.

http://www.chiefdelphi.com/forums/sh...ad.php?t=83015

If anyone who has gotten their camera to track could help, it would mean a lot.
__________________


2011 Pit Crew:
2011 CT Xerox Creativity Award

HYPER Alumni
  #3   Spotlight this post!  
Unread 18-02-2010, 17:50
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Camera programming progress

We're using Java and it's working for us.
We ripped the Target class of the example code, but here's our Camera class:
Code:
package pronto;

import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.camera.*;
import edu.wpi.first.wpilibj.image.*;


/**
 * General parameters for the camera.
 * @author Team Pronto Programmers: Patrick Chiang, Nicholas Escalona, Cody Ryu
 */
public class Camera {
    static final int SENSITIVITY_CAMERA_H = 10;
    static final int SENSITIVITY_CAMERA_V = 3;

    int targetPosition;
    double kScoreThreshold = 0.01;
    
    Timer timer;
    Servo cameraHServo,cameraVServo;
    AxisCamera cam;
    /**
     * Class designated for initializing necessary components for the physical movement of the camera
     * @param horizontalServo Servo designated for turning the camera horizontally
     * @param verticalServo Servo designated for turning the camera vertically
     * @param camera Camera designated for seeing things
     */
    public Camera(Servo horizontalServo, Servo verticalServo, AxisCamera camera){
        super();
        cameraHServo = horizontalServo;
        cameraVServo = verticalServo;
        timer = new Timer();
        cam = camera;
    }
    /**
     * Class used to specify a joystick to control the camera
     * @param cameraStick Joystick designated to control the camera
     */
    public void manual(Joystick cameraStick){
        if(cameraStick.getRawButton(1)){
            track();
            aim();
        }
        if(cameraStick.getRawButton(10)){
            cameraHServo.set(0.5);
            cameraVServo.set(0.5);
        } else{
            move(cameraStick);
        }
    }

    /**
     * Class for allowing constantly centering the ball in the camera's field of vision.
     * @param maxAngle Maximum allowed 
     * @param targetNum
     */
    public int track(){
        // System.out.println("Target Angle: " + cameraHServo.getRaw()); //TODO uncomment
        // based on code from CircleTrackerDemo

        try {
            if (cam.freshImage()) {
                ColorImage image = cam.getImage();
                Thread.yield();
                Target[] targets = Target.findCircularTargets(image);
                Thread.yield();
                image.free();
                if (targets.length == 0 || targets[0].m_score < kScoreThreshold) {
                    // targetNotFoundCount++; // DEBUG
                    // System.out.println("No target found" + targetNotFoundCount + "times"); // DEBUG
                    Target[] newTargets = new Target[targets.length + 1];
                    newTargets[0] = new Target();
                    newTargets[0].m_majorRadius = 0;
                    newTargets[0].m_minorRadius = 0;
                    newTargets[0].m_score = 0;
                    for (int i = 0; i < targets.length; i++) {
                        newTargets[i + 1] = targets[i];
                    }
                } else {
                    // System.out.println(targets[0]); //TODO uncomment
                    // System.out.println("Target Angle: " + targets[targetNum].getHorizontalAngle()); //TODO uncomment
                    // targetFoundCount++; // DEBUG
                    // System.out.println("Num targets found" + targetFoundCount); // DEBUG
                    if(Math.abs(targets[0].getHorizontalAngle())<500){
                        targetPosition = (int)targets[0].getHorizontalAngle();
                        // System.out.println(targets[0].toString());
                    }
                }                
            }
        } catch (NIVisionException e) {
            e.printStackTrace();
        } catch (AxisCameraException e) {
            e.printStackTrace();
        }
        return targetPosition;
    }

    public void aim(){
       if(Utils.isBetween(targetPosition,3,252)){
            cameraHServo.setRaw(cameraHServo.getRaw() + targetPosition);
        } else if((cameraHServo.getRaw() + targetPosition)<3){
            cameraHServo.setRaw(cameraHServo.getRaw() + 3);
        } else if((cameraHServo.getRaw() + targetPosition)>252){
            cameraHServo.setRaw(252);
        }
    }
    /**
     * Allows for manual operation of the camera's movement
     * @param shooterStick Control stick for the camera. Controlled by Buttons 2-4
     */
    public void move(Joystick shooterStick){
        
        // camera control
        if (shooterStick.getRawButton(4)) { // left
            cameraHServo.setRaw(cameraHServo.getRaw() - SENSITIVITY_CAMERA_H);
        }
        if (shooterStick.getRawButton(5)) { // right
            cameraHServo.setRaw(cameraHServo.getRaw() + SENSITIVITY_CAMERA_H);
        }
        if (shooterStick.getRawButton(2)) { // down
            cameraVServo.setRaw(cameraVServo.getRaw() - SENSITIVITY_CAMERA_V);
        }
        if (shooterStick.getRawButton(3)) { // up
            cameraVServo.setRaw(cameraVServo.getRaw() + SENSITIVITY_CAMERA_V);
        }
    }
}
Use track() and aim() together to make the robot's Servo "look" at the target. It works for side to side (horizontal) tracking, but no vertical yet.
  #4   Spotlight this post!  
Unread 18-02-2010, 18:16
bronxbomber92 bronxbomber92 is offline
Registered User
FRC #1551 (Grapes of Wrath)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Naples
Posts: 75
bronxbomber92 is an unknown quantity at this point
Re: Camera programming progress

What do the magical constants 3 and 252 mean in the aim method?
  #5   Spotlight this post!  
Unread 18-02-2010, 18:41
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Camera programming progress

Those prevent the servos from going below 3 or above 255. In theory, they go from 0-255, but they're there just in case.
  #6   Spotlight this post!  
Unread 19-02-2010, 10:46
bronxbomber92 bronxbomber92 is offline
Registered User
FRC #1551 (Grapes of Wrath)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Naples
Posts: 75
bronxbomber92 is an unknown quantity at this point
Re: Camera programming progress

Hmm, ok. I'm just surprised that works since you're treating it like an angle (since targetPosition is supposedly an angle).
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming the Camera Jordan2389Diaz Technical Discussion 15 22-02-2010 20:00
Programming Camera in Easy C Chief Samwize Programming 3 19-05-2007 20:37
Camera Programming railerobotics Programming 2 04-10-2006 21:59
Progressively Professional Programming Progress aaeamdar Programming 2 15-02-2006 23:29
Camera Help (New to Camera Programming) Idaman323 Programming 6 14-01-2006 03:56


All times are GMT -5. The time now is 17:10.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi