Go to Post "Dress to impress," typically, means no denim (sorry, Dean)... - Madison [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 04-02-2014, 21:19
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
How to Make the Robot Drive Forward in Autonomous

This may seem like a simple question but I can't get it to work. I am using commandbase java.

I have a chassis subsystem here:

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

import edu.wpi.first.LFRobot2014.RobotMap;
import edu.wpi.first.LFRobot2014.commands.DriveTele;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.command.Subsystem;

/**
 *
 * @author Developer
 */
public class Chassis extends Subsystem {
    // Put methods for controlling this subsystem
    // here. Call these from Commands.
    RobotDrive drive;

    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        setDefaultCommand(new DriveTele());
    }
    
    public Chassis(){
        drive = new RobotDrive(RobotMap.leftMotorPort, RobotMap.rightMotorPort);
        drive.setSafetyEnabled(false);
    }
    
    public void driveTele(Joystick leftStick, Joystick rightStick){
       drive.tankDrive(leftStick, rightStick);
    }
    
    public void setSpeed(double speed){
        drive.setMaxOutput(speed);
    }

    
}
Do I use this same subsystem(which is the one that I base my TankDrive off of) to write a command that will run the motors for a certain time or do I write up a new subsystem? And what do I have to do code-wise to make this work?

THANKS!
Reply With Quote
  #2   Spotlight this post!  
Unread 04-02-2014, 21:36
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: How to Make the Robot Drive Forward in Autonomous

You use the same subsystem.

Add the following method:

Code:
public void driveAuton(double speed, double turnRate)
{
	drive.arcadeDrive(speed, turnRate);
}
You can then call this method in a command that you make for autonomous. Feel free to use the turning feature too, although don't expect to get much accuracy with it (actually, don't expect to get much accuracy with this method at all).

To implement timing is also pretty simple. In the init of your command, type: setTimeout(timeToRun); (replace timeToRun with the amount of time you want to drive forward. Then, in the isFinished of your command, type: return isTimedOut();
Reply With Quote
  #3   Spotlight this post!  
Unread 04-02-2014, 21:37
xForceDee's Avatar
xForceDee xForceDee is offline
Registered User
AKA: Bart Kerfeld
FRC #4239 (Warpspeed)
Team Role: College Student
 
Join Date: Dec 2012
Rookie Year: 2012
Location: Minnesota
Posts: 58
xForceDee is a splendid one to beholdxForceDee is a splendid one to beholdxForceDee is a splendid one to beholdxForceDee is a splendid one to beholdxForceDee is a splendid one to beholdxForceDee is a splendid one to behold
Re: How to Make the Robot Drive Forward in Autonomous

I think this should work...

Add this method to Chassis.java
Code:
public void driveAuto(double speed) {
     drive.setLeftRightMotorOutputs(speed, -speed); //The - may be wrong
}
Then make a new command which requires chassis and calls this method. If your auton needs to be more sophisticated than drive forward, you can always add the command to a command group. Anyway, this is just one solution of the many out there.

Last edited by xForceDee : 04-02-2014 at 22:19. Reason: Be sure to add double in the parameter (getting too used to python)
Reply With Quote
  #4   Spotlight this post!  
Unread 04-02-2014, 23:33
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
Re: How to Make the Robot Drive Forward in Autonomous

Okay - THANKS guys!
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 13:11.

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