Setting a delay to a motor

We will check your revised code if you would post it. (either a screen shot or a snippet-highlight code, choose “Create VI Snippet from Selection” and it’ll create an image that’s actual code)

Did you place the code in the Periodic (That’s required because of the loop)

Do you call your servo anywhere else? (other calls can/will override the calls in this loop)

Here’s the snippet (For reference, the servo is the one I want to go immediately and the elevator motors are what I want to delay)

Suggest that you add another sequence tab at the end to turn the motors off.

I’m assuming that safety config for these motors is turned off since they are not being written to periodically?

It’s probably lucky that it didn’t work.
You forgot to stop the elevator motors, so they would run forever.

This is in the Periodic

You needed to add in a while button is held check.
The servo would not move if it’s already at the 120 degree position.
Angles are in integer units, rather than floating point.
A half second might not be a long enough time to give a servo to move, but it ill continue to move as the elevator starts.

Something along these lines:

The last reply looks like a really good example. In case you wanted another way to do the same thing, I put another sample below. This one doesn’t block using waits. Instead it starts a timer and checks for completion to start the delayed action. (Instruction on how to make the timers and edge detection are in the book referenced above.)

The False case looks like this.

Operationally the examples do the same thing. The biggest difference is that this one doesn’t block. So it writes a value to the motors every 20 milliseconds.

Good luck!

In this example that you’ve shared, we see the SECRET .vi’s (Edge on, Timer Start, Timer Done?) Are these vi’s available for download? I downloaded the 2020 Secret Book Robot project, and I don’t find them there. Any help is appreciated.


While updating the book, I did create the library associated with the problems. However, I’ve been conflicted about if it is appropriate to provide this since I’m a mentor. I updated the book and added the problems for the library routines so students could learn to create these routines for themselves. I’d really like to hear the thoughts of others on this subject!!!

That being said. The EdgeOn, Time Get, Timer Start, and Is Timer Done subVIs are all fairly easy to create.

Edge On. This is problem 1.4 in the Secret book of LabVIEW 2.x) The truth table for this function can be found in Appendix A. A sample of the logic used in this subVI is found in figure 5.14. The feedback node used in this logic is described in Chapter 1.

Time Get (Used by Timer Start and Is Timer Done) , Timer Start, and Is Timer Done are described in Chapter 2, and problems 2.1, 2.2, 2.3. Compare figures 2.2 and 2.3 to get an idea of the logic that is needed for these.

Here are the steps needed to create your own subVI. (This is throughout chapter 1).

  1. create a new VI.

  2. On the front panel of the new subVI create the input “Controls” (in subVIs, “Controls” are inputs, “Indicators” are outputs) needed for the subVI you are making. Usually inputs are placed on the left. Double click on the default label and type a new name to change the label name.

  3. On the front panel of the new subVI create the output “Indicators”. Usually outputs are placed on the right. Double click on the default label and type a new name to change the label name.

  4. Now create terminals for your inputs (controls) and outputs (indicators). To do this, left click on the terminal you want to use, then left click on the control or indicator to associate with that terminal. The terminal template is shown in the right corner of the front panel.
    Again inputs are on the left and outputs on the right. (This is not mandatory, but it is a lot easier
    to read when the data all flows left to right.) For one input and one output the terminal template would look like this when done. (Yours may look different if you selected different locations. That is okay.) image

  5. For inputs, right click on the input terminals and select “This connection → is required” This will cause an error if you use this subVI and forget to wire an input. This will save you a lot of time debugging!!!.

  6. Switch to the block diagram and add your logic.

  7. Save the file. Give a name that has meaning so you can find it. Also make certain you know in what directory the file is being saved!. Best to keep the files inside the directory of your project (unless using libraries.)

  8. Create an Icon for this subVI. On the front panel, double click the default icon to edit the icon.
    Simple icons that let you know what this is are often the best. Often just the name of the function is enough.
    Completed sample

  9. Set the execution parameters. On the menu, select FILE, then select VI PROPERTIES.

Select the EXECUTION category and change the settings to look like this.

  1. Save the subVI!! (I’m calling it a subVI because it can be used by other VIs. However there really isn’t a difference between VI and subVI.)

Test and use.

Hope this helps this to create these routines.

(The link to the book is above, but just in case here it is.)

Thank you very much! This is excellent help, and a great tutorial that explains the subVI concept and implementation.

For this to work, would I have to disable the elevator motors in teleop? Or remove them from teleop entirely? I tried this example in the code, but it seems like the loop doesn’t activate at all (As in, the elevator works when the button is pressed but there’s no delay and the servo doesn’t activate)

As for @JSIMPSO , that looks very interesting! I’ll definitely give it a try

You can’t command the elevator in two different places.
Both Teleop and Periodic Tasks are running at the same time, so the elevator would get conflicting orders and whatever Teleop is doing would win.

I removed the elevator stuff in teleop and it worked like a charm! Thanks!

A side note: I usually program limit switches in teleop, but since I can’t use teleop for these elevators, is there a way to do limit switches where it doesn’t interfere with periodic tasks? (EX: When DIO 1 is activated, cancel the elevator loop)

You can put everything in Periodic Tasks.
Treat it just like Teleop, but with the code in forever loops.
You’d want to check the elevator limit switches during the automatic jobs, too.

So would that be like this?

That only checks the elevator limits before it starts, not while it is going.

I’d probably move the limit Get and both the motor Set Outputs into that little loop in the second frame.
Then it checks every 20ms and stops the motors as long as button 6 is held down.

Is this right?

The motor set outputs need to be inside that little loop also, so they can be turned off when the DIO says so.
So everything you now have in the second frame needs to be inside that loop.

I tried this, but the elevator motors don’t activate, only the servo (not sure if I connected them right)

For the sake of clarity, these limit switches have to be in periodic tasks, right? (I’m really sorry for dragging this on for so long, maybe I should make a new topic for it at this point…)

I’m away from my computer right now, so I can’t test your code.
I suggest running this through highlight execution or probing the wire values to see if the limit switch is set for the correct direction.

The way you have it assumes the limit switch is wired Normally Closed.
There are two ways the switch can work :slight_smile:

  1. Normally Open (returns true when not depressed)
  2. Normally Closed (returns false when NOT depressed)

See if the limit switch value is what you think it should be.
You can add a DIO Get just in the main loop for you to watch the limit switch value without having to trigger the whole sequence.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.