Scaling motor speed in LabVIEW

How would you layout the code used to program a motor to gradually speed up as you hold down a button?

I have attached code that should do what you want. The while loop is obviously unnecessary if you have this in Teleop or Period Tasks. This code will save the elapsed time of the program to a local variable while a button (the Boolean input) is not pressed. When the button is pressed, it will find the difference between the time at the moment the button was pressed and the current time. This is then divided by a constant to give an output your motor can use.

Let me know if you have any questions.

Incremental Motor Speed.vi (8.3 KB)


Incremental Motor Speed.vi (8.3 KB)

So what I’m asking is when I’m not pressing we’ll say button A, the motors aren’t spinning. However, when I press A, the motors will slowl speed up until they reach their max RPM possible and will sustain the max speed until I release the button.

Do the LabVIEW equivalent of something like this:

if (buttonIsNotPressed) {cmd=0; setMotor(cmd)}
else {cmd+=epsilon; if (cmd>1) cmd=1; setMotor(cmd)}

… where “epsilon” is a small constant value that establishes the ramp-up rate.

The attached image shows how to do it using a feedback node.

A feedback node is a very local variable that keeps the value from the last iteration. This allows execution N be based on the values of execution N-1.

Replace the button with the one you want to read, replace the 0.1 with the delta you want to add, and don’t forget to connect the refnum to the joystick and motor VIs.

Ask questions if some portion of it doesn’t make sense.

Greg McKaskle

Clipboard 1.png


Clipboard 1.png

Ah, there is always an easier way!

When you say this, what exactly do you mean? Sort’ve a noob at LabVIEW still, but I understand some of it. When you say connect the refnum to the joystick and motor VIs, do you mean connect the button portion with the current joystick running our drive motors?

don’t forget to connect the refnum

One of the inputs to the Joystick and Motor blocks, the one on the top left, is called a refnum. Refnum is shorthand for Reference Number. It tells the block which joystick or motor to operate on.

The refnum is created by the Open block and can be stored and retrieved by name.

Take a look at Begin to see some being opened and saved, and Teleop to see them being retrieved and used for RobotDrive and Joystick.

Greg McKaskle