LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Joystick Read + Serial Write to Arduino with LabVIEW

Ben,

 

I got the majority of the VI working using your suggestion. The N,S,E, NE, NW, SE, SW are working and the sensitivity is significantly better than it was on the old zone system. I'd like to take a minute and thank you for the advice as it is making for a much more sensitive control system.

 

The issue I have been having is that for some reason the W LEDs won't trigger. I set up probes to see where the problem is and it seems to be the angle conditions that are not triggering the boolean. I can't imagine what the problem could be since E uses the same exact code and works perfectly. My only thought is to go from a two hemisphere system to a full 360 but that might not work considering how the arctan function is made. Other than that I am hoping it might just be a careless oversight that is easily remedied in which case I would appreciate another set of eyes having a look.

 

I've attached the new VI bellow and I am hoping someone can give me some insight into this.

 

Thanks again for the help,

Yusif

0 Kudos
Message 21 of 36
(1,751 Views)

E is based on a number being less than 22.5 AND greater than -22.5.  That is possible.

 

W is based on a number being less than -157.5 AND greater than 157.5.  That is not possible.

 

PS.  It is less code to convert the radians to degrees once, rather than converting constants in degrees to radians on two separate occasions for each value.

 

Also, the In Range and Coerce function will do the comparisons and use even fewer LabVIEW primitives.

0 Kudos
Message 22 of 36
(1,728 Views)

Thank you for the response. Could you please elaborate on why this is not possible and how I could otherwise approach it?

 

I will be looking into various ways to compact the code once I have it working so I will be keeping these suggestions in mind.

 

Thanks,

Yusif

0 Kudos
Message 23 of 36
(1,725 Views)

@Akello wrote:

Thank you for the response. Could you please elaborate on why this is not possible and how I could otherwise approach it?

 



Find a number that is both less than -157.5 AND greater than +157.5.  A number can be less than -157.5 OR greater than 157.5.  But not both.

 

Message 24 of 36
(1,720 Views)

Thanks for breaking it down; someone at work actually broke it down for me yesterday and showed me how to use the In Range and Coerce tool.

 

I'll be reworking the whole VI in the coming days to use less peices and include more labels so that it can be more easily decipherable. This way, people can take a look at a working sample code if they are doing a similar project.

 

Thanks again for all the help!

Yusif

0 Kudos
Message 25 of 36
(1,714 Views)

This is really coming along! Great work!

Ben D.
Applications Engineer
National Instruments
0 Kudos
Message 26 of 36
(1,711 Views)

I've been working on the VI for the past couple of days and I while I managed to get my original radius/angle VI to run perfectly, the range VI turned out a bit dissapointing. It works but not as smoothly as the one with the greater than/less than values so I am keeping the original and moving on due to time constraints.

 

Currently I have one final issue with this VI that I need help with that was only recently added to it's functionality requirements. I now need not only a serial write but a serial read as well and I need some advice on coordinating that:

 

The way this is mean to work is that a virtual port program will fool the system into thinking that a microcontroller is seriall connected when it is in fact wirelessly connected. For all intents and purposes the microcontroller should appear to be connected via a port (let's say COM3). Now, my VI is currently writing serial commands to that port using a 9600 baud rate and I need it to serially read reports that the mcrocrontroller will be periodically sending back.

 

My questions are:

 

1. Can serial write and serial read occur concurrently without any overlap? Or, do I need to create something that switches between the two in order for them to happen one at a time?

 

2. Will there be any problem with configuring communication according to baud rate given that it is a trick serial connection. To elaborate; there are two serial write and read examples in LabVIEW, one with specified but different COM ports and the other with just a specified baud rate which  have been using. Were this a physical connection I wouldn't even ask but considering I am going a roundabout way in creating it, I wonder if using the baud rate will be a problem.

 

Thanks again for the help and Happy New Year!

Yusif

0 Kudos
Message 27 of 36
(1,697 Views)

Just to tack on to the previous post; I am looking to take continuous readings at regular intervals while the serial writes will be made only when certain controls are activated. I was thinking of modifying the attached example by rearranging their order removing read's boolean condition and making a certain button on the joystick the boolean condition of the write.

 

Am I way off base?

0 Kudos
Message 28 of 36
(1,693 Views)

Akello,

 

Its sounds do able. It seems like you've found both pieces for how to do what you want. You now just have to merge them. You'll probably need to define a set of commands that you'd be expecting from the serial reads so you can parse through the serial strings and find when the joystick is being pressed as well as enclose everything in a while loop. 

 

Good luck on your project.

Kyle Hartley
Senior Embedded Software Engineer

0 Kudos
Message 29 of 36
(1,681 Views)

Thanks for the reply Kyle, I am unfortunately somewhat limited by time and the ability to test my code because not all the equipment is immediately available to me.

 

It does seem like I have all the peices of code necessary and I will be testing how it comes together in the coming days. Currently my plan is to take my VI and add the read portion before the write portion. I am planning on lifting the serial read from the example I attached in my earlier message with the intention that serial read happen as long as the loop is running while serial write happen only in certain structures.

 

The issue I am having is with the delay in the original example. First and foremost, why is the delay there and why is it necessary if read and write can occur concurrently? Second, if the delay is uncessecary (I hope,) will the order be an issue (example has write, delay, read while I plan on read, write) on the actual VI? Would it be better to set them up parrallel versus in order on the layout?

 

The help is much appreciated,

Yusif

0 Kudos
Message 30 of 36
(1,670 Views)