Will this code successfully run my robot as a tank drive also a single forward camera

and quite possibly an intake if at all possible all posts should be to tell me yes or no and if no what to do to fix it so that my team can be almost done. ::rtm::

package org.usfirst.frc.team6051.robot;

import com.ni.vision.NIVision;
import com.ni.vision.NIVision.Image;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**
*
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 {
private static final int Intake = 0;
RobotDrive myRobot;
Joystick stick;
int autoLoopCounter;
private Joystick leftstick;
private Joystick rightstick;
private GenericHID leftStick;
private GenericHID rightStick;
private Talon frontright;
private Talon frontleft;
private Talon rearright;
private Talon rearleft;
int currSession;
int sessionfront;
Image frame;

/**
 * This function is run when the robot is first started up and should be
 * used for any initialization code.
 */
public void robotInit() {
	myRobot = new RobotDrive(0,1,2,3);
	setLeftstick(new Joystick(0));
	setRightstick(new Joystick(1));
	frontright = new Talon(1);
	frontright.set(.5);
	frontleft = new Talon(2);
	frontleft.set(.5);
	rearright = new Talon(3);
	rearright.set(.5);
	rearleft = new Talon(4);
	rearleft.set(.5);
	frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);

	sessionfront = NIVision.IMAQdxOpenCamera("cam1", NIVision.IMAQdxCameraControlMode.CameraControlModeController);

	currSession = sessionfront;

	NIVision.IMAQdxConfigureGrab(currSession);
}

/**
 * This function is run once each time the robot enters autonomous mode
 */
public void autonomousInit() {
	autoLoopCounter = 0;
	myRobot.drive(0.5, 0.0);
}

/**
 * This function is called periodically during autonomous
 */
public void autonomousPeriodic() {
	if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
	{
		myRobot.drive(0.5, 0.0); 	// drive forwards half speed
		autoLoopCounter++;
		} else {
		myRobot.drive(0.0, 0.0); 	// stop robot
	}
}

/**
 * This function is called once each time the robot enters tele-operated mode
 */
public void teleopInit(){
}

/**
 * This function is called periodically during operator control
 */
	public void teleopPeriodic() { 
		myRobot.setSafetyEnabled(true);
		while (isOperatorControl() && isEnabled()) {
		myRobot.tankDrive(leftStick, rightStick);
		System.out.println(leftStick.getY());
		System.out.println(rightStick.getY());
		leftStick.getRawAxis(0);
		Timer.delay(0.005) ; 
		LiveWindow.run();
		rightStick.getPOV(Intake);
		}} 


/**
 * This function is called periodically during test mode
 */
public void testPeriodic() {
	LiveWindow.run();
}

public Joystick getLeftstick() {
	return leftstick;
}

public void setLeftstick(Joystick leftstick) {
	this.leftstick = leftstick;
}

public Joystick getRightstick() {
	return rightstick;
}

public void setRightstick(Joystick rightstick) {
	this.rightstick = rightstick;
}

}

There is a problem in your robotInit where you allocate PWM channels 0-3 when constructing your RobotDrive object and then allowcate PWM channels 1-4 when creating your talons, try changing it to:


/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
  setLeftstick(new Joystick(0));
  setRightstick(new Joystick(1));

  frontright = new Talon(1);
  frontleft = new Talon(2);
  rearright = new Talon(3);
  rearleft = new Talon(4);

  myRobot = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);

  // I would comment out the vision stuff for now, until you are driving

  //frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_ RGB, 0);

  //sessionfront = NIVision.IMAQdxOpenCamera("cam1",   NIVision.IMAQdxCameraControlMode.CameraControlMode Controller);

  //currSession = sessionfront;

  //NIVision.IMAQdxConfigureGrab(currSession);
}

Your autonomous code looks like it should work, however, I think you need to make some adjustments to your teleop code:


/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() { 
  myRobot.tankDrive(leftStick, rightStick);
    
  // Instead of System.out.prinlnt(), you might want to try:  
  // SmartDashboard.putNumber("Left Stick Y", leftStick.getY()); 
  System.out.println(leftStick.getY());
  System.out.println(rightStick.getY());

  // Did you want to do something with the value returned?
  // leftStick.getRawAxis(0);

  // This only reads the angle of POV 0 from the right joystick,
  // you will need to add code if you want to do something with
  // the value returned
  int intakeMode = rightStick.getPOV(Intake);
}

Hope that helps.

Some notes:

  • It would be better in the future if you wrap your code in CODE tags (# symbol in the post editor), in order for your code to be more readable.
  • You initialized your drive motors to 0,1,2,3, but you initialized your talons to 1,2,3,4. I would either initialize the talons and then use them in the RobotDrive initializer, or make constants to represent each channel of each talon.
  • Not sure what the point is of setting each motor to 0.5 in robotInit(). If you want to make sure they’re enabled, you can use the enable() member function. The motors shouldn’t even run in the init functions, but I haven’t tested this.
  • Your camera code is almost complete, but I believe you need to send it to the SmartDashboard with
CameraServer.getInstance().setImage(NIVision.IMAQdxGrab(sessionFront, frame, 1));

Its possible I’m wrong and LiveWindow.run() sends it somehow, but I’m guessing not.

  • Currently, your code will not run an intake. You need to initialize how ever many talons your intake uses and check the state of the POV to decide whether or not to run the motors.