Go to Post ...It's like Christmas morning and waiting to see if Santa got you that soldering iron you wanted. - CLandrum3081 [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #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.
  #2   Spotlight this post!  
Unread 04-03-2014, 16:44
Whippet's Avatar
Whippet Whippet is offline
MIT Class of 2020
AKA: Luis Trueba
FRC #4301 (New Tech Narcissists)
Team Role: Alumni
 
Join Date: Feb 2011
Rookie Year: 2011
Location: Cambridge, MA
Posts: 1,187
Whippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond repute
Send a message via Yahoo to Whippet
Re: No Robot Left Behind 2014

Alright, I'll bite:


(Add this to your current code. Anything already there can remain. Replace any instances of "chassis" with the name of your drivetrain object.)
Java SimpleRobot:

Declaration phase:

Code:
import edu.wpi.first.wpilibj.Timer;
Autonomous mode:

Code:
public void autonomous ()  {
   chassis.setSafetyEnable(false);
   chassis.drive(-.5,0);
   Timer.delay(2.0);
   chassis.drive(0,0);
__________________
2010: FRC 3043, Build Assistant
2011: FRC 3043, Head of Minibot subteam; FLL 12762, Team Captain
2012: FRC 3043, Electrical; FLL 12762, Team Captain; FTC 5670, Team Captain
2013: FRC 4301, Electrical, Team Co-Captain
2014: FRC 4301, Electrical/Programming, Team Co-Captain
2015: FRC 4301, Electrical/Programming, Team Captain
2016: FRC 4301, Chief Technical Officer; FTC 10860, 10861, and 11004: Mentor. Winner, Hub City Regional (3310 & 4063)

Last edited by Whippet : 04-03-2014 at 16:47.
  #3   Spotlight this post!  
Unread 04-03-2014, 16:45
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: No Robot Left Behind 2014

Iterative Robot:

Code:
public class RobotTemplate extends IterativeRobot {

    /**
     * This function is called at the beginning of autonomous
     */
    private static final long DRIVE_FORWARD_TIME_IN_MILLS = 0;
    private static final double DRIVE_FORWARD_SPEED = .2;
    private long startTime = 0;
    public void autonomousInit() {
        startTime = System.currentTimeMillis();
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        //drive forward for the first n milliseconds of autonomous
        if(System.currentTimeMillis() - startTime  < DRIVE_FORWARD_TIME_IN_MILLS){
            drive.driveForward(DRIVE_FORWARD_SPEED);
        }else{
            drive.stop();
        }
    }

}
__________________
"Never let your schooling interfere with your education" -Mark Twain
  #4   Spotlight this post!  
Unread 04-03-2014, 16:48
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: No Robot Left Behind 2014

Simple Robot:

Code:
public class RobotTemplate extends SimpleRobot {
/**
     * This function is called once each time the robot enters autonomous mode.
     */
    private static final long DRIVE_FORWARD_TIME_IN_MILLS = 0;
    private static final double DRIVE_FORWARD_SPEED = .2;
    private long startTime = 0;
    public void autonomous() {
        startTime = System.currentTimeMillis();
        
        while(isOperatorControl() && isEnabled()){
            
            //drive forward for the first n milliseconds of autonomous
            if(System.currentTimeMillis() - startTime  < DRIVE_FORWARD_TIME_IN_MILLS){
                drive.driveForward(DRIVE_FORWARD_SPEED);
            }else{
                drive.stop();
            }
            Timer.delay(0.01);
            
        }
        
    }
}
__________________
"Never let your schooling interfere with your education" -Mark Twain
  #5   Spotlight this post!  
Unread 04-03-2014, 17:21
Woolly's Avatar
Woolly Woolly is offline
Programming Mentor
AKA: Dillon Woollums
FRC #1806 (S.W.A.T.)
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Springfield, MO
Posts: 512
Woolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond repute
Re: No Robot Left Behind 2014

Here's a Labview autonomous based on a 4CIM tank drive.
Motors can be easily added and removed as needed. Be sure to look at the comments, and configure begin correctly.
Attached Thumbnails
Click image for larger version

Name:	drive forward autonomous screenshots.jpg
Views:	77
Size:	856.3 KB
ID:	16477  
Attached Files
File Type: vi Autonomous Independent.vi (48.5 KB, 3 views)
__________________


Team 1806 Student: 2012-2013 | Mentor: 2013-Present
  #6   Spotlight this post!  
Unread 04-03-2014, 17:27
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: No Robot Left Behind 2014

Here's a python sample for a standard two-motor robot. You can test it using the pyfrc robot simulator.

Code:
try:
    import wpilib
except ImportError:
    from pyfrc import wpilib

class MyRobot(wpilib.SimpleRobot):

    def __init__(self):
        super().__init__()
        
        self.stick = wpilib.Joystick(1)
        
        # two wheel drive
        l_motor = wpilib.Jaguar(1)
        r_motor = wpilib.Jaguar(2)
        self.drive = wpilib.RobotDrive(l_motor, r_motor)

    def Autonomous(self):
        '''Called when autonomous mode is enabled'''
        
        timer = wpilib.Timer()
        timer.Start()
        done = False
        
        self.GetWatchdog().SetEnabled(False)
        while self.IsAutonomous() and self.IsEnabled():
            
            if not done and not timer.HasPeriodPassed(5):
                self.drive.ArcadeDrive(0.4, 0)
            else:
                self.drive.ArcadeDrive(0, 0)
                done = True
            
            wpilib.Wait(0.01)

    def OperatorControl(self):
        '''Called when operation control mode is enabled'''
        
        dog = self.GetWatchdog()
        dog.SetEnabled(True)
        dog.SetExpiration(0.25)

        timer = wpilib.Timer()
        timer.Start()

        while self.IsOperatorControl() and self.IsEnabled():
            dog.Feed()
            self.drive.ArcadeDrive(self.stick)
            wpilib.Wait(0.04)

def run():
    '''Called by RobotPy when the robot initializes'''
    
    robot = MyRobot()
    robot.StartCompetition()
    
    return robot


if __name__ == '__main__':
    wpilib.run()
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #7   Spotlight this post!  
Unread 04-03-2014, 21:39
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,756
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: No Robot Left Behind 2014

I attached two images. First is the code from the upper disabled structure already in the Autonomous VI. It was given different speeds and delay values. It assumes that you opened a two or four motor drive in Begin and named it "Left and Right Motors". If you happen to have a six wheel robot without Y-cables, you can also use both a 2 and 4 motor drive in parallel.

I also moved the code to the local computer target and ran it in the simulator. The image shows what that is like. This lets you compare your wiring to the robots wiring and work out motor inversions, positive/negative values, etc. Clearly, I wouldn't trust the distance the robot will travel will match your real robot, but it is something to practice with.

Greg McKaskle
Attached Thumbnails
Click image for larger version

Name:	From Clipboard.png
Views:	49
Size:	107.6 KB
ID:	16482  Click image for larger version

Name:	From Clipboard1.png
Views:	69
Size:	494.5 KB
ID:	16483  
Closed Thread


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 02:34.

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