|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Problematic Java code
Hi, I'm trying to start using Java for my team. I haven't had success yet, so we're probably using LabVIEW again. Nevertheless, I'd like to know what went wrong with this code:
Code:
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
/*HOW (my name) CODES FOR ALL YALL
* I like using small variables. You will see lots of chars.
* I write my variables likeThis. That's called Pascal style, I think.
*/
package edu.wpi.first.wpilibj.templates;
//first stuff
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Jaguar;
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 JRobot extends IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
//button mappings
//powers
//random variables
final boolean useSlowmo = false;
//actual objects
RobotDrive driveObject;
Joystick mainPad;
Jaguar motor1,motor2,motor3,motor4;
public void robotInit() {
mainPad = new Joystick(1);
motor1 = new Jaguar(1);
motor2 = new Jaguar(2);
motor3 = new Jaguar(3);
motor4 = new Jaguar(4);
driveObject = new RobotDrive(motor1,motor2,motor4,motor3);
//distanceMonitor = new Encoder(2,1,2,2);
//tooEasy = new KinectStick(1);
}
/**
* This function is called periodically during autonomous
*/
public void disabledInit() {
driveObject.stopMotor();
}
public void disabledContinuous() {
//blah blah nobody cares
Timer.delay(0.1);
}
public void disabledPeriodic() {
//¡Nos gustan a los deportes y no nos importan a quienes lo saben!
getWatchdog().feed();
}
public void autonomousInit() {
}
public void autonomousPeriodic() {
}
public void autonomousContinuous() {
getWatchdog().feed();
Timer.delay(0.1);
}
/**
* This function is called periodically during operator control
*/
public void teleopInit() {
//still nothing here
}
public void teleopPeriodic() {
}
public void teleopContinuous() {
//i use a double here so java doesn't complain about casting a float
/*this says: is useSlowmo false? if so, halve the joysticks.
otherwise, use full output.*/
double slowmoMultiplier = 1;
driveObject.mecanumDrive_Cartesian(mainPad.getX()*slowmoMultiplier,
mainPad.getY()*slowmoMultiplier,
mainPad.getTwist()*slowmoMultiplier,0.f);
}
}
Last edited by -J.- : 01-30-2012 at 09:48 PM. |
|
#2
|
||||
|
||||
|
Re: Problematic Java code
-You don't need to feed the watchdog.
-It seems that you should be using MecanumDrivePolar as opposed to cartesian as you are just giving it a 0 for the Gyro angle. -The magnitude and direction degrees values of mecanumDrive do not work the way that you are supplying them values. They take an actual value for magnitude and directionDegrees. You can just use mainPad.getMagnitude() and mainPad.getDirectionDegrees() I'll look more in depth and tell you if I find any other issues. The following are not so much problems but can be useful: -Try to name your motors things that make sense. "motor1" may be something useful to you but to anyone else who looks at it is impossible to tell what this is without going to the robot and checking out the wiring. Things like FRONT_LEFT_JAG make more sense to everyone. This code will be enough to get your robot moving from the one game pad in a typical mecanum drive type of way. Code:
RobotDrive driveObject;
Joystick mainPad;
Jaguar motor1;
Jaguar motor2;
Jaguar motor3;
Jaguar motor4;
public void robotInit() {
mainPad = new Joystick(1);
motor1 = new Jaguar(1);
motor2 = new Jaguar(2);
motor3 = new Jaguar(3);
motor4 = new Jaguar(4);
driveObject = new RobotDrive(motor1, motor2, motor4, motor3);
}
public void teleopPeriodic() {
driveObject.mecanumDrive_Polar(mainPad.getMagnitude(), mainPad.getDirectionDegrees(), mainPad.getTwist());
}
}
Last edited by eddie12390 : 01-30-2012 at 11:18 PM. |
|
#3
|
|||
|
|||
|
Re: Problematic Java code
I picked Cartesian because you can give it x and y values from the joystick directly (at least, to my understanding), though I could give polar a shot. Right now, though, we're having issues with the robot doing nothing at all once it gets into teleop, so that might be hardware...
|
|
#4
|
||||
|
||||
|
Re: Problematic Java code
Quote:
I was unaware that you could just supply an X and Y value to Cartesian. I probably should have looked before I suggested a change. That being said, it is still worth a try. Last edited by eddie12390 : 01-31-2012 at 12:52 AM. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|