Go to Post Remember to ALWAYS use physics in engineering discussions. There is really no room for "feelings" in this sort of thing. - JVN [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 24-01-2014, 22:11
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
Motor Programming

Okay - I want to have a motor that - when button 4 is pressed on the joystick the motor moves in one direction until he button is released - when button 5 is pressed the motor moves in the other direction until the button is released.

Here is the code I wrote:

Subsystem for the "ForkMotor":

Quote:
package edu.wpi.first.LFRobot2014.subsystems;

import edu.wpi.first.LFRobot2014.RobotMap;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.command.Subsystem;

/**
*
* @author FrankyMonezz
*/
public class ForkMotor extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
SpeedController motor = new Jaguar(RobotMap.ForkMotorPort);

public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
}

public void up() {
motor.set(1);
}

public void down() {
motor.set(-1);
}
}

Command to move motor in one direction.

Quote:
package edu.wpi.first.LFRobot2014.commands;


/**
*
* @author FrankyMonezz
*/
public class LiftForks extends CommandBase {

public LiftForks() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(ForkMotor);
}

// Called just before this Command runs the first time
protected void initialize() {
}

// Called repeatedly when this Command is scheduled to run
protected void execute() {
ForkMotor.up();
}

// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return false;
}

// Called once after isFinished returns true
protected void end() {
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
Command to move the motor in the other direction:

Quote:
package edu.wpi.first.LFRobot2014.commands;

/**
*
* @author FrankyMonezz
*/
public class LowerForks extends CommandBase {

public LowerForks() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(ForkMotor);
}

// Called just before this Command runs the first time
protected void initialize() {
}

// Called repeatedly when this Command is scheduled to run
protected void execute() {
ForkMotor.down();
}

// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return false;
}

// Called once after isFinished returns true
protected void end() {
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
All ports are already set correctly in RobotMap and buttons are correctly assigned using whileHeld() in OI - noting this will the above code work?

THANKS for the help!
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 09:31.

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