Go to Post I think overcoming obstacles together builds a stronger team. - MissInformation [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 04-03-2014, 16:35
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 947
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
No Robot Left Behind 2014

I was thinking this week about an old thread I remembered in 2008. For anyone who doesn't know or doesn't remember the 2008 game, robots could gain points by simply driving forward in autonomous. Now, in 2008, there was less space and a longer distance to drive, but it was still very doable for almost any team. That year, there was a thread urging teams to help other, perhaps more inexperienced teams, out there and moving in auto, and I'd like to encourage this for Aerial Assist.

What I would like from this thread are easy ways, in your language/template/architecture of choice, to make a robot drive forward for a certain amount of time, then stop. This will provide teams with extra members or bored programmers with a nice palette of solutions from which to draw from for certain situations to help teams drive forward then stop!

Please list assumptions (I think the team being able to drive and having code for that is a safe assumption, but not a ton else).

I'll start first, with Command-Based Java.

Assumptions:
  • CommandBase already has a subsystem for the drive, named drive.
  • drive has a method called driveForward(double speed) which uses the elements of the Subsystem to drive the robot forward at the argued speed. This might be something you need to work with the team to implement, or use their existing methods in another way to do the driving.
  • drive has a method called stop() which stops all drive motors. This might be something you need to work with the team to implement, or use their existing methods in another way to do the stopping.

You'll want a command to do the driving forward and stopping:

Code:
package sample;

import edu.wpi.first.wpilibj.Timer;

public class DriveForwardThenStop extends CommandBase {

    Timer timer;
    double time;
    double speed;

    public DriveForwardThenStop(double seconds, double speed) {
        requires(drive);
        timer = new Timer();
        time = seconds;
        this.speed = speed;
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        drive.stop();
        timer.start();
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        drive.driveForward(speed);
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return (timer.get() > time);
    }

    // Called once after isFinished returns true
    protected void end() {
        drive.stop();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        end();
    }
}
And you'll need to run that command during autonomous in the main robot class. Adjust arguments to the command based on robot behavior. Try it out on the practice field!

Code:
...

class ExampleRobot extends IterativeRobot{

...

    Command autonomousCommand;

...

    public void robotInit() {
        autonomousCommand = new DriveForwardThenStop(2.0, 0.5);

        // Initialize all subsystems
        CommandBase.init();
    }

    public void autonomousInit() {
        autonomousCommand.start();
    }

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

}
Anyway, have at it! Here's a list of common frameworks that we could use examples of solutions in:
  • IterativeRobot Java
  • SimpleRobot Java
  • CommandBased C++
  • IterativeRobot C++
  • SimpleRobot C++
  • LabVIEW (not sure if there are multiple templates/architectures
  • Python?

P.S. Make sure you remember to stop!

Last edited by BigJ : 04-03-2014 at 16:37.
 


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 21:55.

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