Go to Post At the Chesapeake Regional, we will be weighing any team that brings in a kitchen sink (or other major appliances) or an extra robot... - RoboMom [more]
Home
Go Back   Chief Delphi > Technical > Technical Discussion
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 18-02-2015, 13:02
codedr codedr is offline
Registered User
FRC #0537
Team Role: Mentor
 
Join Date: Mar 2010
Rookie Year: 2009
Location: Wisconsin
Posts: 68
codedr will become famous soon enoughcodedr will become famous soon enough
Re: How to make the camera work? (Java)

We got it to work by getting the cameraServer instance, calling the cameraServer with "cam0" argument and calling the start capture method.
  #3   Spotlight this post!  
Unread 18-02-2015, 13:07
codedr codedr is offline
Registered User
FRC #0537
Team Role: Mentor
 
Join Date: Mar 2010
Rookie Year: 2009
Location: Wisconsin
Posts: 68
codedr will become famous soon enoughcodedr will become famous soon enough
Re: How to make the camera work? (Java)

import edu.wpi.first.wpilibj.CameraServer;


CameraServer cams = CameraServer.getInstance();
// set any cam parameters, then start capture
cams.startAutomaticCapture("cam0");
  #4   Spotlight this post!  
Unread 18-02-2015, 16:18
JML's Avatar
JML JML is offline
Jlyon
AKA: Jlyon
FRC #3044 (0xBe4)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2012
Location: 3044
Posts: 17
JML is an unknown quantity at this point
Re: How to make the camera work? (Java)

Our team had trouble viewing the camera on the default dashboard, viewing it with smart dashboard or another program may be easier. To use smart dashboard, you send the image with the camera server class (we don't use automatic capture so we can set the frame rate)

Code:
 int count = 0;

	public void teleopPeriodic() {
		currentTime = Timer.getMatchTime();
		if (count > 3) {
			NIVision.IMAQdxGrab(session, frame, 1);
			CameraServer.getInstance().setImage(frame);
			lastUpdateTime = currentTime;
			count = 0;

		}
		count += 1;
        }
Edit: You also need to hit the play button for it to play on the Default Dashboard

Last edited by JML : 18-02-2015 at 16:24.
  #5   Spotlight this post!  
Unread 18-02-2015, 16:45
MaGiC_PiKaChU's Avatar
MaGiC_PiKaChU MaGiC_PiKaChU is offline
Drive Coach
AKA: Antoine L.
FRC #3360 (Hyperion)
Team Role: Mentor
 
Join Date: Mar 2014
Rookie Year: 2012
Location: Sherbrooke
Posts: 598
MaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond repute
Re: How to make the camera work? (Java)

Our team had to set the quality to 25% for the feed to show
  #6   Spotlight this post!  
Unread 19-02-2015, 00:18
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: How to make the camera work? (Java)

Quote:
Originally Posted by JML View Post
Edit: You also need to hit the play button for it to play on the Default Dashboard
The play button is not associated with the camera image.
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


All times are GMT -5. The time now is 09:27.

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