LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to control a robot through serial port

Hi, i have built a simple robot with radio module ( rs-232 com port transciever module in my PC, and receiver module connected to avr microcontroller with UART ). It looks like that:

 

http://www.youtube.com/watch?v=VGDQnQYLEKg

 

i would like to have a simple VI, that would send a key ascii number after being pressed through rs-232 ( this would make engines to work in a specific way ) and after releasing key to send a char that would stop that action. I have found some basic input demo.vi., some programs using events... but i couldn't make anything useful of that. Still not a very good at programming in Labview. I would be appreciated if someone would provide me with this simple program or if not maybe with some hints.

 

thanks for any help

pauldab

0 Kudos
Message 1 of 30
(5,517 Views)

Do you have any coding attemp you can post. It do not have work. But it will help to say something about your Labview skills. And also show the rest of us, that you have put some effort into this.



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Message 2 of 30
(5,500 Views)

hi,

i'm attaching the program.

It is done with event case structure. In key down there is char number of key pressed comparised with the key number that i want.For example If i press W then the LED connected to W key is ON. There is also a Event filter node in the right - i can't delete it - don't know why it is there - i have downloaded some program from the forum. I suppose that i would need to achieve smth simillar in the Key Up event case, so it would turn on ( send a char ) the other LEDs.... but can't get the char in the left event filter node.

0 Kudos
Message 3 of 30
(5,468 Views)

 

I didn't see the vid (Cant see it from work) but based on what little you say you first need to setup and manually send a char to the serial port to see if the contraption will work from LabVIEW!

 

First test your serial link to the device by opening a port with the serial functions (your device should have the appropriate serial config settings in a manual or on line) then send a single character to the device to see itf it responds to the character.

 

This way you will find out what the device needs to respond. (Some need more than just a command string or character some need CR LF combo or another esc code etc...

 

Once you know how to talk to it you can use your event structure example to send char strings to the device (quick and dirty)  I don't know if I misunderstand you or if this helps or not but to me all other work is irrelevant until you can be sure that the serial communications works first.

 

I'd start with some LV examples that use serial port and try to use one and build up from that.

 

 

 

 

 

0 Kudos
Message 4 of 30
(5,411 Views)

hi AKA_TG,

thanks for reply,

sending a char through a serial port is not a problem in LabView, already have done smth like that. As i already said a rs-232 com port transciever module is connected to my PC ( USB ) , and receiver module is connected to avr microcontroller with UART on the robot. It is really simple to send a char from PC and receive it in AVR microcontroller.

 

I know what device needs to respond, because i have programmed a microcontroller by myself in C. When microcontroller receives a char, the program on uC  goes to related interrupt, and in the interrupt the idea would be like that:

 

if ( ReceivedChar == "W" ) { go forward };

if ( ReceivedChar == "S" ) { go backward };

if ( ReceivedChar == "A" ) { turn left };

if ( ReceivedChar == "D" ) { turn right };

 

I can't really say if it is the best way to do it, although it works. However there is one big disadvantage - when i would press W char on my keyboard the robot, would go forward continuously. And i don't want that. To avoid this i have done smth like that:

 

if ( ReceivedChar == "W" ) { go forward ( or make the uC to force the robot to go forward continuously; wait some period of time ( with the same settings as to the "go forward" state ) ; stop the motors};

 

It is rather not elegant 😜 The best way would be to send a char to make the robot go forward/backward/turn left/turn right - it would be done in key down event, and when the key is released on the keyboard it would stop all actions - key up event.

 

I'm not good at LV, i don't feel good in graphical programming, especially when it goes to the arrays..... :d and have a problem with such a basic program.

 

would be grateful for any help

pauldab

0 Kudos
Message 5 of 30
(5,383 Views)

Hello,

 

There are a couple of ways to communicate through serial port. The mostly depend on the type of hardware you need to use.

http://zone.ni.com/devzone/cda/epd/p/id/6200

http://zone.ni.com/devzone/cda/epd/p/id/2669

http://zone.ni.com/devzone/cda/tut/p/id/11390

 

Please tell me if that helps.

 

Piotr

Piotr Kruczkowski
Certified TestStand Architect
Certified LabVIEW Architect
0 Kudos
Message 6 of 30
(5,328 Views)

How about sending a different character to stop movement?

 

eg

if ( ReceivedChar == "Z" ) { motors off };

 

Then, in your Key Down? event , you send the character to the robot, and in the key up event, if the scan code matches one of W,S,A,D (17, 30, 31, 32) you then send a Z.

 

Personally, I would have the robot acknowledge the command, so you can detect comms failures and shut off power or whatever.

 

Good luck

 

0 Kudos
Message 7 of 30
(5,311 Views)

If I understand correctly, You want motor to move while You keep the key pressed. The easiest way to do that in the structure, You proposed, is to:

-          right click on each of the Boolean indicators (A, S, D and W in the Key Down? event)

-          chose: create – property node – value.

-          change property nodes to read

-          put property nodes inside Key Up event

-          finally create constant input – false.

This will cause writing false to those chars after releasing the key. Hope it will help.

0 Kudos
Message 8 of 30
(5,264 Views)

Hi,

thanks for all replies 🙂

 

TRSns thanks for the links, but my problem was not about sending something through a serial port. It was about making my keyboard to act in

a specifed way.

 

MaxCrunch - what you have told it had been my intention from the beginnig - i see now that i haven't written it very clearly, i have known that already, but i wasn't able to implement it in LabView code due to lack of my programming skills.

 

Barbara_XYZ. You understood it correctly :).Thanks for the solution, it worked for the led's. And it finally gave me a punch to write a program. I'm attaching it.

 

I have tested it with com0com virtual ports. It works fine when i press a button i get on the terminal the char that i have pressed, after releasing it i get the 'z' char meaning to stop. There is one disadvantage, for example:

 

when i press the 'w' button i get a 'w' letter in terminal, while still holding 'w' i press 'a' , and i get in terminal 'a' letter, so the robot is turning left (although both buttons are pressed ), then when i release 'w' button i get 'z' letter ( so it stops the motors ) - BUT i'm still holding the 'a' button.... and it's not truning left now cause it have been stoped by releasing 'w'. Hope it's not too confusing :). Any ideas how to solve it? And would it be possible to send another char- when there are two buttons pressed at once ( 'w' and 'a' to make the robot turn in a curve ).

 

Best regards

pauldab

 

 

0 Kudos
Message 9 of 30
(5,225 Views)

That is an OS issue, not a LV or serial port issue.  Look at a text editor and press a second key while holding down the first.  What do you get?  Both letters repeated? No. On my Mac I only get the last letter pressed.  A keyboard can only send one character at a time to the OS which then passes it to the application.

 

If you want to go forward and turn right at the same time you need to find a way to send a different command or a sequence of commands rather than holding two keys on the keyboard.  For that I do not have any suggestions at the moment.

 

Lynn

0 Kudos
Message 10 of 30
(5,216 Views)