Go to Post Many people here in the CD fora know 'someone' on the inside. They aren't out there somewhere, they are here among us and they won't give an inch regarding the clues. It's very cool. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
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 13-02-2010, 11:06
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
sample code to move robot autonomously

I am a neophyte with labview, would anyone be willing to send a small autonomous code to simply move a robot. I have downloaded the default code but all i get when i push the autonomous button on the drivers station is that the watchdog is not fed.
any help is greatly appreciated

thanks john
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2010, 15:15
Luke Pike's Avatar
Luke Pike Luke Pike is offline
Programmer
FRC #1501 (THRUST)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Huntington
Posts: 114
Luke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to all
Re: sample code to move robot autonomously

Instead of just giving you code, I'm gonna tell you how to do it too.

If you didn't change anything in the default code, the autonomous code will be located in the "Autonomous Independent.vi". This VI gets run once when autonomous is turned on using the driver station.

So, you should have a while loop (a grey-bordered box) and some other junk in there. Delete all the stuff inside and outside the while loop EXCEPT the watchdog code. We're gonna make a state machine which moves the robot for a time period and then stops. Now, you might ask if a state machine's a little overkill for just moving a robot. It might, but state machines can be easily extended to do more stuff, which I assume you're going to do.

So, right-click the area inside the while loop and select structures->case structure. Make this pretty big inside the loop.

Now, right-click to the left of the while loop and select numeric->enum. This will hold all the states our machine will handle. When you drop this on the block diagram, right-click it and select "Edit Items...". In the window that pops up, enter two items, "Move" and "Stop". That's pretty basic, but we'll go with that for now.

Once that's done, make sure its outside the while loop and to the left. Click the right-most side of the enum and wire it into the "?" box of the case structure we created earlier. This will create a tunnel through the while loop. Right click the tunnel and select "Replace with Shift Register". This changes the tunnel into a bigger box with another one just like it on the opposite side of the while loop. Whatever goes into the right side of the shift register comes out the left side on the next iteration. This allows us to save our state between while loop runs.

Now for the fun bit. Go to the "Move" case in the case structure. I'm not sure how you have your drive set up, but if the default code works, just copy the drive code from the "Teleop" VI (including the get from registry) and paste it inside the "Move" case of the case structure. Right click the "Y axis value" input and select create constant. Type some value in here, like 0.5. Do the same for the "X axis value" input, but put 0.

Since we want to move the robot for a time period then stop, we'll need a timer. Luckily for us, there's one for us to use. Right click inside the case structure and select timing->elapsed time. Place it inside the case structure and a dialog will pop up. Enter a time or leave it at the default 1 second. You'll notice the blue box has an boolean output labeled "Time has Elapsed". When this is true, we need to move to the "Stop" case of our state machine.

Okay, some stuff we need to do that might not make sense now, but needs to be done. Right click and select comparison->select and place it inside the case structure. Wire the "Time has Elapsed" output of the elapsed time into the middle input of the select function.

Copy the enum from outside the while loop and paste it into the case structure. Click on it and select "Stop". Wire that into the top input of the select function (the true input). Next, find where the little blue "?" box is on the case structure. You'll notice you can drag a wire off it. Wire this into the lower input of the select function (the false input).

We're almost done, wire the one output of the select function into the right side of the shift register. Copy the drive code and paste it into the "Stop" case. Change all the inputs to 0. Wire the "?" of the case structure into the right side of the shift register. Finally, right click and select boolean->true constant and drop it inside the "Stop" case. Wire this into the red stop box of the while loop. Right click the tunnel it creates in the case structure and select "Use Default If Unwired".

What have we done? Well, we stay in the "Move" state until the timer indicates 1 second has passed. Then, we move to the "Stop" case which stops the robot and ends the loop. You can change and add more states to do more complicated stuff if you want.

I've attached the code so you can look at it and get a feel for how it works. Hope this helps.
Attached Files
File Type: vi Autonomous Independent.vi (28.4 KB, 235 views)
__________________
Twitter Profile
Reply With Quote
  #3   Spotlight this post!  
Unread 14-02-2010, 07:38
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: sample code to move robot autonomously

well i am at home right now, but will try in in about 2 hours when i go to school
thanks much and yes i hope it works too,
thanks alot for the instructions
john
Reply With Quote
  #4   Spotlight this post!  
Unread 14-02-2010, 09:54
Dustin Shadbolt's Avatar
Dustin Shadbolt Dustin Shadbolt is offline
In a server room somewhere...
AKA: Dustin Shadbolt
FRC #1555 (Team PULSE)
Team Role: Alumni
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Monticello,Indiana
Posts: 320
Dustin Shadbolt is on a distinguished road
Re: sample code to move robot autonomously

nice post luke thanks!
Reply With Quote
  #5   Spotlight this post!  
