RobotBuilder/Java help

This year my team is planning on upgrading our camera by adding a pan and tilt mount that I’m going to mock up and build. At the same time I’m also writing a code for it, well at least trying to. I’m using RobotBuilder and I’m trying to set up a PIDsubsystem to allow us to center the camera. Is that possible? I want to use 2 potenimeters and 2 servos that i can set a point for that is centered on what we should line up with.

With a servo, you can tell it a precise angle to turn to - you don’t need the potentiometer.

So, lets say you have the horizontal servo set to 0.50. You look at the camera feed, and notice that the center of the target is a few pixels to the right of center. So, change the servo value to 0.51 and look at the new image. Now how many pixels off are you? Gather some data on this so you can make an equation or a small look-up table that tells you how far to turn based on how far off you are. The picture dimensions define a fixed area to work in, which makes this sort of thing a little easier. Once you have that, go to your ideal shooting location, get lined up, and look at what values you’re setting your servo’s to - that’s what you want to try to hit for a good shot.

Personally, however, my team has found a simpler solution to be a bit easier to work with in the past. We mount the camera at a fixed angle, and then overlay a target on the image (this can be done as easily as taping some clear overhead paper to the computer monitor and drawing on it with sharpie). This way the drivers can look at the image and judge how well lined up they are!

Am I able to set it up on smart dashboard?

Would I be able to control the camera with a joystick?

If you write your code to support that, then yes. Instead of your joystick axis or button feeding the drivetrain motors, they would feed the servo motors. Same premise.

Not sure what you’re asking. You can forward the video feed to the smart dashboard.

If you’re adding the camera on to the robot to allow it to aim at a target. It may be easier to keep your camera fixed, and rotate the drivetrain. Just my two cents.

I just can’t figure out what command to use for that though. Like what the equivelent of arcaeDrive would be.

Basically I want to be able to move then press the trigger to recenter it. It’s not necesacially for shooting or anything. Its this idea that I had last year during the competion that might help us.

There’s no direct command to control the drive train with the camera… you would need to write code that interprets the camera feed and decides how much to turn the wheels. That could then feed into a normal drive routine, or a custom one if you find that easier.

No I mean a code type that is like the arcadeDrive code but it controls the camera. So one joystick for the drive train and the other for the camera.

I’m not aware of anything like that. If I remember right, servo’s are controlled with a range of 0 to 1.0, while a joystick returns a range of -1.0 to 1.0. You could do something like passing the value from the joystick through a conversion function(something like (x+1)/2) into the servo - then releasing the joystick would center the servo, and moving it to either side would give you direct control - the amount you move the joystick would match the amount the camera moved.

There is nothing in robotbuilder that can do that. If you want this feature, you are going to need to figure out how to code it manually. Remember that if you want to be a good coder you are going to need to realize where robotbuilder limits you and you need to break free from it. And btw just because you shouldn’t use robotbuilder for this feature you don’t have to give up robotbuilder entirely. It is designed so that you can use it for some parts of your code and not for others.

I think this should work

public void takeJoystickInputs(Joystick left) {
double servoIn = (left.getX() +1)*0.5;
double servoIn2 = (left.getY() +1)*0.5;
pan.set(servoIn);
tilt.set(servoIn2);
}
public void stop() {
pan.set(0.5);
tilt.set(0.5);
}

What do you guys think?

A couple of things.

The PWM to the servo sets a position. Different than an PWM to a motor that sets a speed. (continuous rotation servos excepted.)

The issue with setting a camera position with a spring return joy stick is holding any position other than neutral. We had better luck using the top hat buttons.

The code you have should behave like Jon Stratis’ description above. After reading your question, it seems to me like you were looking for code that would let you move the camera with the joystick and have it stay put until you reset it. Here’s an example that would give you more ‘Arcade Drive’ like movement of the camera:


public void moveCamera(Joystick joy) {
    final double kSensitivity = 0.1;  // Controls servo response time

    //
    // Add a portion of the joystick position to the current servo position to
    // give the servo an "Arcade Drive"-like response. Y axis value is negated 
    // since the joystick considers forward movement along the Y axis negative.
    //
    double newPan = pan.get() + (joy.getX() * kSensitivity);
    double newTilt = tilt.get() + (-(joy.getY()) * kSensitivity);

    //
    // Make sure the new positions are in the proper range of 0.0 to 1.0.
    // The Servo#set method should check this as well, so this section may
    // not be necessary.
    //
    if (newPan > 1.0) newPan = 1.0;
    else if (newPan < 0.0) newPan = 0.0;
    if (newTilt > 1.0) newTilt = 1.0;
    else if (newTilt < 0.0) newTilt = 0.0;

    //
    // Update the servo positions
    //
    pan.set(newPan);
    tilt.set(newTilt);
}

public void resetCameraPosition() {
    pan.set(0.5);
    tilt.set(0.5);
}

Thanks this was exactly what I was looking for. I also added a center command that runs on a trigger push and it works perfectly.

here’s my camera mount prototype so far. I just replaced the screws with zip ties because they’re more adjustable and stay in place better.

download.jpg


download.jpg