LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

controlling servo motor on arduino through labview

I have few problems when I try to control the servo motors, which are connected to digital inputs on Arduino Nano, through LabVIEW. 

 

Goal: The goal is to be able to control the motors with a slide I have on the front panel in Labview. And I want it to change continuously. As if I had a physical potentiometer. 

 

Problems: 

  • It changes with a delay. In the picture I had a delay in Labview (1100ms), otherwise it'll not manage to write to Arduino. How can I make the slide change the motors as is mentioned in the goal?
  • I also get an error sometimes error -1073807194. Do you know how I can avoid that problem?
  • When I'm changing the value on the slide and keep the mouse down, the motors moves to the position but then jumps to another position. But if I just click at a position on the slide the motors stays on the set position. Why is that?

I attached pictures on my labview code and below you can see the arduino code.

 

Grateful for some help!

 

Arduino code: 

void setup() {
Serial.begin(115200);
//attach all the servos to the pins on the arduino
for (int currentServo = 0; currentServo < ALL_FINGERS; currentServo++){
servoHand[currentServo].attach(servoPins[currentServo]);
}
for (int currentServo = 0; currentServo < ALL_FINGERS; currentServo++){
servoHand[currentServo].write(LIFT_POS);
}
}

void loop() {
   if (Serial.available() > 0) {

      str = "";

   }

   while(Serial.available() > 0){
      cmd = ((byte)Serial.read());
      if(cmd == '\n'){
      break;
   }else{
      str += cmd;
   }
   delay(100);
   }

finger = getValue(str,';',0);
touch = getValue(str,';',1); //separate the input string from LabVIEW

if (touch == "CHANGE"){
   valueServo = finger.toInt();
   for (int currentServo = 0; currentServo < ALL_FINGERS; currentServo++){
      servoHand[currentServo].write(valueServo);
   }
   TOUCH_POS = valueServo;
   }

}

Download All
0 Kudos
Message 1 of 9
(4,594 Views)

1100ms wait seems like a very long wait to send data, also the timeout on the port is set to default in your program anyways.  You set that with the configure serial port function. Also you may lose connection to the port because you are continually flushing and clearing the port, you have no delay in your loop when the slider has not changed value.  This seems like a lot on the port and you might drop the connection, also i always put a 100ms wait after clearing a port before i do anything with it.  If you dont need to clear it everytime i would remove those functions in the false statement.  If you do need to clear it i would wire a 100ms time delay after the clear.



-Matt
0 Kudos
Message 2 of 9
(4,552 Views)

Sorry for the double post, but i forgot you can download a labview interface for arduino and get rid of the code running on your arduino.  You still have to install it on arduino, but ive played around with it.  Might make your life easier.

 

 

 

labview interface for arduino



-Matt
0 Kudos
Message 3 of 9
(4,534 Views)

Hi,

To make arduino programming easier using labVIEW, there is and arduino API called LINX, which is available through VIPM. You can try that, it will help and it also has example codes and support for many sensors.

0 Kudos
Message 4 of 9
(4,512 Views)

Thank you for your reply Matt. 

 

I put the delay when sending data because it doesn't seem like it manage to send something to Arduino. Because when I activate the "highlight execution", then the motors start to move. So I guessed I needed some delay, but maybe it is because of something else?

 

About the clearing: I thought I needed that to prevent overload of data. But maybe in this case it is not needed?

 

Now I removed the case structure so there are no clearing. But it still acts the same as before, besides that it doesn't react if holding down the mouse button. 

 

I've tried the LIFA before, but it keeps on running in the init VI. Don't know if it has to do something about when I choose type of board. I use Arudino nano, but I can't choose that on the board type of the VI so I tried Uno. And that is when it gets stuck in "init". Do you know more about that? 

0 Kudos
Message 5 of 9
(4,500 Views)

Hi, 

Don't use LIFA anymore. It is slightly buggy and outdated.

Try getting LINX, it should have a subVI dedicated to servo without much bug.

0 Kudos
Message 6 of 9
(4,498 Views)

Hi Schlok,

 

you are correct, when i originally downloaded linx i thought it didnt have arduino support.  It does have subVI's dedicated for servo control though. 



-Matt
0 Kudos
Message 7 of 9
(4,484 Views)

Hi, 

I attached a VI that might help you.

Check it out.

0 Kudos
Message 8 of 9
(4,463 Views)

Thank you Shlok, that's very nice.

 

Sorry for late reply, I wanted to try out another thing before and it took some time.

 

I wanted to see if Event structure worked before using LINX. Because I've used LINX before in earlier project (one year ago) and then it worked very well to control the motors. But since LINX used a lot of memory already my program got slower when I wanted to do more stuff with it (also, my code could have been not that efficient either since I used a lot of for-loops). So that's why I wanted to try Visa Write instead since my program is much larger now.

 

Visa write has been working pretty good for the rest of the project (just sending values and which motor I want to control), it was just this small part where I wanted to control the motors with a slide (in labview) which didn't work. 

 

So now, I changed to an event structure instead. And the problem was that I had an delay in the arduino code it didn't manage to read the values continously from the serial port. It works now as I wanted, besides that the labview program got a bit slow instead (but that's another problem). 

 

Thank you both for helping me!

 

Best regards 
Pamela

0 Kudos
Message 9 of 9
(4,452 Views)