Unread 14-02-2010, 15:13
grosh grosh is offline
Registered User
FRC #2147
 
Join Date: Feb 2008
Location: Spokane, WA
Posts: 100
grosh is an unknown quantity at this point
Re: sample code to move robot autonomously

THANKS!!!!!!!!!!!!!!!!!!

We have been trying to complete something similar without success. Your simple explanation w/example code is exactly what we are looking for.

Professional Graciousness are its best!
Reply With Quote
  #6   Spotlight this post!  
Unread 14-02-2010, 21:32
Chris_Elston's Avatar
Chris_Elston Chris_Elston is offline
Controls Engineer
AKA: chakorules
FRC #1501 (Team THRUST)
Team Role: Engineer
 
Join Date: Feb 2004
Rookie Year: 2001
Location: Huntington, Indiana
Posts: 747
Chris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond reputeChris_Elston has a reputation beyond repute
Re: sample code to move robot autonomously

great post Luke.
__________________
Team T.H.R.U.S.T. 1501
Download all of our past robot's source code here:Repository

Favorite CD quote:
"That can't be their 'bot. not nearly enough (if any) rivets to be a 1501 machine." ~RogerR: Team #1369
Reply With Quote
  #7   Spotlight this post!  
Unread 15-02-2010, 08:12
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: sample code to move robot autonomously

Luke it worked great thanks a bunch

I was wondering if I want to add a solenoid action at the end of say 2 seconds of the motor motion do i just tag that on with in the case loop?
or would i have to make another cas loop?

thanks again for all your help.
john
Reply With Quote
  #8   Spotlight this post!  
Unread 15-02-2010, 14:09
Luke Pike's Avatar
Luke Pike Luke Pike is offline
Programmer
FRC #1501 (THRUST)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Huntington
Posts: 114
Luke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to all
Re: sample code to move robot autonomously

Great, glad it worked!

If you want to add more functionality, you can add more states. Just right click on the enum outside the while loop, select "Edit Items...", and add an item. For your case, call it "Fire Solenoid" or something more descriptive of what that does.

As soon as you do this, you'll notice that the enum inside the case structure breaks. This is because the enum changed and the old one is different. It's not that hard to delete the old enum and copy in a new one (making sure the value is the same as before) for this state machine, but as it gets more complicated, it can be a real pain.

To solve this, we can make our enum a typedef. This means that when we change it, any other instance of it, in any location, gets updated as well. To change our enum into a typedef, first right click it and select "Change to Control". Go to the front panel and right click the enum and select "Advanced->Customize". This puts our enum in a new window. You'll notice at the top a pop down which is set to "Control". Click this and change it to "Typedef". Save the typedef, giving it some meaningful name like "State Machine Enum" or something like that. After you close that window, it will ask you if you want to replace the control with the typedef. Hit yes, and change the enum back into a constant by switching to the block diagram and reversing what you did to change it into a control. Now use copies of this enum to switch cases in the state machine. To add more states, right click the constant and select "Open Typedef". Make your changes, then save. All the other constants with that typedef are updated.

Okay, now that that's out of the way, we can add a case to our case structure to activate a solenoid. If you want to wait for a period of time after you stop the robot, you can copy the code from the first state and paste it into the "Stop" case. Change the enum that is passed into the shift register to the new state. Or, you can switch to the solenoid case right after the "Stop" case. Just delete the wire and use an enum constant set to the solenoid item.

To add the solenoid state to our case structure, right click it and select "Create Case for Every Value" (I think that's what it's called). Go to the new case and paste your solenoid code.

A few notes:

Shift registers need something wired into them always, which is why I wire the value from the "?" box of the case structure into the shift register even though it's the last case.

Remember, a state machine does something until a condition changes (a digital input changes, an encoder value goes above some number, etc.), then goes to a new state. It doesn't even have to be the next one, which allows for some pretty cool abilities.
__________________
Twitter Profile
Reply With Quote
  #9   Spotlight this post!  
Unread 15-02-2010, 15:24
Andrew0089 Andrew0089 is offline
Registered User
FRC #3229
 
Join Date: Jan 2010
Location: North Carolina
Posts: 12
Andrew0089 is an unknown quantity at this point
Re: sample code to move robot autonomously

THANK YOU SO MUCH! We are a rookie team and we just need a bunch of help! and once we understand these examples it will help us expain it to other teams in our area! =D
Reply With Quote
  #10   Spotlight this post!  
Unread 15-02-2010, 15:52
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: sample code to move robot autonomously

If you have LEGO programmers who worked in Robolab, there is another way they might appreciate.

Create a VI for each main action - Drive X Distance, Turn X degrees, etc. It will be a blocking VI that is called once and expected to perform an action. It contains its own while loop and runs until it has reached its destination.
Then, create a "Flow" control and indicator on each one. Make the control and indicator inputs and outputs by right-clicking on the icon on the front panel, clicking "Show Connector". Click the position in the grid where you want the input to show up, then click the input. It will now appear the color of the data type. Do the same for the indicator (output). It dosen't matter what data type it is, I use Double because I like orange, but anything works.
In Autonomous Independent, place the blocks in the order of what you want to do. E.G. Drive_Straight for 18 inches, Turn -90 degrees, Drive_Straight 36 inches, etc.
Wire the Flow from one VI to the next in the order you would like them to execute. Since data must move from one VI to the next (Whatever data is on the Flow wire), LabVIEW will make the VI's execute sequentially.
Done. You might want to put common actions, such as wait x time or set kicker to kick in VI's too, just so you have a flow wire to wire between them.

I have a picture of an example. I don't have icons on my VI's since the graphics team is still making them, but I did label them in comments. I also put my VI's in a palatte, but that is more advanced and not really necessary.

I also posted my Drive Straight Vi.

If you prefer the loop-based method shown in previous posts, you can put it in Autonomous Iterative and it will be called at 50hz. You will need to replace the shift register with either a front panel control (local variable) or global variable.
Attached Thumbnails
Click image for larger version

Name:	auton_example.png
Views:	163
Size:	45.6 KB
ID:	8685  
Attached Files
File Type: vi drive_straight.vi (16.0 KB, 23 views)
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack

Last edited by apalrd : 15-02-2010 at 15:56.
Reply With Quote
  #11   Spotlight this post!  
Unread 15-02-2010, 16:37
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: sample code to move robot autonomously

gosh thanks to Luke and parady

these are very very helpful and well explained, i am trying them as soon as i type
thanks again John
Reply With Quote
  #12   Spotlight this post!  
Unread 15-02-2010, 18:09
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: sample code to move robot autonomously

luke i think i did what you instructed, it was alittle hard to follow but it
did not work, i am attaching the auto inde code. maybe you could look at it if you get a chance and let me know what to do next.
thanks John
Attached Files
File Type: vi Autonomous Independent.vi (30.7 KB, 26 views)
Reply With Quote
  #13   Spotlight this post!  
Unread 15-02-2010, 20:22
Luke Pike's Avatar
Luke Pike Luke Pike is offline
Programmer
FRC #1501 (THRUST)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Huntington
Posts: 114
Luke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to allLuke Pike is a name known to all
Re: sample code to move robot autonomously

johncap100,

You are almost there, just some things that were a little off that I didn't explain. I changed your code so you can see.

First, all the booleans wired into the stop box are all true. This means that as soon as the code runs, it stops the loop. Make all of them false except the one in the last case. This makes sure that we stop the loop only when we are done. In fact, you could just wire a false all the time. Just delete all those booleans and create one false boolean outside the case structure and wire that into the stop box. This will keep the code running until someone stops autonomous mode. This is probably better anyway, since you will probably be doing stuff right until the end

Second, in the "stop" case, you never wire a new state into the shift register, you just pass the old one back through. In order to go to the next state, you have to wire a constant set to the state you want to move to. Every state should have a way to move to another, except possibly the last one, where you don't want to ever go to another state.

Other than that, you pretty much nailed it. Should work, I had to disconnect the typedef since I didn't have that file, you can replace the constants with your typedef by dragging the file into the block diagram as many times as you need.
Attached Files
File Type: vi Autonomous Independent.vi (30.9 KB, 59 views)
__________________
Twitter Profile
Reply With Quote
  #14   Spotlight this post!  
Unread 16-02-2010, 07:13
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: sample code to move robot autonomously

ok great thanks much and thanks again for taking time.
this neophyte really needs the help
i will try it today
thanks john
Reply With Quote
  #15   Spotlight this post!  
Unread 16-02-2010, 15:47
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: sample code to move robot autonomously

HI Luke me again well i think i followed your instructions but no go on the solenoid part, it moves ahead fine, but no solenoid action.
I have the solenoid actuated by button one on one of the joysticks in teleop and it works fine there, but I cannot see where in autonomous where we are actually causing the solenoid to actuate. shouldn't there be a place to do that? Liek maybe call a button or something?

what i did was create another sample and started from the beginning including the solenoid case. but still no go.

I was wondering if you would be so kind as to maybe walk me through the steps again?
I am not real confident that i followed your last instructions on adding a case real well.
thanks a bunch
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
sample code johncap100 NI LabVIEW 2 01-02-2010 08:18
Missing sample code ajdecker1022 Java 3 28-01-2010 19:39
Sample Code Belly Programming 1 21-01-2010 14:34
Sample Code Japper Programming 2 01-12-2008 22:36
Sample PID code??? EHaskins Programming 14 08-08-2006 14:18


All times are GMT -5. The time now is 14:13.

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