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

Integrate libtm source code #28

Merged
merged 25 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0fcc044
Enable BUILD_WITH_TM2 CMAKE flag
abernste Sep 12, 2018
baa997c
Initial commit
belkinirena Sep 12, 2018
996f25d
Add libtm source code to librealsense solution (#27)
belkinirena Sep 13, 2018
42c74be
Add libusb library (#28)
belkinirena Sep 13, 2018
fe52e5d
Add libtm source code to librealsense solution
belkinirena Sep 16, 2018
9f5add0
Cmake fixes
abernste Sep 20, 2018
4e4be8b
disable controller streams
belkinirena Sep 25, 2018
a49f54d
1. disable sync mode in viewer by default, 2. remove trajectory bound…
belkinirena Sep 26, 2018
af8e5ac
update pose and imu stream index
belkinirena Sep 26, 2018
d52ec13
Add tm2 temperature option for asic and motion
belkinirena Sep 26, 2018
c13e926
1. Fix linux compilation issues, 2.Update cmake to support linux
belkinirena Sep 27, 2018
03551d4
Change cmake to download TM2 FW from amazon s3
belkinirena Sep 27, 2018
062e8e0
Added libtm_util and rc recorder
belkinirena Oct 2, 2018
66b01f2
Libtm linux support
belkinirena Oct 3, 2018
bfeadf7
Added support in libusb as external project for Windows
belkinirena Oct 10, 2018
246d016
Move libtm library from third party to src directory
belkinirena Oct 10, 2018
64e9f37
Remove duplicate source code
belkinirena Oct 10, 2018
8c63933
Disable libtm logs by default
belkinirena Oct 10, 2018
679e301
Move libtm to third party directory
belkinirena Oct 11, 2018
1aabded
Fix linux compilation issues
belkinirena Oct 15, 2018
2df97b3
1. Fix cmake error 2. Remove tabs
belkinirena Oct 15, 2018
ac272a0
Remove infra cmake file
belkinirena Oct 15, 2018
40e4452
Add include directories to libtm
belkinirena Oct 15, 2018
0649fdf
Fix compilation error
belkinirena Oct 15, 2018
7c430e8
Fix cmake warning
belkinirena Oct 15, 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
5 changes: 4 additions & 1 deletion CMake/Findlibtm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ find_library(INFRA_LIBRARY_DEBUG
HINTS
"${LIBTM_DIR}/bin/Debug"
)

find_library(LIBUSB_LIBRARY
NAMES
libusb-1.0.lib
)

# handle the LIBTM and REQUIRED arguments and set LIBTM_FOUND to TRUE if
# all listed variables are TRUE
Expand Down
91 changes: 38 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ elseif(UNIX)
endif()


option(BUILD_WITH_TM2 "Build with support for Intel TM2 tracking device" OFF)
option(BUILD_WITH_TM2 "Build with support for Intel TM2 tracking device" ON)

option(BUILD_EASYLOGGINGPP "Build EasyLogging++ as a part of the build" ON)

Expand Down Expand Up @@ -785,44 +785,48 @@ if(HWM_OVER_XU)
add_definitions(-DHWM_OVER_XU)
endif()

if (NOT USE_SYSTEM_LIBUSB)
if(NOT WIN32 OR FORCE_LIBUVC)
include(ExternalProject)

ExternalProject_Add(
libusb

GIT_REPOSITORY "https://github.com/libusb/libusb.git"
GIT_TAG "master"

UPDATE_COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/third-party/libusb/CMakeLists.txt
${CMAKE_CURRENT_BINARY_DIR}/third-party/libusb/CMakeLists.txt
PATCH_COMMAND ""

SOURCE_DIR "third-party/libusb/"
CMAKE_ARGS -DCMAKE_CXX_STANDARD_LIBRARIES=${CMAKE_CXX_STANDARD_LIBRARIES}
if ((NOT USE_SYSTEM_LIBUSB AND FORCE_LIBUVC) OR (BUILD_WITH_TM2 AND WIN32))
include(ExternalProject)

ExternalProject_Add(
libusb

GIT_REPOSITORY "https://github.com/libusb/libusb.git"
GIT_TAG "master"

UPDATE_COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/third-party/libusb/CMakeLists.txt
${CMAKE_CURRENT_BINARY_DIR}/third-party/libusb/CMakeLists.txt
PATCH_COMMAND ""

SOURCE_DIR "third-party/libusb/"
CMAKE_ARGS -DCMAKE_CXX_STANDARD_LIBRARIES=${CMAKE_CXX_STANDARD_LIBRARIES}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/libusb_install

TEST_COMMAND ""
)

set(LIBUSB_LOCAL_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/libusb)

set(LIBUSB1_LIBRARY_DIRS ${CMAKE_CURRENT_BINARY_DIR}/libusb_install/lib)
link_directories(${LIBUSB1_LIBRARY_DIRS})

set(LIBUSB1_LIBRARIES usb log)
endif()
TEST_COMMAND ""
)

set(LIBUSB_LOCAL_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party/libusb)

set(LIBUSB1_LIBRARY_DIRS ${CMAKE_CURRENT_BINARY_DIR}/libusb_install/lib)
link_directories(${LIBUSB1_LIBRARY_DIRS})

set(LIBUSB1_LIBRARIES usb)

if(NOT WIN32)
set(LIBUSB1_LIBRARIES ${LIBUSB1_LIBRARIES} log)
endif()

endif()

add_subdirectory(third-party/realsense-file)


if (BUILD_WITH_TM2)
message(STATUS "Building with TM2")


add_subdirectory(third-party/libtm)

if(WIN32)
source_group("Source Files\\Devices\\Tracking" FILES
src/tm2/tm-context.cpp
Expand All @@ -837,22 +841,10 @@ if (BUILD_WITH_TM2)
src/tm2/tm-conversions.h
src/tm2/controller_event_serializer.h
)
add_dependencies(tm libusb)
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
find_package(libtm REQUIRED)

if(BUILD_WITH_STATIC_CRT)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()

list(APPEND REALSENSE_HPP
src/tm2/tm-context.h
Expand All @@ -867,16 +859,7 @@ if (BUILD_WITH_TM2)
src/tm2/tm-device.cpp
src/tm2/tm-info.cpp
)

include_directories(${LIBTM_INCLUDE_DIR})
set(TRACKING_DEVICE_LIBS libtm)

install(TARGETS libtm
EXPORT realsense2Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

endif()

if(LRS_TRY_USE_AVX)
Expand Down Expand Up @@ -904,6 +887,8 @@ endif()

if(BUILD_WITH_TM2)
target_compile_definitions(realsense2 PRIVATE WITH_TRACKING=1 BUILD_STATIC=1)
target_link_libraries(realsense2 PRIVATE tm ${CMAKE_THREAD_LIBS_INIT} ${TRACKING_DEVICE_LIBS})
target_include_directories(realsense2 PRIVATE third-party/libtm/libtm/include)
endif()
set_target_properties(realsense2 PROPERTIES VERSION ${REALSENSE_VERSION_STRING}
SOVERSION ${REALSENSE_VERSION_MAJOR})
Expand Down
92 changes: 1 addition & 91 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ namespace rs2
if (render_pose)
{
total_top_bar_height += top_bar_height; // add additional bar height for pose
const int num_of_pose_buttons = 3; // trajectory, draw camera, boundary selection
const int num_of_pose_buttons = 2; // trajectory, draw camera

ImGui::SetNextWindowPos({ stream_rect.x, stream_rect.y + buttons_heights });
ImGui::SetNextWindowSize({ stream_rect.w, buttons_heights });
Expand Down Expand Up @@ -2137,25 +2137,6 @@ namespace rs2
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", tm2.trajectory_button.get_tooltip().c_str());

// Draw boundary selection button
ImGui::SameLine();
color_icon = tm2.boundary_button.is_pressed(); //draw boundary is on - color the icon
if (color_icon)
{
ImGui::PushStyleColor(ImGuiCol_Text, light_blue);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_blue);
}
if (ImGui::Button(tm2.boundary_button.get_icon().c_str(), { 24, buttons_heights }))
{
tm2.boundary_button.toggle_button();
}
if (color_icon)
{
ImGui::PopStyleColor(2);
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", tm2.boundary_button.get_tooltip().c_str());

ImGui::End();
}

Expand Down Expand Up @@ -3864,7 +3845,6 @@ namespace rs2
rs2_vector translation{ pose_trans.mat[0][3], pose_trans.mat[1][3], pose_trans.mat[2][3] };
tracked_point p{ translation , pose_data.tracker_confidence }; //TODO: Osnat - use tracker_confidence or mapper_confidence ?
tm2.draw_trajectory(p);
tm2.draw_boundary(p);
}
}

Expand Down Expand Up @@ -6669,76 +6649,6 @@ namespace rs2
}
}

void tm2_model::draw_boundary(tracked_point& p)
{
if (!boundary_button.is_pressed())
{
//TODO - separate button
if (boundary.size() > 0)
{
//cleanup last boundary
boundary.clear();
}
return;
}

// if new boundary - grab from trajectory
if (boundary.size() == 0)
{
std::vector<float2> trajectory_projection;
//create the boundary from the trajectory
for (auto&& v : trajectory)
{
// project the trajectory on XZ plane - ignore y coordinate of the point
float2 p{ v.first.x, v.first.z };
trajectory_projection.push_back(p);
}
boundary = simplify_line(trajectory_projection);
}
// check if there is any boundary to render
if (boundary.size() == 0)
{
return;
}

// check if the current position is inside or outside the boundary, to color it accordingly
float2 point{ p.first.x, p.first.z };
bool inside = point_in_polygon_2D(boundary, point);
color c;
if (inside)
{
c = { 0.0f, 1.0f, 0.0f };
}
else
{
c = { 1.0f, 0.0f, 0.0f };
}
// draw the boundary lines parallel to XZ plane
glLineWidth(1.0f);
for (float height = -1.0f; height < 1.0f; height += 0.2f)
{
glBegin(GL_LINE_STRIP);
glColor3f(c[0], c[1], c[2]);
for (auto&& v : boundary)
{
glVertex3f(v.x, height, v.y);
}
glVertex3f(boundary[0].x, height, boundary[0].y);
glEnd();
}

// draw vertical lines along the boundary
glLineWidth(1.0f);
glBegin(GL_LINES);
glColor3f(c[0], c[1], c[2]);
for (auto&& v : boundary)
{
glVertex3f(v.x, -1.0f, v.y);
glVertex3f(v.x, 1.0f, v.y);
}
glEnd();
}

std::string get_timestamped_file_name()
{
std::time_t now = std::time(NULL);
Expand Down
4 changes: 1 addition & 3 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,9 @@ namespace rs2
void draw_controller_pose_object();
void draw_pose_object();
void draw_trajectory(tracked_point& p);
void draw_boundary(tracked_point& p);

press_button_model trajectory_button{ u8"\uf1b0", u8"\uf1b0","Draw trajectory", "Stop drawing trajectory" };
press_button_model camera_object_button{ u8"\uf047", u8"\uf083", "Draw pose axis", "Draw camera pose" };
press_button_model boundary_button{ u8"\uf278", u8"\uf278", "Set trajectory as boundary", "Discard boundary" };

private:
void add_to_trajectory(tracked_point& p);
Expand Down Expand Up @@ -823,7 +821,7 @@ namespace rs2

viewer_model()
: ppf(*this),
synchronization_enable(true)
synchronization_enable(false)
{
s.start(ppf.syncer_queue);
reset_camera();
Expand Down
37 changes: 1 addition & 36 deletions src/tm2/controller_event_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,6 @@ namespace librealsense
return oss.str();
}

std::string get_string(perc::Status value)
{

#define CASE_RETURN_STR(X) case perc::Status::##X: {\
static std::string s##X##_str = make_less_screamy(#X);\
return s##X##_str; }

switch (value)
{
CASE_RETURN_STR(SUCCESS)
CASE_RETURN_STR(COMMON_ERROR)
CASE_RETURN_STR(FEATURE_UNSUPPORTED)
CASE_RETURN_STR(ERROR_PARAMETER_INVALID)
CASE_RETURN_STR(INIT_FAILED)
CASE_RETURN_STR(ALLOC_FAILED)
CASE_RETURN_STR(ERROR_USB_TRANSFER)
CASE_RETURN_STR(ERROR_EEPROM_VERIFY_FAIL)
CASE_RETURN_STR(ERROR_FW_INTERNAL)
CASE_RETURN_STR(BUFFER_TOO_SMALL)
CASE_RETURN_STR(NOT_SUPPORTED_BY_FW)
CASE_RETURN_STR(DEVICE_BUSY)
CASE_RETURN_STR(TIMEOUT)
CASE_RETURN_STR(TABLE_NOT_EXIST)
CASE_RETURN_STR(TABLE_LOCKED)
CASE_RETURN_STR(DEVICE_STOPPED)
CASE_RETURN_STR(TEMPERATURE_WARNING)
CASE_RETURN_STR(TEMPERATURE_STOP)
CASE_RETURN_STR(CRC_ERROR)
CASE_RETURN_STR(INCOMPATIBLE)
CASE_RETURN_STR(SLAM_NO_DICTIONARY)
default: return to_string() << "Unknown (" << (int)value << ")";
}
#undef CASE_RETURN_STR
}

inline std::ostream& operator<<(std::ostream& os, const perc::TrackingData::Version& v)
{
return os << v.major << "." << v.minor << "." << v.patch << "." << v.build;
Expand Down Expand Up @@ -95,7 +60,7 @@ namespace librealsense
static std::string serialized_data(const perc::TrackingData::ControllerConnectedEventFrame& frame)
{
std::string serialized_data = to_string() <<
"\"status\": \"" << get_string(frame.status) << "\","
"\"status\": \"" << (int)frame.status << "\","
"\"controllerId\": " << (int)frame.controllerId << ","
"\"manufacturerId\": " << (int)frame.manufacturerId << ","
"\"protocol\": \"" << frame.protocol << "\","
Expand Down
8 changes: 4 additions & 4 deletions src/tm2/tm-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace librealsense
tm2_context::tm2_context(context* ctx)
: _is_disposed(false), _t(&tm2_context::thread_proc, this), _ctx(ctx)
{
_manager = std::shared_ptr<TrackingManager>(perc::TrackingManager::CreateInstance(this),
_manager = std::shared_ptr<TrackingManager>(perc::TrackingManager::CreateInstance(this),
[](perc::TrackingManager* ptr) { perc::TrackingManager::ReleaseInstance(ptr); });
if (_manager == nullptr)
{
Expand Down Expand Up @@ -48,7 +48,7 @@ namespace librealsense

}

void tm2_context::onStateChanged(TrackingManager::EventType state, TrackingDevice* dev)
void tm2_context::onStateChanged(TrackingManager::EventType state, TrackingDevice* dev, TrackingData::DeviceInfo devInfo)
{
std::shared_ptr<tm2_info> added;
std::shared_ptr<tm2_info> removed;
Expand All @@ -73,9 +73,9 @@ namespace librealsense
on_device_changed(removed, added);
}

void tm2_context::onError(TrackingManager::Error error, TrackingDevice* dev)
void tm2_context::onError(Status error, TrackingDevice* dev)
{
LOG_ERROR("Error occured while connecting device:" << dev << " Error: 0x" << std::hex << error);
LOG_ERROR("Error occured while connecting device:" << dev << " Error: 0x" << std::hex << static_cast<int>(error));
}

void tm2_context::thread_proc()
Expand Down
4 changes: 2 additions & 2 deletions src/tm2/tm-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace librealsense
std::vector<perc::TrackingDevice*> query_devices() const;
signal<tm2_context, std::shared_ptr<tm2_info>, std::shared_ptr<tm2_info>> on_device_changed;
// TrackingManager::Listener
void onStateChanged(perc::TrackingManager::EventType state, perc::TrackingDevice*) override;
void onError(perc::TrackingManager::Error error, perc::TrackingDevice*) override;
void onStateChanged(perc::TrackingManager::EventType state, perc::TrackingDevice* device, perc::TrackingData::DeviceInfo deviceInfo) override;
void onError(perc::Status error, perc::TrackingDevice*) override;
private:
void thread_proc();
friend class connect_disconnect_listener;
Expand Down
Loading