View Single Post
  #1   Spotlight this post!  
Unread 16-01-2017, 13:01
whitetail's Avatar
whitetail whitetail is offline
Registered User
FRC #5407 (Wolf Pack)
Team Role: Driver
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Philadelphia
Posts: 58
whitetail is an unknown quantity at this point
Java coding help

I am just driving to write a simple program to get the motors to drive using a joystick. I can deploy it and it throws no errors but when I move the joystick nothing happens. Any help would be greatly appreciated!

Robot code posted below:

Class Robot:

package org.usfirst.frc.team5407.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
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 {

//Declare classes up here

RobotBase robotbase = new RobotBase(0,1);
Inputs inputs = new Inputs(0);

// final String defaultAuto = "Default";
// final String customAuto = "My Auto";
// String autoSelected;
// SendableChooser chooser;

public void robotInit() {


//Class inputs go here
// robotbase = new RobotBase(0,1);
// inputs = new Inputs(0);
// sensors = new Sensors();


// solenoids = new Solenoids( //Drive train gear shifter w
// );


// chooser = new SendableChooser();
// chooser.addDefault("Default Auto", defaultAuto);
// chooser.addObject("My Auto", customAuto);
// SmartDashboard.putData("Auto choices", chooser);
}

public void autonomousInit() {


// autoSelected = (String) chooser.getSelected();
// autoSelected = SmartDashboard.getString("Auto Selector", defaultAuto);
// System.out.println("Auto selected: " + autoSelected);
}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
//switch(autoSelected) {
//case customAuto:
//Put custom auto code here
// break;
//case defaultAuto:
//default:
//Put default auto code here
//break;
//}
}

/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
//double counter = 0.0; //Counter writes value to SmartDashboard to verify connection
while (isOperatorControl() && isEnabled()){
//SmartDashboard.putNumber("Counter", counter++);
//Timer.delay(0.10);

//Put class.update here for robot think

inputs.readValues();
robotbase.update();
robotThink();

}

}

public void robotThink(){
robotbase.d_LeftDriveMotor = inputs.d_PowerArcadeDrive - inputs.d_TurnArcadeDrive;
robotbase.d_RightDriveMotor = inputs.d_PowerArcadeDrive + inputs.d_TurnArcadeDrive;
}

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

}

}

Class RobotBase:

package org.usfirst.frc.team5407.robot;

import edu.wpi.first.wpilibj.Spark;


public class RobotBase {

//SpeedControllers go here ex: Mot_DriveMotor
Spark mot_LeftDriveMotor;
Spark mot_RightDriveMotor;

//Doubles go here ex: d_DriveMotor
double d_LeftDriveMotor;
double d_RightDriveMotor;

public RobotBase(int PWMConnector_LeftDriveMotor, int PWMConnector_RightDriveMotor){

mot_LeftDriveMotor = new Spark(PWMConnector_LeftDriveMotor);
mot_RightDriveMotor = new Spark(PWMConnector_RightDriveMotor);


//Make sure all motors are stopped
mot_LeftDriveMotor.set(0.0);
mot_RightDriveMotor.set(0.0);

}
public void update(){

}

}

Class Inputs:

package org.usfirst.frc.team5407.robot;

import edu.wpi.first.wpilibj.Joystick;

public class Inputs {

Joystick joy_DriveStick;

//doubles go under here
double d_PowerArcadeDrive;
double d_TurnArcadeDrive;

//booleans go under here
//boolean b_DualSpeedShifter;


public Inputs(int USBConnector_Drivestick){
joy_DriveStick = new Joystick(USBConnector_Drivestick);
zeroInputs();
}

public void readValues(){


//Joystick X,Y,Z, Pov and Throttle go under here
d_PowerArcadeDrive = joy_DriveStick.getX() * -1;
d_TurnArcadeDrive = joy_DriveStick.getY() * -1;

// if (Math.abs(d_PowerArcadeDrive)<.01) {
// d_PowerArcadeDrive = 0;
// }
//
// if (Math.abs(d_TurnArcadeDrive)<.01){
// d_TurnArcadeDrive = 0;
// }


//and an if that if the value is smaller disregard it if its bigger then use it

}

public void zeroInputs(){
this.d_TurnArcadeDrive = 0.0;
this.d_PowerArcadeDrive = 0.0;
}

}
__________________
FRC Team 5407 -Driver, Programmer and Head Control Systems Engineer
2015 MAR Championship Rookie All Star Award
2015 MAR Hatboro-Horsham District Rookie All Star Award
2015 MAR Hatboro-Horsham District event Winner(Thanks 2590 and 2607)
2016 MAR Hatboro-Horsham District event Winner(Thanks 2607 and 1218)
Reply With Quote