View Single Post
  #1   Spotlight this post!  
Unread 12-02-2015, 17:19
5580SQUAD 5580SQUAD is offline
Registered User
FRC #5580
 
Join Date: Feb 2015
Location: Canada
Posts: 5
5580SQUAD is an unknown quantity at this point
How to make the camera work? (Java)

We are trying to get the camera to show it's display on the dashboard but we've failed to get any kind of input showing.




And here's our code:

Code:
package org.usfirst.frc.team5580.robot;
 
import com.ni.vision.NIVision;
import com.ni.vision.NIVision.DrawMode;
import com.ni.vision.NIVision.Image;
import com.ni.vision.NIVision.ShapeMode;
 
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Timer;
 
/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
        final int JOYSTICK_PORT = 0; //Computer port 0
        final int FRONT_LEFT_SC = 1; //PWM, PORT 0
        final int FRONT_RIGHT_SC = 2; // PWM, PORT 1
        final int BACK_LEFT_SC = 3; // PWM, PORT 2
        final int BACK_RIGHT_SC = 4; //PWM, PORT 3
        final int LIFT_SC = 5; //PWM, PORT 4
        int session;
    Image frame;
       
        Joystick driver;
        Talon frontLeft;
        Talon frontRight;
        Talon backLeft;
        Talon backRight;
        DoubleSolenoid sol1;
        Compressor comp;
        Talon lift;
        CameraServer camera;
 
    public void robotInit() {
        driver = new Joystick(JOYSTICK_PORT);
        frontLeft = new Talon(FRONT_LEFT_SC);
        frontRight= new Talon(FRONT_RIGHT_SC);
        backLeft = new Talon(BACK_LEFT_SC);
        backRight= new Talon(BACK_RIGHT_SC);
        sol1 = new DoubleSolenoid(0,1);
        comp = new Compressor(0);
        comp.setClosedLoopControl(true);
        lift = new Talon(LIFT_SC);
        frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
 
        // the camera name (ex "cam0") can be found through the roborio web interface
        session = NIVision.IMAQdxOpenCamera("cam0",
                NIVision.IMAQdxCameraControlMode.CameraControlModeController);
        NIVision.IMAQdxConfigureGrab(session);
    }
 
    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        while (isEnabled()&&isAutonomous()){
               
        }
    }
 
    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        while (isEnabled()&&isOperatorControl()){
                double leftSpeed = driver.getRawAxis(1)*-1;
                double rightSpeed = driver.getRawAxis(5);
                double turns=driver.getRawAxis(3)*-1;
                boolean liftSpeed = driver.getRawButton(2);
                boolean liftSpeed1 = driver.getRawButton(3);
                frontLeft.set(leftSpeed);
                backLeft.set(leftSpeed);
                frontRight.set(rightSpeed);
                backRight.set(rightSpeed);
                        boolean push = driver.getRawButton(1);
                        boolean pull = driver.getRawButton(4);
                        if(turns <0){
                                frontLeft.set(turns);
                        }
                        else if(turns>0){
                               
                        }
                        if (liftSpeed == true){
                                lift.set(1);
                        }
                         else if(liftSpeed1 == true) {
                                 lift.set(-1);
                         }
                                else {
                       
                                lift.set(0);
                        }
                       
                if (push == true){
                  sol1.set(DoubleSolenoid.Value.kReverse);
               
                }
               
                if (pull == true){
                        sol1.set(DoubleSolenoid.Value.kForward);
                }
               
               
 
        }
    }
    public void operatorControl() {
        NIVision.IMAQdxStartAcquisition(session);
 
        /**
         * grab an image, draw the circle, and provide it for the camera server
         * which will in turn send it to the dashboard.
         */
        NIVision.Rect rect = new NIVision.Rect(10, 10, 100, 100);
 
        while (isOperatorControl() && isEnabled()) {
 
            NIVision.IMAQdxGrab(session, frame, 1);
            NIVision.imaqDrawShapeOnImage(frame, frame, rect,
                    DrawMode.DRAW_VALUE, ShapeMode.SHAPE_OVAL, 0.0f);
           
            CameraServer.getInstance().setImage(frame);
 
            /** robot code here! **/
            Timer.delay(0.005);         // wait for a motor update time
        }
        NIVision.IMAQdxStopAcquisition(session);
    }
 
   
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
   
    }
   
}

If you have any idea on what we should do please post a reply