Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Detecting if the code runs from the PC or the RoboRIO (http://www.chiefdelphi.com/forums/showthread.php?t=137863)

GuyM142 29-07-2015 11:00

Detecting if the code runs from the PC or the RoboRIO
 
I have some code that I want to run only when working from the PC (connected with an Ethernet cable) for debugging purposes.
Is there a way for the code to detect if the code runs from the PC or from the RoboRIO itself?
That way I won't need to disable this code block whenever I download it to the robot.
Thank you!

Jonathan L. 29-07-2015 13:04

Re: Detecting if the code runs from the PC or the RoboRIO
 
I have not tested this with a FRC robot yet but I think this is what you're looking for. See this video at 18 min 15 sec and 21 min 30 sec. http://www.ni.com/webcast/3798/en/

The Conditional Disable Structure...

Ari423 29-07-2015 13:51

Re: Detecting if the code runs from the PC or the RoboRIO
 
I haven't ever done it, but I imagine it can be done using some kind of property node. (to LabVIEW documentation!) I would highly recommend removing any code only running in debugging mode from the final robot project to avoid any chance of the robot thinking it is in debug mode and to keep the robot from having to constantly check whether or not it is in debug mode.

Just my $0.02

GuyM142 29-07-2015 14:56

Re: Detecting if the code runs from the PC or the RoboRIO
 
Quote:

Originally Posted by Jonathan L. (Post 1491716)
I have not tested this with a FRC robot yet but I think this is what you're looking for. See this video at 18 min 15 sec and 21 min 30 sec. http://www.ni.com/webcast/3798/en/

The Conditional Disable Structure...

That looks great! I will try it on the robot the next time I'll have a chance :)

Quote:

Originally Posted by Ari423 (Post 1491721)
I haven't ever done it, but I imagine it can be done using some kind of property node. (to LabVIEW documentation!) I would highly recommend removing any code only running in debugging mode from the final robot project to avoid any chance of the robot thinking it is in debug mode and to keep the robot from having to constantly check whether or not it is in debug mode.

Just my $0.02

That's a good point, but I think that the structure that was suggested by Jonathan makes sure that whatever that is in the block doesn't even get compiled so there are no constant checking. (I hope :P)

wt200999 29-07-2015 15:12

Re: Detecting if the code runs from the PC or the RoboRIO
 
Quote:

Originally Posted by Jonathan L. (Post 1491716)
I have not tested this with a FRC robot yet but I think this is what you're looking for. See this video at 18 min 15 sec and 21 min 30 sec. http://www.ni.com/webcast/3798/en/

The Conditional Disable Structure...

Unfortunately I do not think the conditional disable structure will work the way that you want without some extra effort.

The only time RUN_TIME_ENGINE is FALSE will be if you are running the code on your host machine. This works if you are using the simulator vs the actual robot, but once you run it on the robot as you describe it will be TRUE. Target_Type and OS will give you the same issue.

You can create a conditional that is project wide, and manually change it when you build, but that is tedious and more importantly is error prone.

You may be able to play around with the build specification, maybe with the pre/post build actions combined with the project wide build specification, but this is not something I have never tried.

You may be better of with the suggestion from Ari423 unless you have a good reason to prevent the code block from compiling in the first place.

Greg McKaskle 29-07-2015 15:30

Re: Detecting if the code runs from the PC or the RoboRIO
 
If you are asking about simulated versus running on the roboRIO, the Conditional Disable Structure is what you are looking for. An example of how to use it is shown in this VI vi.lib\Rock Robotics\SystemInterfaces\NetworkCommunication\Net Comm_UnloadCPPStartupProgram.vi

If you want to know if a debugging host is connected, I believe you want to use a Property Node to read the App.UserInterfaceAvailable property. Read the help and I think you will see that it does what you want. If not, please explain more of what you are looking for.

Greg McKaskle

Ari423 29-07-2015 15:34

Re: Detecting if the code runs from the PC or the RoboRIO
 
Quote:

Originally Posted by wt200999 (Post 1491728)
The only time RUN_TIME_ENGINE is FALSE will be if you are running the code on your host machine. This works if you are using the simulator vs the actual robot, but once you run it on the robot as you describe it will be TRUE. Target_Type and OS will give you the same issue.

I just had an idea. When you get the file path of Robot Main in Robot Main, if it is built and running in the robot project the second to last string in the file path will be projectName.exe, whereas if you were running it in debug mode (manually running Robot Main) the second to last string in the file path will be the folder the project is in. You should be able to get the file path, strip it twice, and search the second stripped string for ".exe". If you are running a build the index will be greater than 0 (it exists somewhere in the string). If it is running in debug mode, the index will be -1 (search string isn't in source string). You can then save this bool as a global, carry it into teleop and/or periodic, or do whatever you want with it. Let me know if this works.

EDIT: I think this is what you are looking for without using any complicated property nodes. There may be other ways to do the same thing using property nodes or otherwise, and you should feel free to use whichever you feel is easier. My original suggestion about removing this code from the final project still stands.

GuyM142 30-07-2015 07:33

Quote:

Originally Posted by Greg McKaskle (Post 1491731)
If you want to know if a debugging host is connected, I believe you want to use a Property Node to read the App.UserInterfaceAvailable property. Read the help and I think you will see that it does what you want. If not, please explain more of what you are looking for.

Greg McKaskle

This is what I'm looking for, I'll try it.
Quote:

Originally Posted by Ari423 (Post 1491732)
I just had an idea. When you get the file path of Robot Main in Robot Main, if it is built and running in the robot project the second to last string in the file path will be projectName.exe, whereas if you were running it in debug mode (manually running Robot Main) the second to last string in the file path will be the folder the project is in. You should be able to get the file path, strip it twice, and search the second stripped string for ".exe". If you are running a build the index will be greater than 0 (it exists somewhere in the string). If it is running in debug mode, the index will be -1 (search string isn't in source string). You can then save this bool as a global, carry it into teleop and/or periodic, or do whatever you want with it. Let me know if this works.

EDIT: I think this is what you are looking for without using any complicated property nodes. There may be other ways to do the same thing using property nodes or otherwise, and you should feel free to use whichever you feel is easier. My original suggestion about removing this code from the final project still stands.

I want to try your method but I don't have enough experience with LabVIEW strings. Can you post here the code that does what you have explained?

Ari423 02-08-2015 17:03

Re: Detecting if the code runs from the PC or the RoboRIO
 
1 Attachment(s)
Quote:

Originally Posted by GuyM142 (Post 1491779)
I want to try your method but I don't have enough experience with LabVIEW strings. Can you post here the code that does what you have explained?

Sorry it has taken me so long to get back to you, I haven't had access to a computer with LabVIEW on it.

Here is the sample code (you can drag and drop it into a vi and it will automatically render as LabVIEW code):
Attachment 19245

It should return true if it is running in debug mode and false if it is running as part of a build. Let me know how it works out.


All times are GMT -5. The time now is 10:25.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi