Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
robotran
mbsysc
Commits
9c2d0b1c
Commit
9c2d0b1c
authored
Nov 12, 2016
by
Nicolas Van der Noot
Browse files
process unix launched
parent
bd7780fe
Changes
5
Hide whitespace changes
Inline
Side-by-side
MBsysC/mbs_common/mbs_realtime/CMakeLists.txt
View file @
9c2d0b1c
...
...
@@ -176,7 +176,7 @@ include_directories("../mbs_struct")
include_directories
(
"../mbs_utilities"
)
# separate executable for Windows Open GL
if
(
FLAG_OPEN_GL
AND WIN32
)
if
(
FLAG_OPEN_GL
)
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_BINARY_DIR
}
)
add_subdirectory
(
open_gl/process/
${
CMAKE_CURRENT_BINARY_DIR
}
/open_gl/process/
)
endif
()
MBsysC/mbs_common/mbs_realtime/open_gl/interface/open_gl_c_int.cc
View file @
9c2d0b1c
...
...
@@ -9,6 +9,7 @@
#if (defined OPEN_GL_THREAD_UNIX) || (defined OPEN_GL_PROCESS_UNIX)
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#ifdef APPLE_VISU
#include <CoreFoundation/CoreFoundation.h>
...
...
@@ -73,10 +74,11 @@ enum {OPEN_GL_RUN, OPEN_GL_BREAK, OPEN_GL_STOP};
// function prototype
void
joints_view_open_gl
(
Realtime_visu
*
visu
,
int
nb_models
,
int
*
nb_q
,
double
**
q_vec
);
#if (defined OPEN_GL_THREAD_UNIX)
#if (defined OPEN_GL_THREAD_UNIX)
|| (defined OPEN_GL_PROCESS_UNIX)
pid_t
unix_create_process
();
void
opengl_unix_init_pipes
();
void
open_gl_unix_start_fork
(
Realtime_visu
*
visu
,
OpenGlIn
*
open_gl_in
);
void
open_gl_unix_start_fork
(
MbsData
*
mbs_data
,
Realtime_visu
*
visu
,
OpenGlIn
*
open_gl_in
);
void
run_open_gl_visu
(
OpenGlIn
*
open_gl_in
);
#elif (defined OPEN_GL_PROCESS_WIN)
...
...
@@ -133,8 +135,8 @@ void init_open_gl(Realtime_visu *visu, MbsData *mbs_data, int nb_models, int *nb
// initialization of the pipes and the fork
#ifdef OPEN_GL_THREAD_UNIX
opengl_unix_init_pipes
();
open_gl_unix_start_fork
(
visu
,
open_gl_in
);
#endif
open_gl_unix_start_fork
(
mbs_data
,
visu
,
open_gl_in
);
#elif (defined OPEN_GL_PROCESS_WIN)
...
...
@@ -442,7 +444,25 @@ void joints_view_open_gl(Realtime_visu *visu, int nb_models, int *nb_q, double *
#endif
}
#ifdef OPEN_GL_THREAD_UNIX
#if (defined OPEN_GL_THREAD_UNIX) || (defined OPEN_GL_PROCESS_UNIX)
/*! \brief create process for Unix
*
* \return PID of the the child process created
*/
pid_t
unix_create_process
()
{
pid_t
pid
;
// fork while error is EAGAIN
do
{
pid
=
fork
();
}
while
((
pid
==
-
1
)
&&
(
errno
==
EAGAIN
));
return
pid
;
}
/*! \brief initialize the pipes
*/
...
...
@@ -458,10 +478,12 @@ void opengl_unix_init_pipes()
}
/*! \brief start the fork
*
* \param[in] mbs_data Robotran main structure
* \param[out] visu real-time structure for 3D visualization
* \param[in] open_gl_in inputs for the OpenGL window and fields creation
*/
void
open_gl_unix_start_fork
(
Realtime_visu
*
visu
,
OpenGlIn
*
open_gl_in
)
void
open_gl_unix_start_fork
(
MbsData
*
mbs_data
,
Realtime_visu
*
visu
,
OpenGlIn
*
open_gl_in
)
{
// variables declaration
size_t
res
;
...
...
@@ -469,7 +491,7 @@ void open_gl_unix_start_fork(Realtime_visu *visu, OpenGlIn *open_gl_in)
int
nb_viewpoint
;
// fork: create two processes
pid_fork
=
fork
();
pid_fork
=
unix_create_process
();
if
(
pid_fork
==
-
1
)
{
...
...
@@ -477,6 +499,27 @@ void open_gl_unix_start_fork(Realtime_visu *visu, OpenGlIn *open_gl_in)
exit
(
EXIT_FAILURE
);
}
#ifdef OPEN_GL_PROCESS_UNIX
if
(
!
pid_fork
)
{
char
const
*
const
arg
[]
=
{
"open_gl_process"
,
NULL
};
std
::
string
exe_proc
;
exe_proc
=
mbs_data
->
build_name
;
exe_proc
+=
"/open_gl_process"
;
if
(
execv
(
exe_proc
.
c_str
(),
(
char
**
)
arg
)
==
-
1
)
{
perror
(
"execv"
);
exit
(
EXIT_FAILURE
);
}
}
return
;
#endif
if
(
!
pid_fork
)
// son, in charge of the visualization
{
// pipes safety
...
...
@@ -916,21 +959,21 @@ void opengl_win_create_child(MbsData *mbs_data)
// find executable name with path
exe_proc
=
mbs_data
->
build_name
;
if
(
opengl_win_file_exist
(
exe_proc
+
"/
exe_
open_gl_process.exe"
))
if
(
opengl_win_file_exist
(
exe_proc
+
"/open_gl_process.exe"
))
{
exe_proc
+=
"/
exe_
open_gl_process.exe"
;
exe_proc
+=
"/open_gl_process.exe"
;
}
else
if
(
opengl_win_file_exist
(
exe_proc
+
"/Release/
exe_
open_gl_process.exe"
))
else
if
(
opengl_win_file_exist
(
exe_proc
+
"/Release/open_gl_process.exe"
))
{
exe_proc
+=
"/Release/
exe_
open_gl_process.exe"
;
exe_proc
+=
"/Release/open_gl_process.exe"
;
}
else
if
(
opengl_win_file_exist
(
exe_proc
+
"/Debug/
exe_
open_gl_process.exe"
))
else
if
(
opengl_win_file_exist
(
exe_proc
+
"/Debug/open_gl_process.exe"
))
{
exe_proc
+=
"/Debug/
exe_
open_gl_process.exe"
;
exe_proc
+=
"/Debug/open_gl_process.exe"
;
}
else
{
std
::
cout
<<
"open_gl_c_int error:
exe_
open_gl_process.exe not found !"
<<
std
::
endl
;
std
::
cout
<<
"open_gl_c_int error: open_gl_process.exe not found !"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
...
...
MBsysC/mbs_common/mbs_realtime/open_gl/interface/open_gl_unix_process.cc
0 → 100644
View file @
9c2d0b1c
/*!
* \author Nicolas Van der Noot
* \file open_gl_process.cc
* \brief main function to run the separate process for Windows
*/
#if (defined OPEN_GL) && (defined PROCESS_OPEN_GL) && (defined UNIX)
#include "MbsWorld3D.hh"
#include "cmake_config.h"
#include "cmake_open_gl_config.h"
#include "open_gl_c_int.h"
#include <iostream>
// states of the window
enum
{
OPEN_GL_RUN
,
OPEN_GL_BREAK
,
OPEN_GL_STOP
};
/*! \brief main function, used for 3D visualization in a separate process
*
* \param[in] argc number of arguments
* \param[in,out] args strucure with all the needed inputs
*/
int
main
(
int
argc
,
char
const
*
argv
[])
{
// variables declaration
int
nb_models
;
int
flag_state
,
flag_viewpoint
,
flag_close
;
int
*
nb_q
;
double
**
q_vec
;
OpenGLMbs
::
MbsWorld3D
*
world_3d
;
std
::
cout
<<
"launch Unix ok"
<<
std
::
endl
;
exit
(
EXIT_SUCCESS
);
// create world
world_3d
=
new
OpenGLMbs
::
MbsWorld3D
(
1024
,
768
);
// number of .mbs models to load
nb_models
=
0
;
// load each model
for
(
int
i
=
0
;
i
<
nb_models
;
i
++
)
{
world_3d
->
AddMbs
(
NULL
);
}
// save number of joints for each model
nb_q
=
new
int
[
nb_models
];
for
(
int
i
=
0
;
i
<
nb_models
;
i
++
)
{
nb_q
[
i
]
=
0
;
}
// vectors to get joint position
q_vec
=
new
double
*
[
nb_models
];
for
(
int
i
=
0
;
i
<
nb_models
;
i
++
)
{
q_vec
[
i
]
=
new
double
[
nb_q
[
i
]];
for
(
int
j
=
0
;
j
<
nb_q
[
i
];
j
++
)
{
q_vec
[
i
][
j
]
=
0.0
;
}
}
// set the initial values of each joint
//q_vec[i] = 0.0;
for
(
int
i
=
0
;
i
<
nb_models
;
i
++
)
{
world_3d
->
UpdateJoints
(
i
,
nb_q
[
i
],
q_vec
[
i
]);
}
// set the initial viewpoint
if
(
flag_viewpoint
>=
0
)
{
world_3d
->
SetViewPoint
(
flag_viewpoint
);
}
else
{
world_3d
->
SetViewPoint
(
0
);
}
// send the number of viewpoints
world_3d
->
GetNbViews
();
// flag to know when to close the 3D window
flag_close
=
0
;
// loop until command is sent to close
while
(
1
)
{
if
(
!
flag_close
)
{
// check 3D window to close it
if
(
!
flag_close
)
{
if
(
!
world_3d
->
CheckClose
())
{
flag_close
=
1
;
delete
world_3d
;
}
// update world 3D timing
world_3d
->
UpdateTime
();
}
}
// get state, view and joints from father process
// flag_state, flag_viewpoint, q_vec
switch
(
flag_state
)
{
// model running
case
OPEN_GL_RUN
:
// update joint positions
for
(
int
i
=
0
;
i
<
nb_models
;
i
++
)
{
// update the joints
if
(
!
flag_close
)
{
world_3d
->
UpdateJoints
(
i
,
nb_q
[
i
],
q_vec
[
i
]);
}
}
// update viewpoint
if
(
flag_viewpoint
>=
0
)
{
if
(
!
flag_close
)
{
world_3d
->
SetViewPoint
(
flag_viewpoint
);
}
}
// update the window
if
(
!
flag_close
)
{
world_3d
->
Update
();
}
break
;
// break
case
OPEN_GL_BREAK
:
// update the window
if
(
!
flag_close
)
{
world_3d
->
Update
();
}
break
;
// stop the simulation
case
OPEN_GL_STOP
:
// release 'q_vec' memory
for
(
int
i
=
0
;
i
<
nb_models
;
i
++
)
{
delete
[]
q_vec
[
i
];
}
delete
[]
q_vec
;
// release 'nb_q' memory
delete
[]
nb_q
;
// release 'world_3d' memory
if
(
!
flag_close
)
{
delete
world_3d
;
}
// stop this thread
exit
(
EXIT_SUCCESS
);
break
;
default:
std
::
cout
<<
"open_gl_process error: unknown state flag ("
<<
flag_state
<<
") !"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
}
}
#endif
MBsysC/mbs_common/mbs_realtime/open_gl/interface/open_gl_process.cc
→
MBsysC/mbs_common/mbs_realtime/open_gl/interface/open_gl_
win_
process.cc
View file @
9c2d0b1c
File moved
MBsysC/mbs_common/mbs_realtime/open_gl/process/CMakeLists.txt
View file @
9c2d0b1c
...
...
@@ -72,6 +72,11 @@ set(CMAKE_AUX_BIN ${PROJECT_BINARY_DIR}/cmake_aux)
add_subdirectory
(
${
CMAKE_AUX
}
/listing/
${
CMAKE_AUX_BIN
}
/listing/
)
add_subdirectory
(
${
CMAKE_AUX
}
/libraries/
${
CMAKE_AUX_BIN
}
/libraries/
)
# UNIX system
if
(
UNIX
)
add_definitions
(
-D UNIX
)
endif
(
UNIX
)
# Windows M_PI definitions
if
(
WIN32
)
add_definitions
(
-D _USE_MATH_DEFINES
)
...
...
@@ -145,7 +150,7 @@ increment_include("${PROJECT_SOURCE_DIR}/..")
include_directories
(
${
INCLUDE_DIR
}
)
# name of the executable
set
(
Executable
exe_
open_gl_process
)
set
(
Executable open_gl_process
)
# generate the executable
add_executable
(
${
Executable
}
${
SOURCE_FILES
}
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment