Go to Post ...on occasion, just smile and nod in appreciation. - dubious elise [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 11-09-2013, 12:27 PM
Zaque Zaque is offline
FF: Bobo Brigade
AKA: Zachary H.
FRC #3352 (Flaming Monkeys)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2013
Location: Belvidere, Illinois
Posts: 91
Zaque has a spectacular aura aboutZaque has a spectacular aura aboutZaque has a spectacular aura about
Invert Motors in Java

Hello,

We are switching from LabVIEW to Java for the coming build season, and we are currently rewriting our 2013 code in java. We have everything working except for the driving. In the LabVIEW program we had, our front and rear left motors inverted. I have looked at other posts using RobotDrive.setInvertedMotor, but I have not been able to get the program to accept it. My code is attached:

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Victor;
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 SimpleRobot
* 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 RobotTemplate extends SimpleRobot {
Victor frontLeft = new Victor(1);
Victor rearLeft = new Victor(3);
Victor frontRight = new Victor(2);
Victor rearRight = new Victor(4);
/**frontLeft,rearLeft,frontRight,rearRight**/
RobotDrive chassis = new RobotDrive(frontLeft,rearLeft,frontRight,rearRight );
chassis.setInvertedMotor(RobotDrive.frontLeft, true);
chassis.setInvertedMotor(RobotDrive.rearLeft, true);

/**pressureSwitchChannel, compressorRelayChannel**/
Compressor compressor = new Compressor(1, 1);
/**channel**/
DoubleSolenoid right = new DoubleSolenoid(2, 1);
DoubleSolenoid left = new DoubleSolenoid(4, 3);
/**channel**/
AnalogChannel pot = new AnalogChannel(1,1);
Victor shooter = new Victor(8);
Victor angle = new Victor(10);
Victor loader = new Victor(9);
Joystick driver = new Joystick(1);
Joystick operator = new Joystick (2);
double v;
int i = 0;
boolean lastPress = false;
boolean currentPress = false;
boolean shooterState = false;
boolean lastPress2 = false;
boolean currentPress2 = false;
boolean solenoidState = false;

public RobotTemplate() {
compressor.start();
}


public void autonomous() {
chassis.setSafetyEnabled(false);
shooter.set(100);
v = pot.getVoltage();
/**set angle**/
while(v < 1.43){
angle.set(1);
v = pot.getVoltage();
}
angle.set(0);
/**fire**/
while(i<6){
Timer.delay(0.5);
loader.set(100);
Timer.delay(0.25);
loader.set(0);
i++;
}
shooter.set(0);
}

/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
chassis.setSafetyEnabled(true);
while(isOperatorControl() && isEnabled()){
/**drive code**/
chassis.arcadeDrive(driver.getRawAxis(1), driver.getRawAxis(4));
/**hanger code**/
lastPress2 = currentPress2;
currentPress2 = driver.getRawButton(9);
if(currentPress2 && !lastPress2){
if(solenoidState){
left.set(DoubleSolenoid.Value.kForward);
right.set(DoubleSolenoid.Value.kForward);
solenoidState = false;
}else{
left.set(DoubleSolenoid.Value.kReverse);
right.set(DoubleSolenoid.Value.kReverse);
solenoidState = true;
}
}
/**shooter toggle code**/
lastPress = currentPress;
currentPress = operator.getRawButton(2);
if(currentPress && !lastPress){
if(shooterState){
shooter.set(0);
shooterState = false;
}else{
shooter.set(1);
shooterState = true;
}
}
/**loader code**/
if(operator.getRawButton(5)){
loader.set(1);
}else{
loader.set(0);
}

/**angle code**/
if(operator.getRawButton(1)){
angle.set(operator.getRawAxis(2));
}else{
angle.set(0);
}

Timer.delay(0.01);
}
}

/**
* This function is called once each time the robot enters test mode.
*/
public void test() {

}
}
__________________
Zaque (Zach) H.
President
Programming/Electrical Lead
Reply With Quote
 


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 08:18 AM.

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