Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
104 changes: 104 additions & 0 deletions rm_vt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
cmake_minimum_required(VERSION 3.0.2)
project(rm_vt)

## Use C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

## By adding -Wall and -Werror, the compiler does not ignore warnings anymore,
## enforcing cleaner code.
add_definitions(-Wall -Werror -Wno-address-of-packed-member)

## Find catkin macros and libraries
find_package(serial REQUIRED)

find_package(catkin REQUIRED
COMPONENTS
sensor_msgs
roscpp
rm_msgs
serial
rm_common
tf2_geometry_msgs
std_msgs
actionlib
nav_msgs
)

## Find system libraries
#find_package(Eigen3 REQUIRED)

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS
include
LIBRARIES
CATKIN_DEPENDS
roscpp
sensor_msgs
rm_msgs
rm_common
tf2_geometry_msgs
std_msgs
actionlib
nav_msgs
DEPENDS
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
)

## Declare cpp executables
FILE(GLOB ALL_SOURCES "src/*.cpp" "src/common/*.cpp" )
add_executable(${PROJECT_NAME} ${ALL_SOURCES})

## Add dependencies to exported targets, like ROS msgs or srvs
add_dependencies(${PROJECT_NAME}
${catkin_EXPORTED_TARGETS}
)

## Specify libraries to link executable targets against
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)

#############
## Install ##
#############

# Mark executables and/or libraries for installation
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

# Mark cpp header files for installation
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)

## Mark other files for installation
install(
DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
116 changes: 116 additions & 0 deletions rm_vt/include/rm_vt/common/data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// Created by ch on 24-11-23.
//

#pragma once

#include <ros/ros.h>
#include <unistd.h>
#include <serial/serial.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/JointState.h>
#include <std_msgs/Float64.h>
#include <std_msgs/Int8MultiArray.h>
#include <std_msgs/UInt8MultiArray.h>
#include <tf2_ros/buffer.h>
#include <tf2_ros/transform_listener.h>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#include "std_msgs/UInt32.h"
#include "rm_msgs/VisualizeStateData.h"
#include "rm_msgs/CustomControllerData.h"
#include "rm_msgs/VTKeyboardMouseData.h"
#include "rm_msgs/VTReceiverControlData.h"

#include "rm_vt/common/protocol.h"

namespace rm_vt
{
class Base
{
public:
serial::Serial serial_;
bool video_transmission_is_online_ = false;

void initSerial()
{
serial::Timeout timeout = serial::Timeout::simpleTimeout(50);
serial_.setPort("/dev/usbImagetran");
serial_.setBaudrate(921600);
serial_.setTimeout(timeout);
if (serial_.isOpen())
return;
try
{
serial_.open();
}
catch (serial::IOException& e)
{
ROS_ERROR("Cannot open image transmitter port");
}
}

// CRC check
uint8_t getCRC8CheckSum(unsigned char* pch_message, unsigned int dw_length, unsigned char uc_crc_8)
{
unsigned char uc_index;
while (dw_length--)
{
uc_index = uc_crc_8 ^ (*pch_message++);
uc_crc_8 = rm_vt::kCrc8Table[uc_index];
}
return (uc_crc_8);
}

uint32_t verifyCRC8CheckSum(unsigned char* pch_message, unsigned int dw_length)
{
unsigned char uc_expected;
if ((pch_message == nullptr) || (dw_length <= 2))
return 0;
uc_expected = getCRC8CheckSum(pch_message, dw_length - 1, rm_vt::kCrc8Init);
return (uc_expected == pch_message[dw_length - 1]);
}

void appendCRC8CheckSum(unsigned char* pch_message, unsigned int dw_length)
{
unsigned char uc_crc;
if ((pch_message == nullptr) || (dw_length <= 2))
return;
uc_crc = getCRC8CheckSum((unsigned char*)pch_message, dw_length - 1, rm_vt::kCrc8Init);
pch_message[dw_length - 1] = uc_crc;
}

uint16_t getCRC16CheckSum(uint8_t* pch_message, uint32_t dw_length, uint16_t w_crc)
{
uint8_t chData;
if (pch_message == nullptr)
return 0xFFFF;
while (dw_length--)
{
chData = *pch_message++;
(w_crc) = (static_cast<uint16_t>(w_crc) >> 8) ^
rm_vt::wCRC_table[(static_cast<uint16_t>(w_crc) ^ static_cast<uint16_t>(chData)) & 0x00ff];
}
return w_crc;
}

uint32_t verifyCRC16CheckSum(uint8_t* pch_message, uint32_t dw_length)
{
uint16_t w_expected;
if ((pch_message == nullptr) || (dw_length <= 2))
return 0;
w_expected = getCRC16CheckSum(pch_message, dw_length - 2, rm_vt::kCrc16Init);
return ((w_expected & 0xff) == pch_message[dw_length - 2] &&
((w_expected >> 8) & 0xff) == pch_message[dw_length - 1]);
}

void appendCRC16CheckSum(uint8_t* pch_message, uint32_t dw_length)
{
uint16_t wCRC;
if ((pch_message == nullptr) || (dw_length <= 2))
return;
wCRC = getCRC16CheckSum(static_cast<uint8_t*>(pch_message), dw_length - 2, rm_vt::kCrc16Init);
pch_message[dw_length - 2] = static_cast<uint8_t>((wCRC & 0x00ff));
pch_message[dw_length - 1] = static_cast<uint8_t>(((wCRC >> 8) & 0x00ff));
}
};
} // namespace rm_vt
Loading
Loading