Go to Post Yes, machining a dog profile into a steel sprocket on a manual mill was an experience filled with pain and regret. - Joe G. [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-09-2015, 17:15
Hsifeulbhsifder Hsifeulbhsifder is offline
Programmer
AKA: Zaeem Mohamed
FRC #5428 (Breaking Bots)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Markham, ON, Canada
Posts: 41
Hsifeulbhsifder is on a distinguished road
Dynamically Linked Libraries

I was just wondering if it is possible to create and deploy user created code to be linked dynamically at runtime? In other words, is it possible to deploy the RoboRIO equivalent of a win32 .dll file to the RoboRIO?
Reply With Quote
  #2   Spotlight this post!  
Unread 21-09-2015, 17:27
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,169
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Dynamically Linked Libraries

Certainly - in Linux they have a different name structure and are stored in different default locations but the intent is much the same.

Lets say I have a library called "keith". The actual file name (or link) would be called libkeith.so for a static library or libkeith.a for a static library. The objects are compiled with extra flags and the linking step looks different. Just google "Linux shared libraries howto" and there are hundred of good examples on the web.

If you have trouble, post again or PM me.

HTH
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #3   Spotlight this post!  
Unread 21-09-2015, 18:47
Hsifeulbhsifder Hsifeulbhsifder is offline
Programmer
AKA: Zaeem Mohamed
FRC #5428 (Breaking Bots)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Markham, ON, Canada
Posts: 41
Hsifeulbhsifder is on a distinguished road
Re: Dynamically Linked Libraries

Thank you for the help, so do i just ssh the library to the rio?
Reply With Quote
  #4   Spotlight this post!  
Unread 21-09-2015, 20:19
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,169
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Dynamically Linked Libraries

Sure, remember to put it where it can be found. Normally that is in /lib or /usr/lib or /usr/local/lib (for anyone to use) - it is configurable. During development you can use LD_LIBRARY_PATH and put the library anywhere (in the CWD for example).

HTH
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #5   Spotlight this post!  
Unread 21-09-2015, 22:37
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 802
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Dynamically Linked Libraries

Although it may be possible (and it really isn't that hard), I'd highly recommend just statically linking everything. If you dynamically link, you run the risk of running with inconsistent versions of libraries, or having to maintain binary compatibility between libraries. It ends up being easier to just deploy statically linked binaries if RAM and HD aren't an issue, which they aren't. We deploy static binaries both at work and for robotics, and it has saved us many times.
Reply With Quote
  #6   Spotlight this post!  
Unread 21-09-2015, 22:39
JamesTerm's Avatar
JamesTerm JamesTerm is offline
Terminator
AKA: James Killian
FRC #3481 (Bronc Botz)
Team Role: Engineer
 
Join Date: May 2011
Rookie Year: 2010
Location: San Antonio, Texas
Posts: 298
JamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to behold
Re: Dynamically Linked Libraries

Quote:
Originally Posted by Hsifeulbhsifder View Post
I was just wondering if it is possible to create and deploy user created code to be linked dynamically at runtime? In other words, is it possible to deploy the RoboRIO equivalent of a win32 .dll file to the RoboRIO?
Out of curiosity, why would you want it to be a dynamic link library as opposed to say a static library?

The big difference there is if you have global/static variables that are to be shared to multiple children dll's that are dependent on the same dll. Other than that static seemed to be easy to do to keep coding groups encapsulated just as it is in a win32 environment.

There is one other technique that seems to work just as well... this is one project, but within the project each group of files is in its own folder. This one seems to be the easiest to build as I don't have to worry about certain projects being forced to build, when doing it the other way. This method also avoids having multiple instances of singletons (that could occur with static libraries).
Reply With Quote
  #7   Spotlight this post!  
Unread 23-09-2015, 12:50
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,169
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Dynamically Linked Libraries

Quote:
Originally Posted by AustinSchuh View Post
Although it may be possible (and it really isn't that hard), I'd highly recommend just statically linking everything. If you dynamically link, you run the risk of running with inconsistent versions of libraries, or having to maintain binary compatibility between libraries. It ends up being easier to just deploy statically linked binaries if RAM and HD aren't an issue, which they aren't. We deploy static binaries both at work and for robotics, and it has saved us many times.
This is very good advice. I got the feeling the OP was just in learning mode.

The great advantage of shared libraries is that there is only one copy in physical memory, hard to see that as an issue in FRC since there is only one user application running in user space (besides the system and NI daemons).
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #8   Spotlight this post!  
Unread 24-09-2015, 17:10
JamesTerm's Avatar
JamesTerm JamesTerm is offline
Terminator
AKA: James Killian
FRC #3481 (Bronc Botz)
Team Role: Engineer
 
Join Date: May 2011
Rookie Year: 2010
Location: San Antonio, Texas
Posts: 298
JamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to behold
Re: Dynamically Linked Libraries

Quote:
Originally Posted by wireties View Post
The great advantage of shared libraries is that there is only one copy in physical memory, hard to see that as an issue in FRC since there is only one user application running in user space (besides the system and NI daemons).

An example of that... (i.e. an issue in FRC when multiple instances occur due to a static library setup)... would be if someone wishes to use SmartDashboard... I had SmartDashboard in its own library as static... in my win32 environment, and had multiple DLLs in use. Network Tables must have only one instance to work properly... so I had to make a DLL version of it to work correctly... luckily this was all win32 environment so it was easy to do.

For the eclipse environment if something similar needed to be done (which I couldn't see happening, but could if all vision processing was done on roboRIO)... The static library solution may not work... in which case the one project multi folder technique may give the best results... so far I've been leaning towards that as a workflow. I'm going to thank Jeff Downs for that suggestion from his workflow tips on the eclipse old cRIO solution. It gives the benefit for shared libraries, while allowing code to be separate... built time is still very fast too.
Reply With Quote
  #9   Spotlight this post!  
Unread 24-09-2015, 21:30
Hsifeulbhsifder Hsifeulbhsifder is offline
Programmer
AKA: Zaeem Mohamed
FRC #5428 (Breaking Bots)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Markham, ON, Canada
Posts: 41
Hsifeulbhsifder is on a distinguished road
Re: Dynamically Linked Libraries

Quote:
Originally Posted by wireties View Post
This is very good advice. I got the feeling the OP was just in learning mode.
Yep, I am just experimenting with stuff in my free time, seeing what I can do. The purpose of this was to see if I could dynamically load the c++ compiled code into a DLL so that I can tweak values without having to kill the running program. I have the main FRCUserProgram running code that applies only to all the hardware related aspects. This code stores all the necessary memory which is then passed into the dll every iteration. If the dll should change, the same memory is pushed into the new dll and it operates upon the memory as I intended the change to. I think this is called live loop editing.
__________________
Hsifeulbhsifder
___________________
"Any given computer program is obsolete, any set of written rules is incomplete"
Reply With Quote
  #10   Spotlight this post!  
Unread 24-09-2015, 22:56
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 802
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Dynamically Linked Libraries

Quote:
Originally Posted by Hsifeulbhsifder View Post
Yep, I am just experimenting with stuff in my free time, seeing what I can do. The purpose of this was to see if I could dynamically load the c++ compiled code into a DLL so that I can tweak values without having to kill the running program. I have the main FRCUserProgram running code that applies only to all the hardware related aspects. This code stores all the necessary memory which is then passed into the dll every iteration. If the dll should change, the same memory is pushed into the new dll and it operates upon the memory as I intended the change to. I think this is called live loop editing.
We actually achieve the same thing through a different mechanism.

Our robot code is split up into a bunch of processes (each is a separate binary). There is 1 process which has WPILib built into it and interfaces to the hardware. The other processes have our control loops, joystick code, autonomous mode, etc. They all communicate via a shared memory mechanism we designed. The really cool part is that this lets us re-start the various modules and replace them without taking the rest of the code down or restart it. We've been able to do things like deploy new joystick code while the driver was driving.
Reply With Quote
  #11   Spotlight this post!  
Unread 25-09-2015, 01:10
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,169
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Dynamically Linked Libraries

Quote:
Originally Posted by AustinSchuh View Post
We actually achieve the same thing through a different mechanism.

Our robot code is split up into a bunch of processes (each is a separate binary). There is 1 process which has WPILib built into it and interfaces to the hardware. The other processes have our control loops, joystick code, autonomous mode, etc. They all communicate via a shared memory mechanism we designed. The really cool part is that this lets us re-start the various modules and replace them without taking the rest of the code down or restart it. We've been able to do things like deploy new joystick code while the driver was driving.
Our code is structured in much the same way but is multi-threaded and uses pipes for communications (mostly because we ported from VxWorks message queues).

How did you implement the shared memory? We noticed that POSIX message queues are not in the kernel. Is the POSIX shared memory API supported? Or maybe SystemV style shared memory? Or did you do something custom?

TIA
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #12   Spotlight this post!  
Unread 25-09-2015, 01:28
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 802
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Dynamically Linked Libraries

Quote:
Originally Posted by wireties View Post
How did you implement the shared memory? We noticed that POSIX message queues are not in the kernel. Is the POSIX shared memory API supported? Or maybe SystemV style shared memory? Or did you do something custom?
Essentially SystemV shared memory, though we just use the mmap call directly to map a file from /dev/shm/ in. We then built up message queues with mutexes, condition variables, etc in that memory and use those. That lets you use priority inversion safe mutexes, which is good.
Reply With Quote
  #13   Spotlight this post!  
Unread 11-10-2015, 16:50
Hsifeulbhsifder Hsifeulbhsifder is offline
Programmer
AKA: Zaeem Mohamed
FRC #5428 (Breaking Bots)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Markham, ON, Canada
Posts: 41
Hsifeulbhsifder is on a distinguished road
Re: Dynamically Linked Libraries

Just putting this out there, thank you all for all your help. I have successful dynamic loading of code and am able to make changes to the program while the robot is active.
__________________
Hsifeulbhsifder
___________________
"Any given computer program is obsolete, any set of written rules is incomplete"
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:05.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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