Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Teleop move motor forward and backwards timed (http://www.chiefdelphi.com/forums/showthread.php?t=124785)

joecloud 16-01-2014 22:35

Teleop move motor forward and backwards timed
 
1 Attachment(s)
My goal is that when button 7 is pressed, that the motor will move forward at full speed for 1 second, then stop. wait .5 seconds, then move in reverse at half speed for 1.5 seconds. I just wanted to get some feedback on the code and what I could do to make it less cluttered, and possibly more effective (I haven't had a chance to upload it to the bot yet, I will Saturday. )

Attachment 15851

Button 7 is supposed to toggle on/off and start the sequence structure, am I doing it right? :confused:
Thanks!

Also, build team mentioned that they're going to throw another motor on the gearbox that this motor is currently on, so 2 motors will be working together for more power! :D
I was wondering what would be the best way to add a second motor to the sequence? Should I set up an 'Open2Motor' so that they only need one block? Or should I just add the 2nd motor to the case structure (Have separate motor get for the 2 motors)?

Thanks a ton,

Mark McLeod 16-01-2014 22:55

Re: Teleop move motor forward and backwards timed
 
The sequence looks okay, but has a few problems.

The Joystick button will never change, because the Get is outside the While loop. You'll keep using the value of the button at the time the loop first started.
Just add another Joystick Get inside the While loop.

The cimtest RefNum Get would be better outside the While loop and wired in to Motor Set Output. The RefNum is something that doesn't change, so you don't have to keep retrieving it everytime.

I'd increase the Timer to 20ms, because that's as fast as the button can possibly change.

The button 7 check looks good, but since the wires are on top of one another it's hard to be positive.

Cecil 16-01-2014 23:06

Re: Teleop move motor forward and backwards timed
 
Wouldn't having a while loop in Teleop slow the entire Teleop loop down to the point it would start cutting out? I thought that all loops had to go in Periodic Tasks to run correctly.

Other than the other things that Mark pointed out, it looks good to me.

Mark McLeod 16-01-2014 23:15

Re: Teleop move motor forward and backwards timed
 
That's true.
Everything looks good if you drop that as is (with corrections) into the Periodic Tasks.vi

Greg McKaskle 17-01-2014 08:22

Re: Teleop move motor forward and backwards timed
 
I think you'll also discover that you will want a fourth step, to stop the motor after the 1.5 seconds. And as Mark said, if you take the motor reference out of each sequence and wire it across, the code will be smaller and cleaner.

By the way, putting this into teleop wouldn't simply slow it down. If you place an infinite loop into a function, the function becomes, ... , ...? Yep, it becomes infinite as well. So by placing an infinite loop in teleop, you would only call telop once and your teleop portion of your program would pretty much lock up waiting for the loop to finish.

Greg McKaskle

joecloud 17-01-2014 13:44

Re: Teleop move motor forward and backwards timed
 
Alright thank you all for all the help. Making the edits right now. Just wanted to confirm one thing, since we are adding a second motor should i set up an open 2 motor for the 2 motors instead of adding another single motor get to the loop? The second motor is supposed to function just like cimtest.

Thanks again,

Joe Ross 17-01-2014 14:29

Re: Teleop move motor forward and backwards timed
 
Quote:

Originally Posted by joecloud (Post 1328508)
Alright thank you all for all the help. Making the edits right now. Just wanted to confirm one thing, since we are adding a second motor should i set up an open 2 motor for the 2 motors instead of adding another single motor get to the loop? The second motor is supposed to function just like cimtest.

Open 2 motors is part of the robot drive palette for controlling drivetrains, where both sides of the drivetrain get different commands. It isn't appropriate for use for two motors that need the exact same command. Just open a second motor and send it the same command.

Greg McKaskle 17-01-2014 14:30

Re: Teleop move motor forward and backwards timed
 
I believe your choices are to open a second motor and set it to the same values in each sequence, or you can send out one signal and duplicate it using a Y cable.

Greg McKaskle

joecloud 17-01-2014 16:53

Re: Teleop move motor forward and backwards timed
 
1 Attachment(s)
I'll look into the Y-cable, we may or may not already have one.
Here is the code after the suggested modifications.
If I understand this correctly, because the code was originally in teleop it would have kept auto repeating whatever was in the loop forever? :ahh:

Attachment 15855

This is the updated code in Periodic tasks, are there any global variables etc.. of the sort that I need to setup for it to function right? Or does periodic tasks work seamlessly in teleop mode (haven't done much periodic tasks code)


Thanks,

Mark McLeod 17-01-2014 18:18

Re: Teleop move motor forward and backwards timed
 
Looks good.
The last 500 ms Timer isn't necessary. There's nothing to wait for by that point. It'll just prevent the button from working again right away.

Periodic Tasks runs all the time. While Teleop is running, while Disabled even (but the motor outputs are what get disabled, so you won't see any motor move).

Don't try to use cimtest anywhere else now, since it's always going to be in use waiting for that button press.


All times are GMT -5. The time now is 09:54.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi