Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

high performance logging via FRI + flatbuffers with the kuka iiwa #166

Open
wants to merge 111 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
de513aa
KukaToFlatbuffer.hpp create some new toflatbuffer functions for KUKA
Chunting Nov 10, 2017
18305eb
KukaToFlatbuffer.hpp added some toFlatBuffer functions.
Chunting Nov 11, 2017
f84c435
Added some helper functions.
Chunting Nov 12, 2017
4a267f7
kukaToFlatbuffer.hpp added some toFlatBuffer functions.
Chunting Nov 13, 2017
f7ae160
FusionTrackToFlatbuffer.hpp, converted the enum to flatbuffer enum ob…
Chunting Nov 14, 2017
9325862
kukaToFlatbuffer.hpp is created to get the flatbuffer objects (toFlat…
Chunting Nov 15, 2017
623b4f3
Intermediate codes which can't be compiled
Chunting Nov 15, 2017
d9ce32d
toFlatBuffer functions can compile
Chunting Nov 19, 2017
b8e6f49
INTERMEDIATE CODE: DOES NOT COMPILE initial integration of TimeEvent …
ahundt Nov 21, 2017
58bebbe
NTERMEDIATE CODE: DOES NOT COMPILE, FIX SOME ERRORS
Chunting Nov 27, 2017
fb8f67d
Errors fixed, the program can be compiled.
Chunting Nov 27, 2017
7881890
TimeEvent::device_time is used to replace time_point_type
Chunting Nov 28, 2017
1c30197
Some toFlatBuffer funstions are added for ArmControlState.fbs
Chunting Nov 28, 2017
ea0be8f
All the toFlatBuffer functions can compile successfully.
Chunting Nov 28, 2017
8ec6db0
NOT FINISHED: kukaiiwaTest.hpp Unit Test for toFlatBuffer functions
Chunting Nov 29, 2017
a1efda8
NOT FINISHED: kukaiiwaTest.hpp for unit test
Chunting Nov 29, 2017
986d257
kukaiiwaTest.hpp Unit Test starts to work.
Chunting Nov 30, 2017
e18b1e5
Generated Binary file successfully, but json failed.
Chunting Dec 2, 2017
94f4b46
kukaiiwaTest.cpp can be compiled and generate the binary file and j…
Chunting Dec 6, 2017
59181b9
/usr/local/include/flatbuffers/flatbuffer.h, _max_tables is changed t…
Chunting Dec 6, 2017
e606af2
Merge remote-tracking branch 'origin/master' into RobotToFlatBuffer
Chunting Dec 8, 2017
97202e2
Merge remote-tracking branch 'origin/fusiontrack' into RobotToFlatBuffer
Chunting Dec 12, 2017
02f443a
Auto stash before merge of "RobotToFlatBuffer" and "origin/fusiontrack"
Chunting Dec 12, 2017
e20bdd8
updated call to simExtHandEyeCalibStart() to supply vrep string names
Chunting Dec 12, 2017
f030174
Expand the capacity of single buffer size by passing _max_tables to …
Chunting Dec 12, 2017
ad1e078
Connected to the robot in Unit Test
Chunting Jan 3, 2018
65d484f
[NOT FINISHED] Log data in the KukaFRIdriver.hpp
Chunting Jan 5, 2018
d9d552d
KukaFRIdriver.hpp log data to flatbuffer
Chunting Jan 5, 2018
8d4f313
Log data from robot, fail to excute.
Chunting Jan 10, 2018
9f6e120
Get flatbuffer the binary file
Chunting Jan 11, 2018
cb48361
Succeed logging data from the robot (position and torque)
Chunting Jan 11, 2018
b816b53
Log data from robot
Chunting Jan 16, 2018
480eea4
Log data and generate json file
Chunting Jan 17, 2018
074d9e5
Log data from vrep plugin
Chunting Jan 17, 2018
34b0dd9
Add a method to log data in vrep plugin from starting the program
Chunting Jan 17, 2018
f7112ac
Clean some codes and add some comments about socket programming
Chunting Jan 19, 2018
a6ee79e
Don't use externalTorque in this version, it only
Chunting Jan 20, 2018
f752202
In Vrep, log data from real robot.
Chunting Jan 23, 2018
e986de0
Clean some codes
Chunting Jan 24, 2018
622629b
Read data from binary file
Chunting Jan 25, 2018
31c6ed8
Enable the recordDataScript()
Chunting Jan 26, 2018
cac6609
Plot timeEvent
Chunting Feb 1, 2018
49912dd
Modify the TimeEvent
Chunting Feb 1, 2018
31a3e45
dump out the time stuff
Chunting Feb 3, 2018
8f31fb6
Clean some codes based on the review
Chunting Feb 6, 2018
66da11a
Fix a bug about timeevent
Chunting Feb 9, 2018
c5aac6d
Improvements for ploting data and comments for java
Chunting Feb 14, 2018
536e178
Record data properly
Chunting Feb 15, 2018
5de6f4b
Save the pose of the EE to csv
Chunting Feb 19, 2018
3bb9523
Merge remote-tracking branch 'origin/master' into RobotToFlatBuffer
Chunting Feb 20, 2018
1dfaee4
Draw straight line
Chunting Feb 21, 2018
60b6ce8
Plot FT Pose
Chunting Feb 24, 2018
f508a02
Rewrite the CSV writer
Chunting Feb 26, 2018
4b2b607
Plot the data of both markers
Chunting Feb 27, 2018
4a922e2
Improve some codes and add new features
Chunting Feb 27, 2018
735d1b4
Add some comments
Chunting Feb 28, 2018
528d5a4
Skip the bad data
Chunting Feb 28, 2018
06c5459
[NOT FINISHED] Do the Calibration
Chunting Mar 1, 2018
a42196a
Get the inverse pose of the marker
Chunting Mar 8, 2018
134753e
Modifications based on review
Chunting Mar 8, 2018
e539c0b
Add new marker
Chunting Mar 15, 2018
288dc23
Replay
Chunting Mar 21, 2018
c24e58c
cmake and compile build/config fixes
ahundt Mar 23, 2018
596bafb
KukaJAVAdriver.hpp namespace fix
ahundt Mar 23, 2018
dbfc875
cmake build fixes
ahundt Mar 23, 2018
0bee725
Fix some bugs, detruction, ldl
Chunting Mar 23, 2018
832e467
Merge branch 'fusiontrack' into Calibrations
ahundt Mar 23, 2018
0bd0baa
Merge remote-tracking branch 'origin/Calibrations' into Calibrations
Chunting Mar 23, 2018
ff62f6c
Set single buffer limit from lua script
Chunting Mar 25, 2018
0a9163d
Write the hand eye result into a file
Chunting Mar 25, 2018
ee3ba71
To easily analysis data, creat a new branch and redesign the csv files
Chunting Mar 29, 2018
8ce0cc6
Fix bugs
Chunting Mar 30, 2018
88925ee
Reorganize the CSV files, make the time baseline consistent
Chunting Mar 30, 2018
49a1044
Fix bugs, make the timestamp consistency. It can plot the data with t…
Chunting Apr 2, 2018
cb7174b
Use the request time as the baseline
Chunting Apr 2, 2018
cfbc451
Merge remote-tracking branch 'origin/master' into Processing_data
Chunting Apr 3, 2018
6984f3f
Fix hard code
Chunting Apr 4, 2018
0a040c4
Remove hand codes.
Chunting Apr 5, 2018
4ddde2e
Edit c_cpp_properties.json to fix "can't find source files"
Chunting Apr 5, 2018
e84cbaa
Edit URDF file to make the joint and link name consistent with vrep m…
Chunting Apr 5, 2018
2da67fc
Read urdf model from file Robone_KukaLBRiiwa.urdf
Chunting Apr 5, 2018
7010e39
Removed two test files that won't be used any more.
Chunting Apr 5, 2018
72eba28
In order to visualize the urdf model in vrep, change the joint and li…
Chunting Apr 5, 2018
ad76787
Remove some meaningless comments.
Chunting Apr 5, 2018
d8f7c29
Removed some dead code
Chunting Apr 5, 2018
2273afa
Remove some dead code
Chunting Apr 5, 2018
0b3be3f
Updates urdf file path
Chunting Apr 6, 2018
e4aa5be
Remove some std::cout
Chunting Apr 6, 2018
c0d6185
Data analysis document
Chunting Apr 7, 2018
49b6eb5
Edit the document
Chunting Apr 7, 2018
f963ff6
Reorganise the folder structure to make it convenient to read and write.
Chunting Apr 8, 2018
12bfa68
Document about data analysis
Chunting Apr 9, 2018
ff48866
Improved the code based on the reviews.
Chunting Apr 10, 2018
9303a2a
Also improved the code based on the reviews.
Chunting Apr 10, 2018
688dc35
DON'T NEED TO REVIEW THESE FILES
Chunting Apr 10, 2018
156d3a0
Merge branch 'Processing_data' into RobotToFlatBuffer
Chunting Apr 10, 2018
741787e
Update the document about data based on the review.
Chunting Apr 10, 2018
7dcf90e
Undo the commit, removed those meaningless files
Chunting Apr 11, 2018
936f03e
Add new feature for replay process, now user can choose the run mode …
Chunting Apr 12, 2018
ed8a712
Plot the time latency curves
Chunting Apr 13, 2018
9c83f12
Using quaternion replaces Euler-Angles to present marker orientiation
Chunting Apr 15, 2018
1ca4038
Write a data processing log for csv files.
Chunting Apr 16, 2018
56009f3
Change the csv labels.
Chunting Apr 18, 2018
6c8d27c
Edit the instructions
Chunting Apr 18, 2018
d026e4b
Edit the DataRecordingAndPlayback.rst
Chunting Apr 19, 2018
a9bfa4e
Edit the format
Chunting Apr 19, 2018
e35a685
Edit the format
Chunting Apr 19, 2018
5c8459f
FRI set KUKA FRI KONI send period to 1ms, configurable on ProcessData…
Chunting Apr 23, 2018
495f0f0
Merge pull request #17 from ahundt/Data_document
ahundt Apr 23, 2018
b978292
Remove some std::cout
Chunting Apr 30, 2018
15b24a8
Merge remote-tracking branch 'origin/RobotToFlatBuffer' into RobotToF…
Chunting Apr 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion BasisProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ basis_project (
# dependencies
DEPENDS
FlatBuffers # google flatbuffers https://github.com/google/flatbuffers
Boost{program_options,filesystem,unit_test_framework,system,regex,coroutine,chrono}
Boost{program_options,filesystem,unit_test_framework,system,regex,coroutine,chrono,iostreams}
#<dependency>
OPTIONAL_DEPENDS
#<optional-dependency>
Expand All @@ -119,6 +119,7 @@ basis_project (
sch-core # Algorithms for convex hulls https://github.com/jrl-umi3218/sch-core used for inverse kinematics
RBDyn # Models the dynamics of rigid body system https://github.com/jrl-umi3218/RBDyn used for inverse kinematics
Tasks # Real time control of Kinematic Trees https://github.com/jrl-umi3218/Tasks used for inverse kinematics
mc_rbdyn_urdf # This library allows to parse an URDF file and create RBDyn structure from it. https://github.com/jrl-umi3218/mc_rbdyn_urdf
spdlog # fast logging library https://github.com/gabime/spdlog
LibDL # Linux Dynamic Loader library, linux only https://refspecs.linuxfoundation.org/LSB_2.0.1/LSB-Core/LSB-Core/libdl.html
TEST_DEPENDS
Expand Down
4 changes: 2 additions & 2 deletions config/FindFlatBuffers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ if(FLATBUFFERS_FOUND)
set(ABSOLUTE_FBS_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR}/${FILE})

add_custom_command(OUTPUT ${FLATC_OUTPUT}
COMMAND ${FLATBUFFERS_FLATC_EXECUTABLE}
COMMAND ${FLATBUFFERS_COMPILER}
# Note: We are setting several custom parameters here to make life easier.
# see flatbuffers documentation for details.
# flatc --gen-name-strings --scoped-enums --gen-object-api -c -j -p -o
# see https://google.github.io/flatbuffers/flatbuffers_guide_using_schema_compiler.html
ARGS --gen-name-strings --scoped-enums --gen-object-api -c -j -p -o "${OUTPUT_DIR}" ${FILE}
ARGS --gen-name-strings --scoped-enums --gen-object-api -c -j -p -o "${OUTPUT_DIR}" ${ABSOLUTE_FBS_FILE_PATH}
MAIN_DEPENDENCY ${ABSOLUTE_FBS_FILE_PATH}
COMMENT "Building C++, Java, and Python header for ${FILE}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR})
Expand Down
160 changes: 160 additions & 0 deletions config/FindFlatBuffers.cmake.deleteme
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Tries to find Flatbuffers headers and libraries.
#
# Usage of this module as follows:
#
# find_package(Flatbuffers)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# Flatbuffers_HOME -
# When set, this path is inspected instead of standard library locations as
# the root of the Flatbuffers installation. The environment variable
# FLATBUFFERS_HOME overrides this veriable.
#
# This module defines
# FLATBUFFERS_INCLUDE_DIR, directory containing headers
# FLATBUFFERS_LIBS, directory containing flatbuffers libraries
# FLATBUFFERS_STATIC_LIB, path to libflatbuffers.a
# FLATBUFFERS_FOUND, whether flatbuffers has been found

if( NOT "$ENV{FLATBUFFERS_HOME}" STREQUAL "")
file( TO_CMAKE_PATH "$ENV{FLATBUFFERS_HOME}" _native_path )
list( APPEND _flatbuffers_roots ${_native_path} )
elseif ( Flatbuffers_HOME )
list( APPEND _flatbuffers_roots ${Flatbuffers_HOME} )
endif()

# Try the parameterized roots, if they exist
if ( _flatbuffers_roots )
find_path( FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h
PATHS ${_flatbuffers_roots} NO_DEFAULT_PATH
PATH_SUFFIXES "include" )
find_library( FLATBUFFERS_LIBRARIES NAMES flatbuffers
PATHS ${_flatbuffers_roots} NO_DEFAULT_PATH
PATH_SUFFIXES "lib" )
else ()
find_path( FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h )
find_library( FLATBUFFERS_LIBRARIES NAMES flatbufferFLATBUFFERS_FLATC_EXECUTABLEs )
endif ()

find_program(FLATBUFFERS_COMPILER flatc
PATH
$ENV{FLATBUFFERS_HOME}/bin
${_flatbuffers_roots}/bin
/usr/local/bin
/usr/bin
NO_DEFAULT_PATH
)

if (FLATBUFFERS_INCLUDE_DIR AND FLATBUFFERS_LIBRARIES)
set(FLATBUFFERS_FOUND TRUE)
get_filename_component( FLATBUFFERS_LIBS ${FLATBUFFERS_LIBRARIES} PATH )
set(FLATBUFFERS_LIB_NAME libflatbuffers)
set(FLATBUFFERS_STATIC_LIB ${FLATBUFFERS_LIBS}/${FLATBUFFERS_LIB_NAME}.a)
else ()
set(FLATBUFFERS_FOUND FALSE)
endif ()

if (FLATBUFFERS_FOUND)
if (NOT Flatbuffers_FIND_QUIETLY)
message(STATUS "Found the Flatbuffers library: ${FLATBUFFERS_LIBRARIES}")
endif ()FLATBUFFERS_COMPILER
else ()
if (NOT Flatbuffers_FIND_QUIETLY)
set(FLATBUFFERS_ERR_MSG "Could not find the Flatbuffers library. Looked in ")
if ( _flatbuffers_roots )
set(FLATBUFFERS_ERR_MSG "${FLATBUFFERS_ERR_MSG} in ${_flatbuffers_roots}.")
else ()
set(FLATBUFFERS_ERR_MSG "${FLATBUFFERS_ERR_MSG} system search paths.")
endif ()
if (Flatbuffers_FIND_REQUIRED)
message(FATAL_ERROR "${FLATBUFFERS_ERR_MSG}")
else (Flatbuffers_FIND_REQUIRED)
message(STATUS "${FLATBUFFERS_ERR_MSG}")
endif (Flatbuffers_FIND_REQUIRED)
endif ()
endif ()

mark_as_advanced(
FLATBUFFERS_INCLUDE_DIR
FLATBUFFERS_LIBS
FLATBUFFERS_STATIC_LIB
FLATBUFFERS_COMPILER
)

if(FLATBUFFERS_FOUND)
function(FLATBUFFERS_GENERATE_C_HEADERS Name FLATBUFFERS_DIR OUTPUT_DIR)
# Name is the name of the user defined variable that will be created by this function
# Another variable that will be set is ${NAME}_OUTPUTS which will be set to the names
# of all output files that have been generated.FLATBUFFERS_COMPILER
# FLATBUFFERS_DIR is the directory in which to look for the .fbs files
# OUTPUT_DIR is the directory in which all output files should be placed
set(FLATC_OUTPUTS)
foreach(FILE ${ARGN})
get_filename_component(FLATC_OUTPUT ${FILE} NAME_WE)
# create a target for the specific flatbuffers file
set(FBS_FILE_COPY_INCLUDE copy_${FLATC_OUTPUT}_to_include)
set(FBS_FILE_COPY_BIN copy_${FLATC_OUTPUT}_to_bin)
# create a target for the generated output cpp file
set(FLATC_OUTPUT
"${OUTPUT_DIR}/${FLATC_OUTPUT}_generated.h")
list(APPEND FLATC_OUTPUTS ${FLATC_OUTPUT} ${FBS_FILE_COPY_INCLUDE} ${FBS_FILE_COPY_BIN})

# this is the absolute path to the actual filename.fbs file
set(ABSOLUTE_FBS_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR}/${FILE})

add_custom_command(OUTPUT ${FLATC_OUTPUT}
COMMAND ${FLATBUFFERS_COMPILER}
# Note: We are setting several custom parameters here to make life easier.
# see flatbuffers documentation for details.
# flatc --gen-name-strings --scoped-enums --gen-object-api -c -j -p -o
# see https://google.github.io/flatbuffers/flatbuffers_guide_using_schema_compiler.html
ARGS --gen-name-strings --scoped-enums --gen-object-api -c -j -p -o "${OUTPUT_DIR}" ${FILE}
MAIN_DEPENDENCY ${ABSOLUTE_FBS_FILE_PATH}
COMMENT "Building C++, Java, and Python header for ${FILE}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR})

# need to copy the flatbuffers schema so config files can be loaded
# http://stackoverflow.com/a/13429998/99379
# CMAKE_CURRENT_SOURCE_DIR
# this is the directory where the currently processed CMakeLists.txt is located in
# terminal copy commands change between OS versions, so we use CMake's built in file
# copy command which runs with "cmake -E copy file_to_copy file_destination"
# we use some variables here so the path is reproducible.
add_custom_command(OUTPUT ${FBS_FILE_COPY_INCLUDE}
COMMAND ${CMAKE_COMMAND} ARGS -E copy ${ABSOLUTE_FBS_FILE_PATH} ${OUTPUT_DIR}
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR}/${FILE}
COMMENT "Copying fbs file ${FILE} to ${OUTPUT_DIR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR}
)

add_custom_command(OUTPUT ${FBS_FILE_COPY_BIN}
# TODO(ahundt) remove hacky /bin manually set path, this will break for some IDEs
COMMAND ${CMAKE_COMMAND} ARGS -E copy ${ABSOLUTE_FBS_FILE_PATH} ${CMAKE_BINARY_DIR}/bin
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR}/${FILE}
COMMENT "Copying fbs file ${FILE} to ${CMAKE_BINARY_DIR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${FLATBUFFERS_DIR}
)
endforeach()
set(${Name}_OUTPUTS ${FLATC_OUTPUTS} PARENT_SCOPE)
endfunction()

set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR})
include_directories(${CMAKE_BINARY_DIR})
else()
set(FLATBUFFERS_INCLUDE_DIR)
endif()
4 changes: 3 additions & 1 deletion config/Settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ if(UNIX AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
ADD_DEFINITIONS(-fPIC)
endif(UNIX AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")


if(UNIX AND NOT APPLE)
set(LINUX_ONLY_LIBS ${LIBDL_LIBRARIES})
endif()
# Link the boost.log library
# @todo consider an alternative to always linking boost log
ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
Expand Down
110 changes: 110 additions & 0 deletions doc/howto/DataRecordingAndPlayback.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
====================
Data Analysis
====================

.. note:: I will interpret the data files, including the relative location and the main content.

How to collect data
==================================

In this project, the messages are communicated by `FlatBuffers <https://google.github.io/flatbuffers/>`__ between PC and Kuka workstation, which makes reading and writing data efficient.


1. Install `VREP <http://coppeliarobotics.com/>`__ and `grl <https://github.com/ahundt/robotics_setup>`__.

2. Start VREP and load the scene `RoboneSimulation_private.ttt <https://github.com/ahundt/robonetracker/blob/master/modules/roboneprivate/data/RoboneSimulation_private.ttt>`__.

3. Set flatbuffer limit in `robone.lua <https://github.com/ahundt/robonetracker/blob/master/modules/grl/src/lua/robone.lua>`__.
The hard limit for flatbuffer is 2 GB, but you can customize it based on your requirement in this project.
When flatbuffer size hits this limit, the data will be written to disk. Or when you click on the STOP button in VREP,
the data will also be written to disk automaticly, regardless of the limit::

KUKA_single_buffer_limit_bytes = 256 -- MB
FB_single_buffer_limit_bytes = 1024 -- MB

4. Start to record data while simulation is running in `robone.lua <https://github.com/ahundt/robonetracker/blob/master/modules/grl/src/lua/robone.lua>`__.
By defaut, program starts to collect data automatically. You can change it by following functions::
simExtKukaLBRiiwaRecordWhileSimulationIsRunning(true, KUKA_single_buffer_limit_bytes)
simExtAtracsysFusionTrackRecordWhileSimulationIsRunning(true, FB_single_buffer_limit_bytes)

5. Enable lua scripts StartRealArmDriverScript and Tracker in VREP, then program can communicate with Atracsys and Kuka.
Only after connecting the devices, it can start to record data correctly.

6. Stop recording data.
There are two ways to stop the data collection process, one is the buffer hits the limit in Step 3, the other is to click on the STOP button in VREP,
then it will stop and write the data to disk automatically.


The binary files are put in VREP data folder (i.e. ~/src/V-REP_PRO_EDU_V3_4_0_Linux/data/),
and are named by the time stamp (i.e. 2018_03_26_19_06_21_FusionTrack.flik, 2018_03_26_19_06_21_Kukaiiwa.iiwa).

The command to generate json file is as below, the binary file and the fbs file should be put in the same folder::
flatc -I . --json LogKUKAiiwaFusionTrack.fbs -- 2018_03_26_19_06_21_FusionTrack.flik
flatc -I . --json KUKAiiwa.fbs -- 2018_03_26_19_06_21_Kukaiiwa.iiwa

How to export data
==================================

When exporting the flatbuffer file to CSV, you need to follow the instructions below:

1. Keep the binary files in the VREP data folder (i.e. ~/src/V-REP_PRO_EDU_V3_4_0_Linux/data/);

2. Run `readFlatbufferTest <https://github.com/ahundt/robonetracker/tree/master/modules/grl/test>`__ in terminal with the arguments of the name of binary file::

./readFlatbufferTest 2018_03_26_19_06_21_Kukaiiwa.iiwa 2018_03_26_19_06_21_FusionTrack.flik
# You can also pass the arguments manually to the main() function in readFlatbufferTest.cpp.

3. The generated csv files will be put into the VREP data folder in which the subfolder is named by time stamp.
Label explanation:
.. code-block:: bash
local_request_time_offset: PC time of sending a requesting command to devices;
local_receive_time_offset: PC time of receiving measured data from devices;
device_time_offset: the time from device;
time_Y: time driftting, device_time_offset - local_request_time_offset;
counter: the identifier of message, defined by devices;
X Y Z A B C: the cartesian postion and oritation in Plucker coordinate system;
M_Pos_J*: measured joint position of joint i from kuka;
C_Pos_J*: command joint position of joint i to kuka;
M_Tor_J*: measured joint torque of joint i form kuka;
C_Tor_J*: comand joint torque of joint i to kuka;
E_Tor_J*: external torque of joint i exerted on kuka;

# on the first message save local_request_time as the initial_local_request_time. Both kuka and Atracsys share the same initial_local_request_time, which means they have the same time axis.
# on the first message save device_time as the initial_device_time
X = local_request_time
local_request_offset = (local_request_time - initial_local_request_time)
device_offset = (device_time - initial_device_time)
time_Y = device_offset - local_request_offset

CSV file explanation:
FTKUKA_TimeEvent.csv has the information from both Atracsys and kuka. It can help analysis time event.
FT_Pose_Marker*.csv have the time event and pose (in Plucker coordinate) of the specific marker in Atracsys space;
FT_TimeEvent.csv gives more detail information about time event from Atracsys, such as the time step;
KUKA_FRIMessage.csv includes all the FRI message from robot;
KUKA_Command_Joint.csv has the commanding joint angle sent to robot, which should use local_request_time_offset as time axis when plotting;
KUKA_Measured_Joint.csv has the measured joint angles received from robt, which should use local_receive_time_offset as time axis when plotting.
KUKA_TimeEvent.csv gives more detail information about time event from kuka, such as the time step;

All the CSV files above are generated from binary files. To make it convenient, all the files have time event information, which can be used as X-axis when plotting.


Replay Process
==================================
The replay process can perform the forward kinematics to get the cartesian pose of the end effector.

1. Copy the KUKA_Measured_Joint.csv, KUKA_Command_Joint.csv and FT_Pose_Marker22.csv to the ~/src/V-REP_PRO_EDU_V3_4_0_Linux/data/data_in/.
The result will be writen in ForwardKinematics_Pose.csv.

2. Enable the CutBoneScript.

3. Set the parameter of simExtGrlInverseKinematicsStart(...) to replay_mode in robone.lua.
You should run this function two times, one time commanddata is true, the other is false. Then you can get the cartesian pose for both command and measured data::

-- ik_mode, run real inverse kinematics algorith;
-- replay_mode, run the replay process;
-- test_mode, go to a test pose;
-- commanddata, only in replay_mode we need to set it to select the joint data set.
commanddata = false
run_mode = { ik_mode = 1, replay_mode = 2, test_mode = 3}
print("Moving Robotiiwa arm along inversekinematics")
simExtGrlInverseKinematicsStart(run_mode.replay_mode, commanddata)
Loading