When you're around my motors redline.
Home
Go Back   Chief Delphi > FIRST > General Forum
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 01-02-2017, 22:27
trycatch's Avatar
trycatch trycatch is offline
Registered User
FRC #5858
 
Join Date: Nov 2015
Rookie Year: 2015
Location: AL
Posts: 44
trycatch is on a distinguished road
Autonomous won't do *anything* ?

I'm trying to do the most absolutely *basic* wpilib autonomous, and I can't get it to trigger. It isn't doing anything, and I'm following the wpilib pretty closely...

Code:
// RobotBuilder Version: 2.0
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.


package org.usfirst.frc5858.SteamworksBot; 

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

import org.usfirst.frc5858.SteamworksBot.commands.*;
import org.usfirst.frc5858.SteamworksBot.subsystems.*;

/**
 * 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 {

    Command autonomousCommand;

    public static OI oi;
    

    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	RobotMap.init();
        oi = new OI();

        //autonomousCommand = new AutonomousCommand();
        autonomousCommand = new DebugAutoCommandOne();
    }

    /**
     * This function is called when the disabled button is hit.
     * You can use it to reset subsystems before shutting down.
     */
    public void disabledInit(){

    }

    public void disabledPeriodic() {
        Scheduler.getInstance().run();
    }

    public void autonomousInit() {
        // schedule the autonomous command (example)
        if (autonomousCommand != null) autonomousCommand.start();
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

    public void teleopInit() {
        // This makes sure that the autonomous stops running when
        // teleop starts running. If you want the autonomous to
        // continue until interrupted by another command, remove
        // this line or comment it out.
        if (autonomousCommand != null) autonomousCommand.cancel();
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        Scheduler.getInstance().run();
    }

    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
        LiveWindow.run();
    }
}
Code:
package org.usfirst.frc5858.SteamworksBot.commands;

import java.util.Timer;

import org.usfirst.frc5858.SteamworksBot.Robot;

import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 *
 */
public class DebugAutoCommandOne extends Command {

	// we're using 8 so we can use 9 later during a sequential operation!
	public String debug_output = "DB/String 9";
	double start_time;
	double elapsed_time;
	
    public DebugAutoCommandOne() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
    	requires(Robot.drivetrain);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    	SmartDashboard.putString(debug_output, "Debug one INIT.");
    	start_time = System.currentTimeMillis();
    	
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	elapsed_time = System.currentTimeMillis() - start_time;
    	SmartDashboard.putString(debug_output, "Debug 1 : " + elapsed_time + " ms");
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
    	SmartDashboard.putString(debug_output, "Debug one DONE.");
        return elapsed_time - start_time >= 2.0;
    }

    // Called once after isFinished returns true
    protected void end() {
    	SmartDashboard.putString(debug_output, "Debug one END.");
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    	SmartDashboard.putString(debug_output, "Debug one INTERRUPTED.");
    }
}
I *never* see any indication it's running, either in the debug boxes OR by debugging and setting breakpoints. It never hits any of the breakpoints at all.. am I missing something that's not covered in the wpilib documentation?
Reply With Quote
  #2   Spotlight this post!  
Unread 01-02-2017, 22:58
trycatch's Avatar
trycatch trycatch is offline
Registered User
FRC #5858
 
Join Date: Nov 2015
Rookie Year: 2015
Location: AL
Posts: 44
trycatch is on a distinguished road
Re: Autonomous won't do *anything* ?

Okay, ignoring the dumb typo in my math above (which didn't explain why I was never hitting to break point to evaluate it), the issue seems to be with having setDefaultCommand in a few subsystems - evidently having setDefaultCommand prevents queued commands from running at all..?

EDIT: Note, I cleaned my code up a little above and got rid of subsystems I didn't think mattered.. but I have a drivetrain subsystem and a computer vision networking subsystem, and if I setDefaultCommand in either one of them, my Autonomous command is never called.. this is very strange..

Last edited by trycatch : 01-02-2017 at 23:05.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2017, 00:13
mreynolds's Avatar
mreynolds mreynolds is offline
Team Captain | Head of Controls
AKA: Matthew Reynolds
FRC #4946 (The Alpha Dogs)
Team Role: Programmer
 
Join Date: Sep 2015
Rookie Year: 2014
Location: Ontario, Canada
Posts: 12
mreynolds is an unknown quantity at this point
Re: Autonomous won't do *anything* ?

The first thing that immediately pops up to me is that you've got some funky stuff going on with your time calculations. Firstly, you're subtracting start_time from elapsed_time twice, once in execute() and once in isFinished(). You should drop it out of isFinished(), changing your return statement in isFinished() to just
Code:
return elapsed_time >= 2.0;
The other issue is there, with your comparison. System.currentTimeMillis() gives values in just that; milliseconds. Your comparison checks to see if 2ms have passed, not 2sec as I'm guessing you were probably going for. You could change your code to be return elapsed_time >= 2000; if you're going for 2 seconds, or you could drop the use of System.currentTimeMillis() altogether and just use a WPILib Timer:

Create the Timer as you would any other object,
Code:
Timer timer = new Timer();
In initialize(), you should reset your timer to 0 seconds, and then start it
Code:
timer.reset();
timer.start();
in isFinished, change your code to
Code:
return timer.get() > 2;
**Note that the Timer object works in Seconds, not Milliseconds!

And lastly, to keep things tidy, you can throw a timer.stop(); into your end() and interrupted() methods if you want.


I'm not entirely sure why your current code isn't doing anything, but these are a couple of things that should be cleaned up to get the debugging started.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-02-2017, 00:14
msonnier msonnier is offline
Engineering Mentor
FRC #2992 (SS Prometheus)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: United States
Posts: 10
msonnier is an unknown quantity at this point
Re: Autonomous won't do *anything* ?

Is your default command Interruptible? If the default command on the subsystem is not Interruptible, then any new commands including your Autonomous command will not execute until that default command ends.

Since what you have is a drivetrain, I'm guessing your default command does some kind of Teleop read of the joysticks to drive the bot around -- and probably will never terminate on its own. You may need to make sure this default command can be interrupted by using the setInterruptible(boolean interruptible) method.

Without seeing the code of your default command, however, it's hard to tell whats going on in your case.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-02-2017, 08:48
trycatch's Avatar
trycatch trycatch is offline
Registered User
FRC #5858
 
Join Date: Nov 2015
Rookie Year: 2015
Location: AL
Posts: 44
trycatch is on a distinguished road
Re: Autonomous won't do *anything* ?

Argh, yeah, I bet that's it. I had no idea you had to setInterruptable.

And yeah, the timing stuff I had just thrown together ultra quick, I found the dumb bugs in that pretty fast.
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 12:54.

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