Go to Post do the math, then use the math to go for total overkill. - pfreivald [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 29-03-2016, 19:54
aansonjr001 aansonjr001 is offline
Registered User
FRC #5432
 
Join Date: Mar 2016
Location: Gardena
Posts: 2
aansonjr001 is an unknown quantity at this point
Button assignment for specific motors

I've been having trouble trying to find out how to assign motors to buttons. In vex you could do something like.........

if(vexRT[Bn5U] == 1){
motor[left] ==127;
motor[right]==127;
}
else{
motor[left]==0;
motor[right]==0;
}'(everything probably not exact but its something like this)

so my teammate and I were trying to do the same in java for the frc programming but when we tried it, it did not work out well. We've been trying to fix it but were having trouble assigning motors(Victor, Talon, etc.) to buttons on our joystick(all motors, servos, encoders, and counters are initialized) . So if someone can help us out I will really appreciate it because it's starting to bug me since I couldn't figure it out. ^W^

This is our code now....


package org.usfirst.frc.team5432.robot;

import edu.wpi.first.wpilibj.CounterBase.EncodingType;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.TalonSRX;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.buttons.JoystickButton;

/**
* 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 {
RobotDrive myRobot;
Joystick stick;
Joystick xbox;
JoystickButton A;
JoystickButton B;
JoystickButton X;
JoystickButton Y;
JoystickButton LB;
JoystickButton RB;
JoystickButton BACK;
JoystickButton START;

int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
JoystickButton button1;
JoystickButton button2;
JoystickButton button3;
JoystickButton button4;
JoystickButton button5;
JoystickButton button6;
JoystickButton button7;
JoystickButton button8;
JoystickButton button9;
JoystickButton button10;
JoystickButton button11;
JoystickButton button12;
VictorSP rightMotors;
VictorSP leftMotors;
Servo retaining;
Servo shooting;
TalonSRX arm;
Victor shooter;
Talon lift;
Talon winch;
Encoder right;
Encoder left;
Encoder shootarm;

public void roboInit() {
myRobot = new RobotDrive(0,1);
xbox = new Joystick(1);
A = new JoystickButton(xbox,1);
B = new JoystickButton(xbox,2);
X = new JoystickButton(xbox,3);
Y = new JoystickButton(xbox,4);
LB = new JoystickButton(xbox,5);
RB = new JoystickButton(xbox,6);

stick = new Joystick(0);
button1 = new JoystickButton(stick,1);
button2 = new JoystickButton(stick,2);
button3 = new JoystickButton(stick,3);
button4 = new JoystickButton(stick,4);
button5 = new JoystickButton(stick,5);
button6 = new JoystickButton(stick,6);
button7 = new JoystickButton(stick,7);
button8 = new JoystickButton(stick,8);
button9 = new JoystickButton(stick,9);
button10 = new JoystickButton(stick,10);
button11 = new JoystickButton(stick,11);
button12 = new JoystickButton(stick,12);
retaining = new Servo(9);
shooting = new Servo(8);
lift = new Talon(4);
winch = new Talon(3);
shooter = new Victor(5);
leftMotors = new VictorSP(6);
left = new Encoder(6,counter1,true, EncodingType.k1X);
rightMotors = new VictorSP(7);
right = new Encoder(7,counter2,true, EncodingType.k1X);
arm = new TalonSRX(2);
shootarm = new Encoder(2,counter3,true, EncodingType.k1X);
}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {

}

/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
myRobot.arcadeDrive(stick);




}

/**
* This function is called periodically during test mode
*/
public void testPeriodic() {

}

}
Reply With Quote
  #2   Spotlight this post!  
Unread 29-03-2016, 20:28
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Button assignment for specific motors

The method you need is this:
Code:
public boolean getRawButton(final int button);
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 29-03-2016, 20:34
Pault's Avatar
Pault Pault is offline
Registered User
FRC #0246 (Overclocked)
Team Role: College Student
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Boston
Posts: 618
Pault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond repute
Re: Button assignment for specific motors

If you want the arm to move full speed in the positive direction when A on your XBOX controller:

Code:
if(A.get()) {
    arm.set(1);
}
Note that in frc you send motors a value between -1 and 1, with -1 being full reverse, 0 being stopped, and 1 being full forward.
Reply With Quote
  #4   Spotlight this post!  
Unread 29-03-2016, 22:30
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 322
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Button assignment for specific motors

Quote:
Originally Posted by Pault View Post
If you want the arm to move full speed in the positive direction when A on your XBOX controller:

Code:
if(A.get()) {
    arm.set(1);
}
Note that in frc you send motors a value between -1 and 1, with -1 being full reverse, 0 being stopped, and 1 being full forward.
Code:
if(A.get()) {
    arm.set(1);
} else {
    arm.set(0); // !!
}
Motor safety should catch this for you, but please make sure to stop your motors when you're done with them.
Reply With Quote
  #5   Spotlight this post!  
Unread 30-03-2016, 19:34
aansonjr001 aansonjr001 is offline
Registered User
FRC #5432
 
Join Date: Mar 2016
Location: Gardena
Posts: 2
aansonjr001 is an unknown quantity at this point
Re: Button assignment for specific motors

Thank you sooooooooo much Pault, mikets, and euhlmann this will help us write the code. This is just what we need.
Reply With Quote
Reply


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

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