mirror of
https://github.com/westonrobot/scout_ros.git
synced 2026-01-12 03:15:01 +08:00
updated to latest implementation
This commit is contained in:
@@ -4,9 +4,10 @@ project(scout_base)
|
||||
## Compile as C++11, supported in ROS Kinetic and newer
|
||||
add_compile_options(-std=c++11)
|
||||
|
||||
find_package(catkin REQUIRED COMPONENTS
|
||||
controller_manager
|
||||
hardware_interface
|
||||
# cmake module path
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
find_package(catkin REQUIRED COMPONENTS
|
||||
roslaunch
|
||||
roslint
|
||||
roscpp
|
||||
@@ -14,8 +15,13 @@ find_package(catkin REQUIRED COMPONENTS
|
||||
std_msgs
|
||||
geometry_msgs
|
||||
scout_msgs
|
||||
tf)
|
||||
scout_sdk
|
||||
tf2
|
||||
tf2_ros
|
||||
)
|
||||
|
||||
# find_package(LCM REQUIRED)
|
||||
|
||||
# find_package(Boost REQUIRED COMPONENTS chrono)
|
||||
|
||||
###################################
|
||||
@@ -24,8 +30,8 @@ find_package(catkin REQUIRED COMPONENTS
|
||||
|
||||
catkin_package(
|
||||
INCLUDE_DIRS include
|
||||
LIBRARIES scoutbase
|
||||
CATKIN_DEPENDS hardware_interface scout_msgs roscpp sensor_msgs
|
||||
LIBRARIES scout_messenger
|
||||
CATKIN_DEPENDS scout_msgs roscpp sensor_msgs scout_sdk
|
||||
# DEPENDS Boost
|
||||
)
|
||||
|
||||
@@ -38,31 +44,35 @@ catkin_package(
|
||||
include_directories(
|
||||
include
|
||||
${catkin_INCLUDE_DIRS}
|
||||
${LCM_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# add scout sdk
|
||||
add_subdirectory(src/scout_sdk)
|
||||
|
||||
add_library(scout_messenger STATIC src/scout_messenger.cpp)
|
||||
target_link_libraries(scout_messenger scoutbase ${catkin_LIBRARIES})
|
||||
target_link_libraries(scout_messenger ${catkin_LIBRARIES})
|
||||
set_property(TARGET scout_messenger PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
add_executable(scout_base_node src/scout_base_node.cpp)
|
||||
target_link_libraries(scout_base_node scoutbase scout_messenger ${catkin_LIBRARIES})
|
||||
target_link_libraries(scout_base_node scout_messenger ${catkin_LIBRARIES})
|
||||
|
||||
# add_executable(imu_broadcast_node src/imu_broadcast_node.cpp)
|
||||
# target_link_libraries(imu_broadcast_node ${catkin_LIBRARIES} ${LCM_LIBRARIES})
|
||||
|
||||
#############
|
||||
## Install ##
|
||||
#############
|
||||
|
||||
# roslaunch_add_file_check(launch)
|
||||
roslaunch_add_file_check(launch)
|
||||
|
||||
# install(TARGETS scoutcpp scoutio scout_base
|
||||
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
||||
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
|
||||
install(TARGETS scout_messenger scout_base_node
|
||||
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
|
||||
|
||||
# install(DIRECTORY include/${PROJECT_NAME}/
|
||||
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
|
||||
install(DIRECTORY include/${PROJECT_NAME}/
|
||||
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
|
||||
|
||||
# install(DIRECTORY launch config
|
||||
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
|
||||
install(DIRECTORY include/lcmtypes
|
||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION})
|
||||
|
||||
install(DIRECTORY launch urdf
|
||||
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
|
||||
|
||||
36
scout_base/cmake/FindLCM.cmake
Normal file
36
scout_base/cmake/FindLCM.cmake
Normal file
@@ -0,0 +1,36 @@
|
||||
###############################################################################
|
||||
# Find package: lcm
|
||||
#
|
||||
# This sets the following variables:
|
||||
|
||||
# <package>_FOUND
|
||||
# <package>_INCLUDE_DIRS
|
||||
# <package>_LIBRARIES
|
||||
# Source: https://github.com/RobotLocomotion/director/blob/master/cmake/modules/FindLCM.cmake
|
||||
|
||||
|
||||
macro(pkg_config_find_module varname pkgname header library pathsuffix)
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(${varname}_pkgconfig ${pkgname})
|
||||
|
||||
find_path(${varname}_INCLUDE_DIR ${header}
|
||||
HINTS ${${varname}_pkgconfig_INCLUDEDIR}
|
||||
PATH_SUFFIXES ${pathsuffix}
|
||||
DOC "Path to ${pkgname} include directory")
|
||||
|
||||
find_library(${varname}_LIBRARY ${library} HINTS ${${varname}_pkgconfig_LIBDIR} DOC "Path to ${pkgname} library")
|
||||
|
||||
set(${varname}_INCLUDE_DIRS ${${varname}_INCLUDE_DIR})
|
||||
set(${varname}_LIBRARIES ${${varname}_LIBRARY})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(${varname} DEFAULT_MSG ${varname}_INCLUDE_DIR ${varname}_LIBRARY)
|
||||
|
||||
mark_as_advanced(${varname}_INCLUDE_DIR)
|
||||
mark_as_advanced(${varname}_LIBRARY)
|
||||
|
||||
endmacro()
|
||||
|
||||
|
||||
pkg_config_find_module(LCM lcm lcm/lcm.h lcm lcm)
|
||||
17
scout_base/include/lcmtypes/wescore.h
Normal file
17
scout_base/include/lcmtypes/wescore.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef __lcmtypes_wescore_h__
|
||||
#define __lcmtypes_wescore_h__
|
||||
|
||||
#include "wescore_lcm_msgs_IMU.h"
|
||||
#include "wescore_lcm_msgs_NavSatFix.h"
|
||||
#include "wescore_lcm_msgs_NavSatStatus.h"
|
||||
#include "wescore_lcm_msgs_Quaternion.h"
|
||||
#include "wescore_lcm_msgs_RawAccel.h"
|
||||
#include "wescore_lcm_msgs_RawGyro.h"
|
||||
#include "wescore_lcm_msgs_RawIMU10DOF.h"
|
||||
#include "wescore_lcm_msgs_RawIMU6DOF.h"
|
||||
#include "wescore_lcm_msgs_RawIMU9DOF.h"
|
||||
#include "wescore_lcm_msgs_RawMag.h"
|
||||
#include "wescore_lcm_msgs_Vector2.h"
|
||||
#include "wescore_lcm_msgs_Vector3.h"
|
||||
|
||||
#endif
|
||||
17
scout_base/include/lcmtypes/wescore.hpp
Normal file
17
scout_base/include/lcmtypes/wescore.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef __lcmtypes_wescore_hpp__
|
||||
#define __lcmtypes_wescore_hpp__
|
||||
|
||||
#include "wescore_lcm_msgs/IMU.hpp"
|
||||
#include "wescore_lcm_msgs/NavSatFix.hpp"
|
||||
#include "wescore_lcm_msgs/NavSatStatus.hpp"
|
||||
#include "wescore_lcm_msgs/Quaternion.hpp"
|
||||
#include "wescore_lcm_msgs/RawAccel.hpp"
|
||||
#include "wescore_lcm_msgs/RawGyro.hpp"
|
||||
#include "wescore_lcm_msgs/RawIMU10DOF.hpp"
|
||||
#include "wescore_lcm_msgs/RawIMU6DOF.hpp"
|
||||
#include "wescore_lcm_msgs/RawIMU9DOF.hpp"
|
||||
#include "wescore_lcm_msgs/RawMag.hpp"
|
||||
#include "wescore_lcm_msgs/Vector2.hpp"
|
||||
#include "wescore_lcm_msgs/Vector3.hpp"
|
||||
|
||||
#endif
|
||||
215
scout_base/include/lcmtypes/wescore_lcm_msgs/IMU.hpp
Normal file
215
scout_base/include/lcmtypes/wescore_lcm_msgs/IMU.hpp
Normal file
@@ -0,0 +1,215 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_IMU_hpp__
|
||||
#define __wescore_lcm_msgs_IMU_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
#include "lcmtypes/wescore_lcm_msgs/Quaternion.hpp"
|
||||
#include "lcmtypes/wescore_lcm_msgs/Vector3.hpp"
|
||||
#include "lcmtypes/wescore_lcm_msgs/Vector3.hpp"
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class IMU
|
||||
{
|
||||
public:
|
||||
int64_t mtime;
|
||||
|
||||
wescore_lcm_msgs::Quaternion orientation;
|
||||
|
||||
double orientation_covariance[9];
|
||||
|
||||
wescore_lcm_msgs::Vector3 angular_velocity;
|
||||
|
||||
double angular_velocity_covariance[9];
|
||||
|
||||
wescore_lcm_msgs::Vector3 linear_acceleration;
|
||||
|
||||
double linear_acceleration_covariance[9];
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "IMU"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int IMU::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int IMU::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int IMU::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t IMU::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* IMU::getTypeName()
|
||||
{
|
||||
return "IMU";
|
||||
}
|
||||
|
||||
int IMU::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->orientation._encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->orientation_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->angular_velocity._encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->angular_velocity_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->linear_acceleration._encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->linear_acceleration_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int IMU::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->orientation._decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->orientation_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->angular_velocity._decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->angular_velocity_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->linear_acceleration._decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->linear_acceleration_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int IMU::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int64_t_encoded_array_size(NULL, 1);
|
||||
enc_size += this->orientation._getEncodedSizeNoHash();
|
||||
enc_size += __double_encoded_array_size(NULL, 9);
|
||||
enc_size += this->angular_velocity._getEncodedSizeNoHash();
|
||||
enc_size += __double_encoded_array_size(NULL, 9);
|
||||
enc_size += this->linear_acceleration._getEncodedSizeNoHash();
|
||||
enc_size += __double_encoded_array_size(NULL, 9);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t IMU::_computeHash(const __lcm_hash_ptr *p)
|
||||
{
|
||||
const __lcm_hash_ptr *fp;
|
||||
for(fp = p; fp != NULL; fp = fp->parent)
|
||||
if(fp->v == IMU::getHash)
|
||||
return 0;
|
||||
const __lcm_hash_ptr cp = { p, IMU::getHash };
|
||||
|
||||
uint64_t hash = 0xac2e31fe8e135e97LL +
|
||||
wescore_lcm_msgs::Quaternion::_computeHash(&cp) +
|
||||
wescore_lcm_msgs::Vector3::_computeHash(&cp) +
|
||||
wescore_lcm_msgs::Vector3::_computeHash(&cp);
|
||||
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
224
scout_base/include/lcmtypes/wescore_lcm_msgs/NavSatFix.hpp
Normal file
224
scout_base/include/lcmtypes/wescore_lcm_msgs/NavSatFix.hpp
Normal file
@@ -0,0 +1,224 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_NavSatFix_hpp__
|
||||
#define __wescore_lcm_msgs_NavSatFix_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
#include "lcmtypes/wescore_lcm_msgs/NavSatStatus.hpp"
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class NavSatFix
|
||||
{
|
||||
public:
|
||||
wescore_lcm_msgs::NavSatStatus status;
|
||||
|
||||
double latitude;
|
||||
|
||||
double longitude;
|
||||
|
||||
double altitude;
|
||||
|
||||
double position_covariance[9];
|
||||
|
||||
int8_t position_covariance_type;
|
||||
|
||||
public:
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t COVARIANCE_TYPE_UNKNOWN = 0;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t COVARIANCE_TYPE_APPROXIMATED = 1;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t COVARIANCE_TYPE_DIAGONAL_KNOWN = 2;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t COVARIANCE_TYPE_KNOWN = 3;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "NavSatFix"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int NavSatFix::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatFix::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatFix::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t NavSatFix::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* NavSatFix::getTypeName()
|
||||
{
|
||||
return "NavSatFix";
|
||||
}
|
||||
|
||||
int NavSatFix::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = this->status._encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->latitude, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->longitude, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->altitude, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->position_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __int8_t_encode_array(buf, offset + pos, maxlen - pos, &this->position_covariance_type, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatFix::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = this->status._decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->latitude, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->longitude, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->altitude, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->position_covariance[0], 9);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __int8_t_decode_array(buf, offset + pos, maxlen - pos, &this->position_covariance_type, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatFix::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += this->status._getEncodedSizeNoHash();
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 9);
|
||||
enc_size += __int8_t_encoded_array_size(NULL, 1);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t NavSatFix::_computeHash(const __lcm_hash_ptr *p)
|
||||
{
|
||||
const __lcm_hash_ptr *fp;
|
||||
for(fp = p; fp != NULL; fp = fp->parent)
|
||||
if(fp->v == NavSatFix::getHash)
|
||||
return 0;
|
||||
const __lcm_hash_ptr cp = { p, NavSatFix::getHash };
|
||||
|
||||
uint64_t hash = 0x60c5a36268b1a1a0LL +
|
||||
wescore_lcm_msgs::NavSatStatus::_computeHash(&cp);
|
||||
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
200
scout_base/include/lcmtypes/wescore_lcm_msgs/NavSatStatus.hpp
Normal file
200
scout_base/include/lcmtypes/wescore_lcm_msgs/NavSatStatus.hpp
Normal file
@@ -0,0 +1,200 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_NavSatStatus_hpp__
|
||||
#define __wescore_lcm_msgs_NavSatStatus_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
/// GPS
|
||||
class NavSatStatus
|
||||
{
|
||||
public:
|
||||
int8_t status;
|
||||
|
||||
int16_t service;
|
||||
|
||||
public:
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t STATUS_NO_FIX = -1;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t STATUS_FIX = 0;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t STATUS_SBAS_FIX = 1;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int8_t STATUS_GBAS_FIX = 2;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int16_t SERVICE_GPS = 1;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int16_t SERVICE_GLONASS = 2;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int16_t SERVICE_COMPASS = 4;
|
||||
// If you're using C++11 and are getting compiler errors saying
|
||||
// things like ‘constexpr’ needed for in-class initialization of
|
||||
// static data member then re-run lcm-gen with '--cpp-std=c++11'
|
||||
// to generate code that is compliant with C++11
|
||||
static const int16_t SERVICE_GALILEO = 8;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "NavSatStatus"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int NavSatStatus::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatStatus::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatStatus::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t NavSatStatus::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* NavSatStatus::getTypeName()
|
||||
{
|
||||
return "NavSatStatus";
|
||||
}
|
||||
|
||||
int NavSatStatus::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int8_t_encode_array(buf, offset + pos, maxlen - pos, &this->status, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, &this->service, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatStatus::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int8_t_decode_array(buf, offset + pos, maxlen - pos, &this->status, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, &this->service, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int NavSatStatus::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int8_t_encoded_array_size(NULL, 1);
|
||||
enc_size += __int16_t_encoded_array_size(NULL, 1);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t NavSatStatus::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0x76b236592075c1dbLL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
175
scout_base/include/lcmtypes/wescore_lcm_msgs/Quaternion.hpp
Normal file
175
scout_base/include/lcmtypes/wescore_lcm_msgs/Quaternion.hpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_Quaternion_hpp__
|
||||
#define __wescore_lcm_msgs_Quaternion_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class Quaternion
|
||||
{
|
||||
public:
|
||||
double x;
|
||||
|
||||
double y;
|
||||
|
||||
double z;
|
||||
|
||||
double w;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "Quaternion"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int Quaternion::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Quaternion::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Quaternion::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t Quaternion::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* Quaternion::getTypeName()
|
||||
{
|
||||
return "Quaternion";
|
||||
}
|
||||
|
||||
int Quaternion::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->x, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->y, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->z, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->w, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Quaternion::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->x, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->y, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->z, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->w, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Quaternion::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t Quaternion::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0x9b1dee9dfc8c0515LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
157
scout_base/include/lcmtypes/wescore_lcm_msgs/RawAccel.hpp
Normal file
157
scout_base/include/lcmtypes/wescore_lcm_msgs/RawAccel.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_RawAccel_hpp__
|
||||
#define __wescore_lcm_msgs_RawAccel_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class RawAccel
|
||||
{
|
||||
public:
|
||||
int64_t mtime;
|
||||
|
||||
float accel[3];
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "RawAccel"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int RawAccel::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawAccel::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawAccel::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t RawAccel::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* RawAccel::getTypeName()
|
||||
{
|
||||
return "RawAccel";
|
||||
}
|
||||
|
||||
int RawAccel::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawAccel::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawAccel::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int64_t_encoded_array_size(NULL, 1);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t RawAccel::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0x1317644918cca9a1LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
158
scout_base/include/lcmtypes/wescore_lcm_msgs/RawGyro.hpp
Normal file
158
scout_base/include/lcmtypes/wescore_lcm_msgs/RawGyro.hpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_RawGyro_hpp__
|
||||
#define __wescore_lcm_msgs_RawGyro_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
/// IMU data
|
||||
class RawGyro
|
||||
{
|
||||
public:
|
||||
int64_t mtime;
|
||||
|
||||
float gyro[3];
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "RawGyro"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int RawGyro::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawGyro::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawGyro::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t RawGyro::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* RawGyro::getTypeName()
|
||||
{
|
||||
return "RawGyro";
|
||||
}
|
||||
|
||||
int RawGyro::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawGyro::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawGyro::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int64_t_encoded_array_size(NULL, 1);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t RawGyro::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0xc2ebea5c61fc00c8LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
175
scout_base/include/lcmtypes/wescore_lcm_msgs/RawIMU10DOF.hpp
Normal file
175
scout_base/include/lcmtypes/wescore_lcm_msgs/RawIMU10DOF.hpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_RawIMU10DOF_hpp__
|
||||
#define __wescore_lcm_msgs_RawIMU10DOF_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class RawIMU10DOF
|
||||
{
|
||||
public:
|
||||
int64_t mtime;
|
||||
|
||||
float gyro[3];
|
||||
|
||||
float accel[3];
|
||||
|
||||
float baro;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "RawIMU10DOF"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int RawIMU10DOF::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU10DOF::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU10DOF::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t RawIMU10DOF::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* RawIMU10DOF::getTypeName()
|
||||
{
|
||||
return "RawIMU10DOF";
|
||||
}
|
||||
|
||||
int RawIMU10DOF::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->baro, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU10DOF::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->baro, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU10DOF::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int64_t_encoded_array_size(NULL, 1);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
enc_size += __float_encoded_array_size(NULL, 1);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t RawIMU10DOF::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0xd27571225f0da045LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
166
scout_base/include/lcmtypes/wescore_lcm_msgs/RawIMU6DOF.hpp
Normal file
166
scout_base/include/lcmtypes/wescore_lcm_msgs/RawIMU6DOF.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_RawIMU6DOF_hpp__
|
||||
#define __wescore_lcm_msgs_RawIMU6DOF_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class RawIMU6DOF
|
||||
{
|
||||
public:
|
||||
int64_t mtime;
|
||||
|
||||
float gyro[3];
|
||||
|
||||
float accel[3];
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "RawIMU6DOF"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int RawIMU6DOF::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU6DOF::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU6DOF::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t RawIMU6DOF::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* RawIMU6DOF::getTypeName()
|
||||
{
|
||||
return "RawIMU6DOF";
|
||||
}
|
||||
|
||||
int RawIMU6DOF::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU6DOF::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU6DOF::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int64_t_encoded_array_size(NULL, 1);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t RawIMU6DOF::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0x825c4435b1c7fa46LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
175
scout_base/include/lcmtypes/wescore_lcm_msgs/RawIMU9DOF.hpp
Normal file
175
scout_base/include/lcmtypes/wescore_lcm_msgs/RawIMU9DOF.hpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_RawIMU9DOF_hpp__
|
||||
#define __wescore_lcm_msgs_RawIMU9DOF_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class RawIMU9DOF
|
||||
{
|
||||
public:
|
||||
int64_t mtime;
|
||||
|
||||
float gyro[3];
|
||||
|
||||
float accel[3];
|
||||
|
||||
float magn[3];
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "RawIMU9DOF"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int RawIMU9DOF::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU9DOF::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU9DOF::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t RawIMU9DOF::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* RawIMU9DOF::getTypeName()
|
||||
{
|
||||
return "RawIMU9DOF";
|
||||
}
|
||||
|
||||
int RawIMU9DOF::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->magn[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU9DOF::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->gyro[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->accel[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->magn[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawIMU9DOF::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int64_t_encoded_array_size(NULL, 1);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t RawIMU9DOF::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0x225ef7a05c5d1715LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
157
scout_base/include/lcmtypes/wescore_lcm_msgs/RawMag.hpp
Normal file
157
scout_base/include/lcmtypes/wescore_lcm_msgs/RawMag.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_RawMag_hpp__
|
||||
#define __wescore_lcm_msgs_RawMag_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class RawMag
|
||||
{
|
||||
public:
|
||||
int64_t mtime;
|
||||
|
||||
float magn[3];
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "RawMag"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int RawMag::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawMag::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawMag::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t RawMag::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* RawMag::getTypeName()
|
||||
{
|
||||
return "RawMag";
|
||||
}
|
||||
|
||||
int RawMag::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_encode_array(buf, offset + pos, maxlen - pos, &this->magn[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawMag::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this->mtime, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __float_decode_array(buf, offset + pos, maxlen - pos, &this->magn[0], 3);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int RawMag::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __int64_t_encoded_array_size(NULL, 1);
|
||||
enc_size += __float_encoded_array_size(NULL, 3);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t RawMag::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0xc2ebe073b6fa00c8LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
157
scout_base/include/lcmtypes/wescore_lcm_msgs/Vector2.hpp
Normal file
157
scout_base/include/lcmtypes/wescore_lcm_msgs/Vector2.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_Vector2_hpp__
|
||||
#define __wescore_lcm_msgs_Vector2_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class Vector2
|
||||
{
|
||||
public:
|
||||
double x;
|
||||
|
||||
double y;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "Vector2"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int Vector2::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector2::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector2::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t Vector2::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* Vector2::getTypeName()
|
||||
{
|
||||
return "Vector2";
|
||||
}
|
||||
|
||||
int Vector2::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->x, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->y, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector2::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->x, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->y, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector2::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t Vector2::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0xd259512e30b44885LL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
166
scout_base/include/lcmtypes/wescore_lcm_msgs/Vector3.hpp
Normal file
166
scout_base/include/lcmtypes/wescore_lcm_msgs/Vector3.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
* BY HAND!!
|
||||
*
|
||||
* Generated by lcm-gen
|
||||
**/
|
||||
|
||||
#ifndef __wescore_lcm_msgs_Vector3_hpp__
|
||||
#define __wescore_lcm_msgs_Vector3_hpp__
|
||||
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
|
||||
|
||||
namespace wescore_lcm_msgs
|
||||
{
|
||||
|
||||
class Vector3
|
||||
{
|
||||
public:
|
||||
double x;
|
||||
|
||||
double y;
|
||||
|
||||
double z;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Encode a message into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at thie byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally be
|
||||
* equal to getEncodedSize().
|
||||
* @return The number of bytes encoded, or <0 on error.
|
||||
*/
|
||||
inline int encode(void *buf, int offset, int maxlen) const;
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode this message.
|
||||
*/
|
||||
inline int getEncodedSize() const;
|
||||
|
||||
/**
|
||||
* Decode a message from binary form into this instance.
|
||||
*
|
||||
* @param buf The buffer containing the encoded message.
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
inline int decode(const void *buf, int offset, int maxlen);
|
||||
|
||||
/**
|
||||
* Retrieve the 64-bit fingerprint identifying the structure of the message.
|
||||
* Note that the fingerprint is the same for all instances of the same
|
||||
* message type, and is a fingerprint on the message type definition, not on
|
||||
* the message contents.
|
||||
*/
|
||||
inline static int64_t getHash();
|
||||
|
||||
/**
|
||||
* Returns "Vector3"
|
||||
*/
|
||||
inline static const char* getTypeName();
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
|
||||
inline int _getEncodedSizeNoHash() const;
|
||||
inline int _decodeNoHash(const void *buf, int offset, int maxlen);
|
||||
inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
|
||||
};
|
||||
|
||||
int Vector3::encode(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
int64_t hash = getHash();
|
||||
|
||||
tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector3::decode(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, thislen;
|
||||
|
||||
int64_t msg_hash;
|
||||
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
if (msg_hash != getHash()) return -1;
|
||||
|
||||
thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
|
||||
if (thislen < 0) return thislen; else pos += thislen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector3::getEncodedSize() const
|
||||
{
|
||||
return 8 + _getEncodedSizeNoHash();
|
||||
}
|
||||
|
||||
int64_t Vector3::getHash()
|
||||
{
|
||||
static int64_t hash = static_cast<int64_t>(_computeHash(NULL));
|
||||
return hash;
|
||||
}
|
||||
|
||||
const char* Vector3::getTypeName()
|
||||
{
|
||||
return "Vector3";
|
||||
}
|
||||
|
||||
int Vector3::_encodeNoHash(void *buf, int offset, int maxlen) const
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->x, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->y, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->z, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector3::_decodeNoHash(const void *buf, int offset, int maxlen)
|
||||
{
|
||||
int pos = 0, tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->x, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->y, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->z, 1);
|
||||
if(tlen < 0) return tlen; else pos += tlen;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
int Vector3::_getEncodedSizeNoHash() const
|
||||
{
|
||||
int enc_size = 0;
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
enc_size += __double_encoded_array_size(NULL, 1);
|
||||
return enc_size;
|
||||
}
|
||||
|
||||
uint64_t Vector3::_computeHash(const __lcm_hash_ptr *)
|
||||
{
|
||||
uint64_t hash = 0x573f2fdd2f76508fLL;
|
||||
return (hash<<1) + ((hash>>63)&1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
155
scout_base/include/lcmtypes/wescore_lcm_msgs_IMU.h
Normal file
155
scout_base/include/lcmtypes/wescore_lcm_msgs_IMU.h
Normal file
@@ -0,0 +1,155 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_IMU_h
|
||||
#define _wescore_lcm_msgs_IMU_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lcmtypes/wescore_lcm_msgs_Quaternion.h"
|
||||
#include "lcmtypes/wescore_lcm_msgs_Vector3.h"
|
||||
#include "lcmtypes/wescore_lcm_msgs_Vector3.h"
|
||||
typedef struct _wescore_lcm_msgs_IMU wescore_lcm_msgs_IMU;
|
||||
struct _wescore_lcm_msgs_IMU
|
||||
{
|
||||
int64_t mtime;
|
||||
wescore_lcm_msgs_Quaternion orientation;
|
||||
double orientation_covariance[9];
|
||||
wescore_lcm_msgs_Vector3 angular_velocity;
|
||||
double angular_velocity_covariance[9];
|
||||
wescore_lcm_msgs_Vector3 linear_acceleration;
|
||||
double linear_acceleration_covariance[9];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_IMU.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_IMU_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_IMU* wescore_lcm_msgs_IMU_copy(const wescore_lcm_msgs_IMU* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_IMU created by wescore_lcm_msgs_IMU_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_IMU_destroy(wescore_lcm_msgs_IMU* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_IMU_subscription_t wescore_lcm_msgs_IMU_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_IMU is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_IMU_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_IMU *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_IMU using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_IMU_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_IMU *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_IMU using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_IMU_subscription_t* wescore_lcm_msgs_IMU_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_IMU_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_IMU_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_IMU_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_IMU_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_IMU_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_IMU_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_IMU into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_IMU_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_IMU_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_IMU *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_IMU from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_IMU_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_IMU_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_IMU *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_IMU_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_IMU_decode_cleanup(wescore_lcm_msgs_IMU *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_IMU
|
||||
*/
|
||||
int wescore_lcm_msgs_IMU_encoded_size(const wescore_lcm_msgs_IMU *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_IMU_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_IMU_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_IMU_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_IMU *p, int elements);
|
||||
int __wescore_lcm_msgs_IMU_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_IMU *p, int elements);
|
||||
int __wescore_lcm_msgs_IMU_decode_array_cleanup(wescore_lcm_msgs_IMU *p, int elements);
|
||||
int __wescore_lcm_msgs_IMU_encoded_array_size(const wescore_lcm_msgs_IMU *p, int elements);
|
||||
int __wescore_lcm_msgs_IMU_clone_array(const wescore_lcm_msgs_IMU *p, wescore_lcm_msgs_IMU *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
157
scout_base/include/lcmtypes/wescore_lcm_msgs_NavSatFix.h
Normal file
157
scout_base/include/lcmtypes/wescore_lcm_msgs_NavSatFix.h
Normal file
@@ -0,0 +1,157 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_NavSatFix_h
|
||||
#define _wescore_lcm_msgs_NavSatFix_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lcmtypes/wescore_lcm_msgs_NavSatStatus.h"
|
||||
#define WESCORE_LCM_MSGS_NAVSATFIX_COVARIANCE_TYPE_UNKNOWN 0
|
||||
#define WESCORE_LCM_MSGS_NAVSATFIX_COVARIANCE_TYPE_APPROXIMATED 1
|
||||
#define WESCORE_LCM_MSGS_NAVSATFIX_COVARIANCE_TYPE_DIAGONAL_KNOWN 2
|
||||
#define WESCORE_LCM_MSGS_NAVSATFIX_COVARIANCE_TYPE_KNOWN 3
|
||||
|
||||
typedef struct _wescore_lcm_msgs_NavSatFix wescore_lcm_msgs_NavSatFix;
|
||||
struct _wescore_lcm_msgs_NavSatFix
|
||||
{
|
||||
wescore_lcm_msgs_NavSatStatus status;
|
||||
double latitude;
|
||||
double longitude;
|
||||
double altitude;
|
||||
double position_covariance[9];
|
||||
int8_t position_covariance_type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_NavSatFix.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_NavSatFix_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_NavSatFix* wescore_lcm_msgs_NavSatFix_copy(const wescore_lcm_msgs_NavSatFix* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_NavSatFix created by wescore_lcm_msgs_NavSatFix_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_NavSatFix_destroy(wescore_lcm_msgs_NavSatFix* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_NavSatFix_subscription_t wescore_lcm_msgs_NavSatFix_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_NavSatFix is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_NavSatFix_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_NavSatFix *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_NavSatFix using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatFix_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_NavSatFix *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_NavSatFix using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_NavSatFix_subscription_t* wescore_lcm_msgs_NavSatFix_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_NavSatFix_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_NavSatFix_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatFix_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_NavSatFix_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatFix_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_NavSatFix_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_NavSatFix into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_NavSatFix_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatFix_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_NavSatFix *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_NavSatFix from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_NavSatFix_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatFix_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_NavSatFix *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_NavSatFix_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatFix_decode_cleanup(wescore_lcm_msgs_NavSatFix *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_NavSatFix
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatFix_encoded_size(const wescore_lcm_msgs_NavSatFix *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_NavSatFix_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_NavSatFix_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_NavSatFix_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_NavSatFix *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatFix_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_NavSatFix *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatFix_decode_array_cleanup(wescore_lcm_msgs_NavSatFix *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatFix_encoded_array_size(const wescore_lcm_msgs_NavSatFix *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatFix_clone_array(const wescore_lcm_msgs_NavSatFix *p, wescore_lcm_msgs_NavSatFix *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
157
scout_base/include/lcmtypes/wescore_lcm_msgs_NavSatStatus.h
Normal file
157
scout_base/include/lcmtypes/wescore_lcm_msgs_NavSatStatus.h
Normal file
@@ -0,0 +1,157 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_NavSatStatus_h
|
||||
#define _wescore_lcm_msgs_NavSatStatus_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_STATUS_NO_FIX -1
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_STATUS_FIX 0
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_STATUS_SBAS_FIX 1
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_STATUS_GBAS_FIX 2
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_SERVICE_GPS 1
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_SERVICE_GLONASS 2
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_SERVICE_COMPASS 4
|
||||
#define WESCORE_LCM_MSGS_NAVSATSTATUS_SERVICE_GALILEO 8
|
||||
|
||||
/// GPS
|
||||
typedef struct _wescore_lcm_msgs_NavSatStatus wescore_lcm_msgs_NavSatStatus;
|
||||
struct _wescore_lcm_msgs_NavSatStatus
|
||||
{
|
||||
int8_t status;
|
||||
int16_t service;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_NavSatStatus.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_NavSatStatus_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_NavSatStatus* wescore_lcm_msgs_NavSatStatus_copy(const wescore_lcm_msgs_NavSatStatus* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_NavSatStatus created by wescore_lcm_msgs_NavSatStatus_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_NavSatStatus_destroy(wescore_lcm_msgs_NavSatStatus* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_NavSatStatus_subscription_t wescore_lcm_msgs_NavSatStatus_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_NavSatStatus is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_NavSatStatus_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_NavSatStatus *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_NavSatStatus using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatStatus_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_NavSatStatus *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_NavSatStatus using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_NavSatStatus_subscription_t* wescore_lcm_msgs_NavSatStatus_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_NavSatStatus_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_NavSatStatus_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatStatus_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_NavSatStatus_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatStatus_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_NavSatStatus_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_NavSatStatus into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_NavSatStatus_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatStatus_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_NavSatStatus *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_NavSatStatus from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_NavSatStatus_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatStatus_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_NavSatStatus *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_NavSatStatus_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatStatus_decode_cleanup(wescore_lcm_msgs_NavSatStatus *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_NavSatStatus
|
||||
*/
|
||||
int wescore_lcm_msgs_NavSatStatus_encoded_size(const wescore_lcm_msgs_NavSatStatus *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_NavSatStatus_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_NavSatStatus_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_NavSatStatus_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_NavSatStatus *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatStatus_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_NavSatStatus *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatStatus_decode_array_cleanup(wescore_lcm_msgs_NavSatStatus *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatStatus_encoded_array_size(const wescore_lcm_msgs_NavSatStatus *p, int elements);
|
||||
int __wescore_lcm_msgs_NavSatStatus_clone_array(const wescore_lcm_msgs_NavSatStatus *p, wescore_lcm_msgs_NavSatStatus *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
149
scout_base/include/lcmtypes/wescore_lcm_msgs_Quaternion.h
Normal file
149
scout_base/include/lcmtypes/wescore_lcm_msgs_Quaternion.h
Normal file
@@ -0,0 +1,149 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_Quaternion_h
|
||||
#define _wescore_lcm_msgs_Quaternion_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_Quaternion wescore_lcm_msgs_Quaternion;
|
||||
struct _wescore_lcm_msgs_Quaternion
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
double w;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_Quaternion.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_Quaternion_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_Quaternion* wescore_lcm_msgs_Quaternion_copy(const wescore_lcm_msgs_Quaternion* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_Quaternion created by wescore_lcm_msgs_Quaternion_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_Quaternion_destroy(wescore_lcm_msgs_Quaternion* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_Quaternion_subscription_t wescore_lcm_msgs_Quaternion_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_Quaternion is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_Quaternion_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_Quaternion *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_Quaternion using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_Quaternion_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_Quaternion *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_Quaternion using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_Quaternion_subscription_t* wescore_lcm_msgs_Quaternion_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_Quaternion_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_Quaternion_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_Quaternion_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_Quaternion_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_Quaternion_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_Quaternion_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_Quaternion into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_Quaternion_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_Quaternion_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_Quaternion *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_Quaternion from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_Quaternion_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_Quaternion_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_Quaternion *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_Quaternion_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_Quaternion_decode_cleanup(wescore_lcm_msgs_Quaternion *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_Quaternion
|
||||
*/
|
||||
int wescore_lcm_msgs_Quaternion_encoded_size(const wescore_lcm_msgs_Quaternion *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_Quaternion_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_Quaternion_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_Quaternion_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_Quaternion *p, int elements);
|
||||
int __wescore_lcm_msgs_Quaternion_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_Quaternion *p, int elements);
|
||||
int __wescore_lcm_msgs_Quaternion_decode_array_cleanup(wescore_lcm_msgs_Quaternion *p, int elements);
|
||||
int __wescore_lcm_msgs_Quaternion_encoded_array_size(const wescore_lcm_msgs_Quaternion *p, int elements);
|
||||
int __wescore_lcm_msgs_Quaternion_clone_array(const wescore_lcm_msgs_Quaternion *p, wescore_lcm_msgs_Quaternion *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
147
scout_base/include/lcmtypes/wescore_lcm_msgs_RawAccel.h
Normal file
147
scout_base/include/lcmtypes/wescore_lcm_msgs_RawAccel.h
Normal file
@@ -0,0 +1,147 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_RawAccel_h
|
||||
#define _wescore_lcm_msgs_RawAccel_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_RawAccel wescore_lcm_msgs_RawAccel;
|
||||
struct _wescore_lcm_msgs_RawAccel
|
||||
{
|
||||
int64_t mtime;
|
||||
float accel[3];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_RawAccel.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_RawAccel_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_RawAccel* wescore_lcm_msgs_RawAccel_copy(const wescore_lcm_msgs_RawAccel* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_RawAccel created by wescore_lcm_msgs_RawAccel_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_RawAccel_destroy(wescore_lcm_msgs_RawAccel* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_RawAccel_subscription_t wescore_lcm_msgs_RawAccel_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_RawAccel is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_RawAccel_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_RawAccel *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_RawAccel using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawAccel_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_RawAccel *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_RawAccel using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_RawAccel_subscription_t* wescore_lcm_msgs_RawAccel_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_RawAccel_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_RawAccel_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_RawAccel_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_RawAccel_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_RawAccel_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_RawAccel_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_RawAccel into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_RawAccel_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawAccel_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawAccel *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_RawAccel from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_RawAccel_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawAccel_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawAccel *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_RawAccel_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_RawAccel_decode_cleanup(wescore_lcm_msgs_RawAccel *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_RawAccel
|
||||
*/
|
||||
int wescore_lcm_msgs_RawAccel_encoded_size(const wescore_lcm_msgs_RawAccel *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_RawAccel_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_RawAccel_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_RawAccel_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawAccel *p, int elements);
|
||||
int __wescore_lcm_msgs_RawAccel_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawAccel *p, int elements);
|
||||
int __wescore_lcm_msgs_RawAccel_decode_array_cleanup(wescore_lcm_msgs_RawAccel *p, int elements);
|
||||
int __wescore_lcm_msgs_RawAccel_encoded_array_size(const wescore_lcm_msgs_RawAccel *p, int elements);
|
||||
int __wescore_lcm_msgs_RawAccel_clone_array(const wescore_lcm_msgs_RawAccel *p, wescore_lcm_msgs_RawAccel *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
148
scout_base/include/lcmtypes/wescore_lcm_msgs_RawGyro.h
Normal file
148
scout_base/include/lcmtypes/wescore_lcm_msgs_RawGyro.h
Normal file
@@ -0,0 +1,148 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_RawGyro_h
|
||||
#define _wescore_lcm_msgs_RawGyro_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// IMU data
|
||||
typedef struct _wescore_lcm_msgs_RawGyro wescore_lcm_msgs_RawGyro;
|
||||
struct _wescore_lcm_msgs_RawGyro
|
||||
{
|
||||
int64_t mtime;
|
||||
float gyro[3];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_RawGyro.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_RawGyro_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_RawGyro* wescore_lcm_msgs_RawGyro_copy(const wescore_lcm_msgs_RawGyro* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_RawGyro created by wescore_lcm_msgs_RawGyro_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_RawGyro_destroy(wescore_lcm_msgs_RawGyro* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_RawGyro_subscription_t wescore_lcm_msgs_RawGyro_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_RawGyro is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_RawGyro_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_RawGyro *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_RawGyro using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawGyro_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_RawGyro *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_RawGyro using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_RawGyro_subscription_t* wescore_lcm_msgs_RawGyro_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_RawGyro_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_RawGyro_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_RawGyro_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_RawGyro_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_RawGyro_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_RawGyro_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_RawGyro into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_RawGyro_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawGyro_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawGyro *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_RawGyro from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_RawGyro_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawGyro_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawGyro *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_RawGyro_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_RawGyro_decode_cleanup(wescore_lcm_msgs_RawGyro *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_RawGyro
|
||||
*/
|
||||
int wescore_lcm_msgs_RawGyro_encoded_size(const wescore_lcm_msgs_RawGyro *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_RawGyro_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_RawGyro_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_RawGyro_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawGyro *p, int elements);
|
||||
int __wescore_lcm_msgs_RawGyro_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawGyro *p, int elements);
|
||||
int __wescore_lcm_msgs_RawGyro_decode_array_cleanup(wescore_lcm_msgs_RawGyro *p, int elements);
|
||||
int __wescore_lcm_msgs_RawGyro_encoded_array_size(const wescore_lcm_msgs_RawGyro *p, int elements);
|
||||
int __wescore_lcm_msgs_RawGyro_clone_array(const wescore_lcm_msgs_RawGyro *p, wescore_lcm_msgs_RawGyro *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
149
scout_base/include/lcmtypes/wescore_lcm_msgs_RawIMU10DOF.h
Normal file
149
scout_base/include/lcmtypes/wescore_lcm_msgs_RawIMU10DOF.h
Normal file
@@ -0,0 +1,149 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_RawIMU10DOF_h
|
||||
#define _wescore_lcm_msgs_RawIMU10DOF_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_RawIMU10DOF wescore_lcm_msgs_RawIMU10DOF;
|
||||
struct _wescore_lcm_msgs_RawIMU10DOF
|
||||
{
|
||||
int64_t mtime;
|
||||
float gyro[3];
|
||||
float accel[3];
|
||||
float baro;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_RawIMU10DOF.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_RawIMU10DOF_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_RawIMU10DOF* wescore_lcm_msgs_RawIMU10DOF_copy(const wescore_lcm_msgs_RawIMU10DOF* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_RawIMU10DOF created by wescore_lcm_msgs_RawIMU10DOF_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_RawIMU10DOF_destroy(wescore_lcm_msgs_RawIMU10DOF* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_RawIMU10DOF_subscription_t wescore_lcm_msgs_RawIMU10DOF_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_RawIMU10DOF is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_RawIMU10DOF_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_RawIMU10DOF *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_RawIMU10DOF using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU10DOF_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_RawIMU10DOF *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_RawIMU10DOF using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_RawIMU10DOF_subscription_t* wescore_lcm_msgs_RawIMU10DOF_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_RawIMU10DOF_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_RawIMU10DOF_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU10DOF_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_RawIMU10DOF_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU10DOF_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_RawIMU10DOF_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_RawIMU10DOF into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_RawIMU10DOF_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU10DOF_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawIMU10DOF *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_RawIMU10DOF from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_RawIMU10DOF_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU10DOF_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawIMU10DOF *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_RawIMU10DOF_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU10DOF_decode_cleanup(wescore_lcm_msgs_RawIMU10DOF *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_RawIMU10DOF
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU10DOF_encoded_size(const wescore_lcm_msgs_RawIMU10DOF *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_RawIMU10DOF_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_RawIMU10DOF_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_RawIMU10DOF_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawIMU10DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU10DOF_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawIMU10DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU10DOF_decode_array_cleanup(wescore_lcm_msgs_RawIMU10DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU10DOF_encoded_array_size(const wescore_lcm_msgs_RawIMU10DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU10DOF_clone_array(const wescore_lcm_msgs_RawIMU10DOF *p, wescore_lcm_msgs_RawIMU10DOF *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
148
scout_base/include/lcmtypes/wescore_lcm_msgs_RawIMU6DOF.h
Normal file
148
scout_base/include/lcmtypes/wescore_lcm_msgs_RawIMU6DOF.h
Normal file
@@ -0,0 +1,148 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_RawIMU6DOF_h
|
||||
#define _wescore_lcm_msgs_RawIMU6DOF_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_RawIMU6DOF wescore_lcm_msgs_RawIMU6DOF;
|
||||
struct _wescore_lcm_msgs_RawIMU6DOF
|
||||
{
|
||||
int64_t mtime;
|
||||
float gyro[3];
|
||||
float accel[3];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_RawIMU6DOF.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_RawIMU6DOF_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_RawIMU6DOF* wescore_lcm_msgs_RawIMU6DOF_copy(const wescore_lcm_msgs_RawIMU6DOF* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_RawIMU6DOF created by wescore_lcm_msgs_RawIMU6DOF_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_RawIMU6DOF_destroy(wescore_lcm_msgs_RawIMU6DOF* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_RawIMU6DOF_subscription_t wescore_lcm_msgs_RawIMU6DOF_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_RawIMU6DOF is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_RawIMU6DOF_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_RawIMU6DOF *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_RawIMU6DOF using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU6DOF_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_RawIMU6DOF *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_RawIMU6DOF using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_RawIMU6DOF_subscription_t* wescore_lcm_msgs_RawIMU6DOF_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_RawIMU6DOF_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_RawIMU6DOF_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU6DOF_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_RawIMU6DOF_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU6DOF_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_RawIMU6DOF_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_RawIMU6DOF into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_RawIMU6DOF_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU6DOF_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawIMU6DOF *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_RawIMU6DOF from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_RawIMU6DOF_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU6DOF_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawIMU6DOF *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_RawIMU6DOF_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU6DOF_decode_cleanup(wescore_lcm_msgs_RawIMU6DOF *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_RawIMU6DOF
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU6DOF_encoded_size(const wescore_lcm_msgs_RawIMU6DOF *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_RawIMU6DOF_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_RawIMU6DOF_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_RawIMU6DOF_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawIMU6DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU6DOF_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawIMU6DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU6DOF_decode_array_cleanup(wescore_lcm_msgs_RawIMU6DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU6DOF_encoded_array_size(const wescore_lcm_msgs_RawIMU6DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU6DOF_clone_array(const wescore_lcm_msgs_RawIMU6DOF *p, wescore_lcm_msgs_RawIMU6DOF *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
149
scout_base/include/lcmtypes/wescore_lcm_msgs_RawIMU9DOF.h
Normal file
149
scout_base/include/lcmtypes/wescore_lcm_msgs_RawIMU9DOF.h
Normal file
@@ -0,0 +1,149 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_RawIMU9DOF_h
|
||||
#define _wescore_lcm_msgs_RawIMU9DOF_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_RawIMU9DOF wescore_lcm_msgs_RawIMU9DOF;
|
||||
struct _wescore_lcm_msgs_RawIMU9DOF
|
||||
{
|
||||
int64_t mtime;
|
||||
float gyro[3];
|
||||
float accel[3];
|
||||
float magn[3];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_RawIMU9DOF.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_RawIMU9DOF_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_RawIMU9DOF* wescore_lcm_msgs_RawIMU9DOF_copy(const wescore_lcm_msgs_RawIMU9DOF* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_RawIMU9DOF created by wescore_lcm_msgs_RawIMU9DOF_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_RawIMU9DOF_destroy(wescore_lcm_msgs_RawIMU9DOF* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_RawIMU9DOF_subscription_t wescore_lcm_msgs_RawIMU9DOF_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_RawIMU9DOF is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_RawIMU9DOF_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_RawIMU9DOF *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_RawIMU9DOF using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU9DOF_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_RawIMU9DOF *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_RawIMU9DOF using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_RawIMU9DOF_subscription_t* wescore_lcm_msgs_RawIMU9DOF_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_RawIMU9DOF_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_RawIMU9DOF_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU9DOF_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_RawIMU9DOF_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU9DOF_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_RawIMU9DOF_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_RawIMU9DOF into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_RawIMU9DOF_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU9DOF_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawIMU9DOF *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_RawIMU9DOF from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_RawIMU9DOF_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU9DOF_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawIMU9DOF *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_RawIMU9DOF_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU9DOF_decode_cleanup(wescore_lcm_msgs_RawIMU9DOF *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_RawIMU9DOF
|
||||
*/
|
||||
int wescore_lcm_msgs_RawIMU9DOF_encoded_size(const wescore_lcm_msgs_RawIMU9DOF *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_RawIMU9DOF_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_RawIMU9DOF_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_RawIMU9DOF_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawIMU9DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU9DOF_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawIMU9DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU9DOF_decode_array_cleanup(wescore_lcm_msgs_RawIMU9DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU9DOF_encoded_array_size(const wescore_lcm_msgs_RawIMU9DOF *p, int elements);
|
||||
int __wescore_lcm_msgs_RawIMU9DOF_clone_array(const wescore_lcm_msgs_RawIMU9DOF *p, wescore_lcm_msgs_RawIMU9DOF *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
147
scout_base/include/lcmtypes/wescore_lcm_msgs_RawMag.h
Normal file
147
scout_base/include/lcmtypes/wescore_lcm_msgs_RawMag.h
Normal file
@@ -0,0 +1,147 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_RawMag_h
|
||||
#define _wescore_lcm_msgs_RawMag_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_RawMag wescore_lcm_msgs_RawMag;
|
||||
struct _wescore_lcm_msgs_RawMag
|
||||
{
|
||||
int64_t mtime;
|
||||
float magn[3];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_RawMag.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_RawMag_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_RawMag* wescore_lcm_msgs_RawMag_copy(const wescore_lcm_msgs_RawMag* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_RawMag created by wescore_lcm_msgs_RawMag_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_RawMag_destroy(wescore_lcm_msgs_RawMag* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_RawMag_subscription_t wescore_lcm_msgs_RawMag_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_RawMag is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_RawMag_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_RawMag *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_RawMag using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawMag_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_RawMag *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_RawMag using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_RawMag_subscription_t* wescore_lcm_msgs_RawMag_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_RawMag_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_RawMag_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_RawMag_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_RawMag_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_RawMag_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_RawMag_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_RawMag into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_RawMag_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawMag_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawMag *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_RawMag from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_RawMag_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_RawMag_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawMag *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_RawMag_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_RawMag_decode_cleanup(wescore_lcm_msgs_RawMag *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_RawMag
|
||||
*/
|
||||
int wescore_lcm_msgs_RawMag_encoded_size(const wescore_lcm_msgs_RawMag *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_RawMag_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_RawMag_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_RawMag_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_RawMag *p, int elements);
|
||||
int __wescore_lcm_msgs_RawMag_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_RawMag *p, int elements);
|
||||
int __wescore_lcm_msgs_RawMag_decode_array_cleanup(wescore_lcm_msgs_RawMag *p, int elements);
|
||||
int __wescore_lcm_msgs_RawMag_encoded_array_size(const wescore_lcm_msgs_RawMag *p, int elements);
|
||||
int __wescore_lcm_msgs_RawMag_clone_array(const wescore_lcm_msgs_RawMag *p, wescore_lcm_msgs_RawMag *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
147
scout_base/include/lcmtypes/wescore_lcm_msgs_Vector2.h
Normal file
147
scout_base/include/lcmtypes/wescore_lcm_msgs_Vector2.h
Normal file
@@ -0,0 +1,147 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_Vector2_h
|
||||
#define _wescore_lcm_msgs_Vector2_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_Vector2 wescore_lcm_msgs_Vector2;
|
||||
struct _wescore_lcm_msgs_Vector2
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_Vector2.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_Vector2_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_Vector2* wescore_lcm_msgs_Vector2_copy(const wescore_lcm_msgs_Vector2* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_Vector2 created by wescore_lcm_msgs_Vector2_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_Vector2_destroy(wescore_lcm_msgs_Vector2* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_Vector2_subscription_t wescore_lcm_msgs_Vector2_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_Vector2 is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_Vector2_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_Vector2 *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_Vector2 using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector2_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_Vector2 *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_Vector2 using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_Vector2_subscription_t* wescore_lcm_msgs_Vector2_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_Vector2_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_Vector2_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector2_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_Vector2_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector2_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_Vector2_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_Vector2 into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_Vector2_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector2_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_Vector2 *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_Vector2 from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_Vector2_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector2_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_Vector2 *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_Vector2_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector2_decode_cleanup(wescore_lcm_msgs_Vector2 *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_Vector2
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector2_encoded_size(const wescore_lcm_msgs_Vector2 *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_Vector2_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_Vector2_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_Vector2_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_Vector2 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector2_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_Vector2 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector2_decode_array_cleanup(wescore_lcm_msgs_Vector2 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector2_encoded_array_size(const wescore_lcm_msgs_Vector2 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector2_clone_array(const wescore_lcm_msgs_Vector2 *p, wescore_lcm_msgs_Vector2 *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
148
scout_base/include/lcmtypes/wescore_lcm_msgs_Vector3.h
Normal file
148
scout_base/include/lcmtypes/wescore_lcm_msgs_Vector3.h
Normal file
@@ -0,0 +1,148 @@
|
||||
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
|
||||
// BY HAND!!
|
||||
//
|
||||
// Generated by lcm-gen
|
||||
|
||||
#ifndef _wescore_lcm_msgs_Vector3_h
|
||||
#define _wescore_lcm_msgs_Vector3_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <lcm/lcm_coretypes.h>
|
||||
#include <lcm/lcm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _wescore_lcm_msgs_Vector3 wescore_lcm_msgs_Vector3;
|
||||
struct _wescore_lcm_msgs_Vector3
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of a wescore_lcm_msgs_Vector3.
|
||||
* When no longer needed, destroy it with wescore_lcm_msgs_Vector3_destroy()
|
||||
*/
|
||||
wescore_lcm_msgs_Vector3* wescore_lcm_msgs_Vector3_copy(const wescore_lcm_msgs_Vector3* to_copy);
|
||||
|
||||
/**
|
||||
* Destroy an instance of wescore_lcm_msgs_Vector3 created by wescore_lcm_msgs_Vector3_copy()
|
||||
*/
|
||||
void wescore_lcm_msgs_Vector3_destroy(wescore_lcm_msgs_Vector3* to_destroy);
|
||||
|
||||
/**
|
||||
* Identifies a single subscription. This is an opaque data type.
|
||||
*/
|
||||
typedef struct _wescore_lcm_msgs_Vector3_subscription_t wescore_lcm_msgs_Vector3_subscription_t;
|
||||
|
||||
/**
|
||||
* Prototype for a callback function invoked when a message of type
|
||||
* wescore_lcm_msgs_Vector3 is received.
|
||||
*/
|
||||
typedef void(*wescore_lcm_msgs_Vector3_handler_t)(
|
||||
const lcm_recv_buf_t *rbuf, const char *channel,
|
||||
const wescore_lcm_msgs_Vector3 *msg, void *userdata);
|
||||
|
||||
/**
|
||||
* Publish a message of type wescore_lcm_msgs_Vector3 using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to publish with.
|
||||
* @param channel The channel to publish on.
|
||||
* @param msg The message to publish.
|
||||
* @return 0 on success, <0 on error. Success means LCM has transferred
|
||||
* responsibility of the message data to the OS.
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector3_publish(lcm_t *lcm, const char *channel, const wescore_lcm_msgs_Vector3 *msg);
|
||||
|
||||
/**
|
||||
* Subscribe to messages of type wescore_lcm_msgs_Vector3 using LCM.
|
||||
*
|
||||
* @param lcm The LCM instance to subscribe with.
|
||||
* @param channel The channel to subscribe to.
|
||||
* @param handler The callback function invoked by LCM when a message is
|
||||
* received. This function is invoked by LCM during calls to lcm_handle()
|
||||
* and lcm_handle_timeout().
|
||||
* @param userdata An opaque pointer passed to @p handler when it is invoked.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
wescore_lcm_msgs_Vector3_subscription_t* wescore_lcm_msgs_Vector3_subscribe(
|
||||
lcm_t *lcm, const char *channel, wescore_lcm_msgs_Vector3_handler_t handler, void *userdata);
|
||||
|
||||
/**
|
||||
* Removes and destroys a subscription created by wescore_lcm_msgs_Vector3_subscribe()
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector3_unsubscribe(lcm_t *lcm, wescore_lcm_msgs_Vector3_subscription_t* hid);
|
||||
|
||||
/**
|
||||
* Sets the queue capacity for a subscription.
|
||||
* Some LCM providers (e.g., the default multicast provider) are implemented
|
||||
* using a background receive thread that constantly revceives messages from
|
||||
* the network. As these messages are received, they are buffered on
|
||||
* per-subscription queues until dispatched by lcm_handle(). This function
|
||||
* how many messages are queued before dropping messages.
|
||||
*
|
||||
* @param subs the subscription to modify.
|
||||
* @param num_messages The maximum number of messages to queue
|
||||
* on the subscription.
|
||||
* @return 0 on success, <0 if an error occured
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector3_subscription_set_queue_capacity(
|
||||
wescore_lcm_msgs_Vector3_subscription_t* subs, int num_messages);
|
||||
|
||||
/**
|
||||
* Encode a message of type wescore_lcm_msgs_Vector3 into binary form.
|
||||
*
|
||||
* @param buf The output buffer.
|
||||
* @param offset Encoding starts at this byte offset into @p buf.
|
||||
* @param maxlen Maximum number of bytes to write. This should generally
|
||||
* be equal to wescore_lcm_msgs_Vector3_encoded_size().
|
||||
* @param msg The message to encode.
|
||||
* @return The number of bytes encoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector3_encode(void *buf, int offset, int maxlen, const wescore_lcm_msgs_Vector3 *p);
|
||||
|
||||
/**
|
||||
* Decode a message of type wescore_lcm_msgs_Vector3 from binary form.
|
||||
* When decoding messages containing strings or variable-length arrays, this
|
||||
* function may allocate memory. When finished with the decoded message,
|
||||
* release allocated resources with wescore_lcm_msgs_Vector3_decode_cleanup().
|
||||
*
|
||||
* @param buf The buffer containing the encoded message
|
||||
* @param offset The byte offset into @p buf where the encoded message starts.
|
||||
* @param maxlen The maximum number of bytes to read while decoding.
|
||||
* @param msg Output parameter where the decoded message is stored
|
||||
* @return The number of bytes decoded, or <0 if an error occured.
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector3_decode(const void *buf, int offset, int maxlen, wescore_lcm_msgs_Vector3 *msg);
|
||||
|
||||
/**
|
||||
* Release resources allocated by wescore_lcm_msgs_Vector3_decode()
|
||||
* @return 0
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector3_decode_cleanup(wescore_lcm_msgs_Vector3 *p);
|
||||
|
||||
/**
|
||||
* Check how many bytes are required to encode a message of type wescore_lcm_msgs_Vector3
|
||||
*/
|
||||
int wescore_lcm_msgs_Vector3_encoded_size(const wescore_lcm_msgs_Vector3 *p);
|
||||
|
||||
// LCM support functions. Users should not call these
|
||||
int64_t __wescore_lcm_msgs_Vector3_get_hash(void);
|
||||
uint64_t __wescore_lcm_msgs_Vector3_hash_recursive(const __lcm_hash_ptr *p);
|
||||
int __wescore_lcm_msgs_Vector3_encode_array(
|
||||
void *buf, int offset, int maxlen, const wescore_lcm_msgs_Vector3 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector3_decode_array(
|
||||
const void *buf, int offset, int maxlen, wescore_lcm_msgs_Vector3 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector3_decode_array_cleanup(wescore_lcm_msgs_Vector3 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector3_encoded_array_size(const wescore_lcm_msgs_Vector3 *p, int elements);
|
||||
int __wescore_lcm_msgs_Vector3_clone_array(const wescore_lcm_msgs_Vector3 *p, wescore_lcm_msgs_Vector3 *q, int elements);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -14,26 +14,28 @@
|
||||
|
||||
#include <ros/ros.h>
|
||||
#include <nav_msgs/Odometry.h>
|
||||
#include <tf/transform_broadcaster.h>
|
||||
// #include <tf/transform_broadcaster.h>
|
||||
#include <tf2_ros/transform_broadcaster.h>
|
||||
|
||||
#include "scout_msgs/ScoutLightCmd.h"
|
||||
#include "scout_base/scout_base.hpp"
|
||||
#include "scout_sdk/scout_base.hpp"
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
class ScoutROSMessenger
|
||||
{
|
||||
public:
|
||||
explicit ScoutROSMessenger(ros::NodeHandle nh);
|
||||
ScoutROSMessenger(ScoutBase *scout, ros::NodeHandle nh);
|
||||
explicit ScoutROSMessenger(ros::NodeHandle *nh);
|
||||
ScoutROSMessenger(ScoutBase *scout, ros::NodeHandle *nh);
|
||||
|
||||
std::string odom_frame_;
|
||||
std::string base_frame_;
|
||||
|
||||
bool simulated_robot_;
|
||||
int sim_control_rate_;
|
||||
bool simulated_robot_ = false;
|
||||
int sim_control_rate_ = 50;
|
||||
|
||||
void SetupSubscription();
|
||||
|
||||
void PublishStateToROS();
|
||||
void PublishSimStateToROS(double linear, double angular);
|
||||
|
||||
@@ -41,7 +43,7 @@ public:
|
||||
|
||||
private:
|
||||
ScoutBase *scout_;
|
||||
ros::NodeHandle nh_;
|
||||
ros::NodeHandle *nh_;
|
||||
|
||||
std::mutex twist_mutex_;
|
||||
geometry_msgs::Twist current_twist_;
|
||||
@@ -50,9 +52,8 @@ private:
|
||||
ros::Publisher status_publisher_;
|
||||
ros::Subscriber motion_cmd_subscriber_;
|
||||
ros::Subscriber light_cmd_subscriber_;
|
||||
tf::TransformBroadcaster tf_broadcaster_;
|
||||
tf2_ros::TransformBroadcaster tf_broadcaster_;
|
||||
|
||||
private:
|
||||
// speed variables
|
||||
double linear_speed_ = 0.0;
|
||||
double angular_speed_ = 0.0;
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
<launch>
|
||||
<node name="scout_odom" pkg="scout_base" type="scout_base_node" output="screen">
|
||||
<param name="port_name" type="string" value="can0" />
|
||||
<!--
|
||||
The robot can be controlled either through CAN bus or UART port. Make sure the hardware
|
||||
interface is set up correctly before attempting to connect to the robot.
|
||||
|
||||
You only need to specify the port name, such as "can0", "/dev/ttyUSB0". The port should
|
||||
operate with the following configuration:
|
||||
|
||||
* CAN bus: 500k
|
||||
* UART: 115200, Parity None, 8-bit Data, 1 Stop Bit
|
||||
-->
|
||||
<arg name="port_name" default="can0" />
|
||||
<arg name="simulated_robot" default="false" />
|
||||
|
||||
<node name="scout_base_node" pkg="scout_base" type="scout_base_node" output="screen">
|
||||
<param name="port_name" type="string" value="$(arg port_name)" />
|
||||
<param name="simulated_robot" type="bool" value="$(arg simulated_robot)" />
|
||||
|
||||
<param name="odom_frame" type="string" value="odom" />
|
||||
<param name="base_frame" type="string" value="base_footprint" />
|
||||
|
||||
<param name="simulated_robot" type="bool" value="false" />
|
||||
<param name="base_frame" type="string" value="base_link" />
|
||||
</node>
|
||||
</launch>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<launch>
|
||||
|
||||
<node name="scout_odom" pkg="scout_vrep_sim" type="scout_base_sim" output="screen">
|
||||
<param name="odom_frame" type="string" value="odom" />
|
||||
<param name="base_frame" type="string" value="base_link" />
|
||||
<param name="simulated_robot" type="bool" value="true" />
|
||||
<param name="sim_control_rate" value="50" />
|
||||
</node>
|
||||
|
||||
<!-- Differential controller parameters and basic localization -->
|
||||
<!--
|
||||
<include file="$(find scout_control)/launch/control.launch" />
|
||||
-->
|
||||
</launch>
|
||||
6
scout_base/launch/view_scout_model.launch
Normal file
6
scout_base/launch/view_scout_model.launch
Normal file
@@ -0,0 +1,6 @@
|
||||
<launch>
|
||||
<param name="robot_description" textfile="$(find scout_base)/urdf/agilex_scout.urdf" />
|
||||
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
|
||||
|
||||
<node name="rviz" pkg="rviz" type="rviz" required="true" args="-d $(find scout_viz)/rviz/scout_model.rviz" />
|
||||
</launch>
|
||||
@@ -14,24 +14,18 @@
|
||||
<url type="repository">TODO</url>
|
||||
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
<build_depend>controller_manager</build_depend>
|
||||
<build_depend>hardware_interface</build_depend>
|
||||
<build_depend>scout_msgs</build_depend>
|
||||
<build_depend>roscpp</build_depend>
|
||||
<build_depend>roslaunch</build_depend>
|
||||
<build_depend>roslint</build_depend>
|
||||
<build_depend>sensor_msgs</build_depend>
|
||||
|
||||
<build_depend>scout_sdk</build_depend>
|
||||
<run_depend>controller_manager</run_depend>
|
||||
<run_depend>diff_drive_controller</run_depend>
|
||||
<run_depend>geometry_msgs</run_depend>
|
||||
<run_depend>hardware_interface</run_depend>
|
||||
<run_depend>scout_control</run_depend>
|
||||
<run_depend>scout_msgs</run_depend>
|
||||
<run_depend>scout_description</run_depend>
|
||||
<run_depend>roscpp</run_depend>
|
||||
<run_depend>sensor_msgs</run_depend>
|
||||
<run_depend>topic_tools</run_depend>
|
||||
|
||||
<run_depend>scout_sdk</run_depend>
|
||||
<export></export>
|
||||
</package>
|
||||
|
||||
72
scout_base/src/imu_broadcast_node.cpp
Normal file
72
scout_base/src/imu_broadcast_node.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* imu_broadcast_node.cpp
|
||||
*
|
||||
* Created on: Oct 02, 2019 19:09
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <lcm/lcm-cpp.hpp>
|
||||
#include "lcmtypes/wescore.hpp"
|
||||
|
||||
#include <ros/ros.h>
|
||||
#include <sensor_msgs/Imu.h>
|
||||
|
||||
ros::Publisher imu_pub;
|
||||
|
||||
struct MessageBroadcaster
|
||||
{
|
||||
void IMULCMCallback(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const wescore_lcm_msgs::IMU *msg)
|
||||
{
|
||||
static uint64_t count = 0;
|
||||
// std::cout << "imu msg received" << std::endl;
|
||||
sensor_msgs::Imu imu_msg;
|
||||
imu_msg.header.frame_id = "imu_link";
|
||||
imu_msg.header.stamp = ros::Time::now();
|
||||
imu_msg.header.seq = count++;
|
||||
|
||||
imu_msg.angular_velocity.x = msg->angular_velocity.x;
|
||||
imu_msg.angular_velocity.y = msg->angular_velocity.y;
|
||||
imu_msg.angular_velocity.z = msg->angular_velocity.z;
|
||||
|
||||
imu_msg.linear_acceleration.x = msg->linear_acceleration.x;
|
||||
imu_msg.linear_acceleration.y = msg->linear_acceleration.y;
|
||||
imu_msg.linear_acceleration.z = msg->linear_acceleration.z;
|
||||
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
imu_msg.orientation_covariance[i] = msg->orientation_covariance[i];
|
||||
imu_msg.angular_velocity_covariance[i] = msg->angular_velocity_covariance[i];
|
||||
imu_msg.linear_acceleration_covariance[i] = msg->linear_acceleration_covariance[i];
|
||||
}
|
||||
|
||||
imu_pub.publish(imu_msg);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// setup LCM
|
||||
lcm::LCM lcm;
|
||||
|
||||
if (!lcm.good())
|
||||
return 1;
|
||||
MessageBroadcaster mb;
|
||||
lcm.subscribe("sensor_hub_raw_imu", &MessageBroadcaster::IMULCMCallback, &mb);
|
||||
|
||||
// setup ROS node
|
||||
ros::init(argc, argv, "imu_broadcast_node");
|
||||
ros::NodeHandle nh;
|
||||
imu_pub = nh.advertise<sensor_msgs::Imu>("imu", 1000);
|
||||
|
||||
ROS_INFO("Started broadcasting");
|
||||
while (ros::ok())
|
||||
{
|
||||
lcm.handleTimeout(5);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
#include <string>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <ros/ros.h>
|
||||
#include <sensor_msgs/JointState.h>
|
||||
#include <tf/transform_broadcaster.h>
|
||||
#include <nav_msgs/Odometry.h>
|
||||
|
||||
#include "scout_base/scout_base.hpp"
|
||||
#include "scout_sdk/scout_base.hpp"
|
||||
#include "scout_base/scout_messenger.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
@@ -15,20 +14,30 @@ int main(int argc, char **argv)
|
||||
{
|
||||
// setup ROS node
|
||||
ros::init(argc, argv, "scout_odom");
|
||||
ros::NodeHandle node("scout_robot"), private_node("~");
|
||||
ros::NodeHandle node(""), private_node("~");
|
||||
|
||||
// instantiate a robot
|
||||
// instantiate a robot object
|
||||
ScoutBase robot;
|
||||
ScoutROSMessenger messenger(&robot, node);
|
||||
ScoutROSMessenger messenger(&robot, &node);
|
||||
|
||||
std::string scout_can_port;
|
||||
private_node.param<std::string>("port_name", scout_can_port, std::string("can0"));
|
||||
// fetch parameters before connecting to robot
|
||||
std::string port_name;
|
||||
private_node.param<std::string>("port_name", port_name, std::string("can0"));
|
||||
private_node.param<std::string>("odom_frame", messenger.odom_frame_, std::string("odom"));
|
||||
private_node.param<std::string>("base_frame", messenger.base_frame_, std::string("base_footprint"));
|
||||
private_node.param<std::string>("base_frame", messenger.base_frame_, std::string("base_link"));
|
||||
private_node.param<bool>("simulated_robot", messenger.simulated_robot_, false);
|
||||
|
||||
// connect to scout and setup ROS subscription
|
||||
robot.Connect(scout_can_port);
|
||||
// connect to robot and setup ROS subscription
|
||||
if (port_name.find("can") != std::string::npos)
|
||||
{
|
||||
robot.Connect(port_name);
|
||||
ROS_INFO("Using CAN bus to talk with the robot");
|
||||
}
|
||||
else
|
||||
{
|
||||
robot.Connect(port_name, 115200);
|
||||
ROS_INFO("Using UART to talk with the robot");
|
||||
}
|
||||
messenger.SetupSubscription();
|
||||
|
||||
// publish robot state at 20Hz while listening to twist commands
|
||||
|
||||
@@ -9,27 +9,29 @@
|
||||
|
||||
#include "scout_base/scout_messenger.hpp"
|
||||
|
||||
#include <tf/transform_broadcaster.h>
|
||||
|
||||
#include "scout_msgs/ScoutStatus.h"
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
ScoutROSMessenger::ScoutROSMessenger(ros::NodeHandle nh) : scout_(nullptr), nh_(nh)
|
||||
ScoutROSMessenger::ScoutROSMessenger(ros::NodeHandle *nh) : scout_(nullptr), nh_(nh)
|
||||
{
|
||||
}
|
||||
|
||||
ScoutROSMessenger::ScoutROSMessenger(ScoutBase *scout, ros::NodeHandle nh) : scout_(scout), nh_(nh)
|
||||
ScoutROSMessenger::ScoutROSMessenger(ScoutBase *scout, ros::NodeHandle *nh) : scout_(scout), nh_(nh)
|
||||
{
|
||||
}
|
||||
|
||||
void ScoutROSMessenger::SetupSubscription()
|
||||
{
|
||||
// odometry publisher
|
||||
odom_publisher_ = nh_.advertise<nav_msgs::Odometry>(odom_frame_, 50);
|
||||
status_publisher_ = nh_.advertise<scout_msgs::ScoutStatus>("/scout_status", 10);
|
||||
odom_publisher_ = nh_->advertise<nav_msgs::Odometry>(odom_frame_, 50);
|
||||
status_publisher_ = nh_->advertise<scout_msgs::ScoutStatus>("/scout_status", 10);
|
||||
|
||||
// cmd subscriber
|
||||
motion_cmd_subscriber_ = nh_.subscribe<geometry_msgs::Twist>("/cmd_vel", 5, &ScoutROSMessenger::TwistCmdCallback, this); //不启用平滑包则订阅“cmd_vel”
|
||||
light_cmd_subscriber_ = nh_.subscribe<scout_msgs::ScoutLightCmd>("/scout_light_control", 5, &ScoutROSMessenger::LightCmdCallback, this);
|
||||
motion_cmd_subscriber_ = nh_->subscribe<geometry_msgs::Twist>("/cmd_vel", 5, &ScoutROSMessenger::TwistCmdCallback, this); //不启用平滑包则订阅“cmd_vel”
|
||||
light_cmd_subscriber_ = nh_->subscribe<scout_msgs::ScoutLightCmd>("/scout_light_control", 5, &ScoutROSMessenger::LightCmdCallback, this);
|
||||
}
|
||||
|
||||
void ScoutROSMessenger::TwistCmdCallback(const geometry_msgs::Twist::ConstPtr &msg)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
# Changelog for scout_sdk
|
||||
|
||||
## 0.4 (2019-09-15)
|
||||
------------------
|
||||
* Unified implementation of UART/CAN for firmware and SDK
|
||||
* Improvements of code organization
|
||||
* Contributors: Ruixiang Du
|
||||
|
||||
## 0.3 (2019-08-02)
|
||||
------------------
|
||||
* Added full UART support
|
||||
* Contributors: Ruixiang Du
|
||||
|
||||
## 0.2 (2019-06-14)
|
||||
------------------
|
||||
* Deprecated initial serial interface support (new one under development)
|
||||
* Added full CAN support
|
||||
* Improved multi-threading implementation
|
||||
* Contributors: Ruixiang Du
|
||||
|
||||
## 0.1 (2019-05-07)
|
||||
------------------
|
||||
|
||||
* Added basic serial communication support
|
||||
* Provided C++ interface, ROS/LCM demo
|
||||
* Contributors: Ruixiang Du
|
||||
@@ -1,50 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
project(scout_sdk)
|
||||
|
||||
# generate symbols for IDE indexer
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/devel)
|
||||
|
||||
## Set compiler to use c++ 11 features
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
## Put all binary files into /bin and libraries into /lib
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
set(ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
## Use GNUInstallDirs to install libraries into correct
|
||||
# locations on all platforms.
|
||||
include(GNUInstallDirs)
|
||||
|
||||
## Chosse build type
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
# set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
set(default_build_type "Release")
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
|
||||
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
|
||||
STRING "Choose the type of build." FORCE)
|
||||
# Set the possible values of build type for cmake-gui
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
|
||||
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
||||
endif()
|
||||
|
||||
## Optionally built modules: ON/OFF
|
||||
set(BUILD_TESTS OFF)
|
||||
set(BUILD_MONITOR ON)
|
||||
|
||||
# Disable monitor if ncurses library is not found
|
||||
set(CURSES_NEED_NCURSES TRUE)
|
||||
find_package(Curses QUIET)
|
||||
|
||||
if(BUILD_MONITOR AND NOT CURSES_FOUND)
|
||||
set(BUILD_MONITOR OFF)
|
||||
message(STATUS "Monitor app will not be built due to missing ncurses library, try: sudo apt install libncurses5-dev")
|
||||
endif()
|
||||
|
||||
## Add source directories
|
||||
add_subdirectory(src)
|
||||
@@ -1,99 +0,0 @@
|
||||
# SDK for AgileX Scout Mobile Base
|
||||
|
||||
Copyright (c) 2019 [WestonRobot](https://www.westonrobot.com/)
|
||||
|
||||
## Introduction
|
||||
|
||||
This software packages provides a C++ interface to communicate with the Scout mobile base, for sending commands to the robot and acquiring the latest robot state. The SDK works on both x86 and ARM platforms.
|
||||
|
||||
Generally, you only need to instantiate an object of "class ScoutBase", then use the object to programmatically control the robot. Internally, class ScoutBase manages two background threads, one to process CAN/UART messages of the robot state and accordingly update state variables in the ScoutState data structure, and the other to maintain a 50Hz loop and send the latest command to the robot base. User can iteratively perform tasks in the main thread and check the robot state or set control commands.
|
||||
|
||||
Refer to "src/apps/scout_demo" for an example.
|
||||
|
||||
## Package Structure
|
||||
|
||||
* apps: demo to illustrate how to use the SDK, scout_monitor is a TUI application to monitor states of Scout
|
||||
* comm/async_io: manages raw data communication with robot
|
||||
* comm/scout_protocol: encoding and decoding of Scout UART/CAN protocols
|
||||
* scout_base: interface to send command to robot and receive robot state
|
||||
* third_party
|
||||
- asio: asynchronous IO management (serial and CAN)
|
||||
- googletest: for unit tests only (not required otherwise)
|
||||
|
||||
## Setup CAN-To-USB adapter
|
||||
|
||||
The instructions work for stm32f0-based adapter with [candleLight](https://github.com/HubertD/candleLight_fw) firmware on a host computer running Linux. (Refer to limitations listed at the bottom for more details.)
|
||||
|
||||
1. Enable gs_usb kernel module
|
||||
```
|
||||
$ sudo modprobe gs_usb
|
||||
```
|
||||
2. Bringup can device
|
||||
```
|
||||
$ sudo ip link set can0 up type can bitrate 500000
|
||||
```
|
||||
3. If no error occured during the previous steps, you should be able to see the can device now by using command
|
||||
```
|
||||
$ ifconfig -a
|
||||
```
|
||||
4. Install and use can-utils to test the hardware
|
||||
```
|
||||
$ sudo apt install can-utils
|
||||
```
|
||||
5. Testing command
|
||||
```
|
||||
# receiving data from can0
|
||||
$ candump can0
|
||||
# send data to can0
|
||||
$ cansend can0 001#1122334455667788
|
||||
```
|
||||
|
||||
Two scripts inside the "./scripts" folder are provided for easy setup. You can run "./setup_can2usb.bash" for the first-time setup and run "./bringup_can2usb.bash" to bring up the device each time you unplug and re-plug the adapter.
|
||||
|
||||
## Build SDK
|
||||
|
||||
Install compile tools
|
||||
|
||||
```
|
||||
$ sudo apt install build-essential cmake
|
||||
```
|
||||
|
||||
If you want to build the TUI monitor tool, install libncurses
|
||||
|
||||
```
|
||||
$ sudo apt install libncurses5-dev
|
||||
```
|
||||
|
||||
Configure and build
|
||||
|
||||
```
|
||||
$ cd scout_sdk
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make
|
||||
```
|
||||
|
||||
## Known Limitations
|
||||
|
||||
1. The CAN interface requires the hardware to appear as a CAN device in the system. You can use the command "ifconfig" to check the interface status. For example, you may see something like
|
||||
|
||||
```
|
||||
can1: flags=193<UP,RUNNING,NOARP> mtu 16
|
||||
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
|
||||
RX packets 4751634 bytes 38013072 (36.2 MiB)
|
||||
RX errors 0 dropped 0 overruns 0 frame 0
|
||||
TX packets 126269 bytes 1010152 (986.4 KiB)
|
||||
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
||||
device interrupt 43
|
||||
```
|
||||
|
||||
If you use your own CAN-to-USB adapter, make sure it supports slcan or can be brought up as a native CAN device (for example, CANable https://www.canable.io/). Some adapters may use a custom-defined protocol and appear as a serial device in Linux. In such a case, you will have to translate the byte stream between CAN and UART by yourself. It would be difficult for us to provide support for them since not all manufacturers define this protocol in the same way.
|
||||
|
||||
<!--
|
||||
2. Release v0.1 of this SDK provided a serial interface to talk with the robot. Front/rear light on the robot cannot be controlled and only a small subset of all robot states can be acquired through that interface. Full support of the serial interface is still under development and requires additional work on both the SDK and firmware sides.
|
||||
-->
|
||||
|
||||
## Reference
|
||||
|
||||
* [CAN command reference in Linux](https://wiki.rdu.im/_pages/Notes/Embedded-System/Linux/can-bus-in-linux.html)
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,23 +0,0 @@
|
||||
# Setup CAN on Beaglebone Black
|
||||
|
||||
CAN/RS485 Cape: https://item.taobao.com/item.htm?spm=a1z09.2.0.0.68b02e8d02l2uT&id=42637485181&_u=a4mg52ma183
|
||||
|
||||
* Install latest Debian image from offical site
|
||||
* Build and install overlays
|
||||
```
|
||||
$ sudo apt install device-tree-compiler
|
||||
$ git clone https://github.com/beagleboard/bb.org-overlays
|
||||
$ cd ./bb.org-overlays/
|
||||
$ ./install.sh
|
||||
```
|
||||
* Edit /boot/uEnv.txt
|
||||
```
|
||||
# 1. Add the following overlay
|
||||
###Custom Cape
|
||||
dtb_overlay=/lib/firmware/BB-CAN1-00A0.dtbo
|
||||
|
||||
# 2. Disable auto loading of virutal capes (uncomment the two lines)
|
||||
disable_uboot_overlay_video=1
|
||||
disable_uboot_overlay_audio=1
|
||||
```
|
||||
* Reboot the system
|
||||
@@ -1,51 +0,0 @@
|
||||
```
|
||||
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu stretch main" > /etc/apt/sources.list.d/ros-latest.list'
|
||||
$ wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -O - | sudo apt-key add -
|
||||
$ sudo apt-get update
|
||||
```
|
||||
|
||||
```
|
||||
$ sudo apt-get install -y python-pip python-setuptools python-yaml python-distribute python-docutils python-dateutil python-six
|
||||
$ sudo pip install rosdep rosinstall_generator wstool rosinstall
|
||||
$ sudo apt-get install -y \
|
||||
libconsole-bridge-dev liblz4-dev checkinstall cmake \
|
||||
python-empy python-nose libbz2-dev \
|
||||
libboost-test-dev libboost-dev libboost-program-options-dev \
|
||||
libboost-regex-dev libboost-signals-dev \
|
||||
libtinyxml-dev libboost-filesystem-dev libxml2-dev \
|
||||
libgtest-dev libpoco-dev
|
||||
```
|
||||
|
||||
```
|
||||
$ sudo rosdep init
|
||||
$ rosdep update
|
||||
```
|
||||
|
||||
```
|
||||
$ rosinstall_generator ros_comm --rosdistro melodic --deps --tar > melodic-ros_comm.rosinstall
|
||||
$ wstool init -j1 src melodic-ros_comm.rosinstall
|
||||
```
|
||||
|
||||
```
|
||||
$ # rosdep install --from-paths src --ignore-src --rosdistro melodic -y
|
||||
$ sudo ./src/catkin/bin/catkin_make_isolated --install --install-space /opt/ros/melodic -DCMAKE_BUILD_TYPE=Release
|
||||
```
|
||||
|
||||
```
|
||||
$ source /opt/ros/melodic/setup.bash
|
||||
```
|
||||
|
||||
Additional runtime dependencies:
|
||||
|
||||
```
|
||||
$ sudo apt install -y python-defusedxml python-netifaces
|
||||
```
|
||||
|
||||
```
|
||||
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
|
||||
```
|
||||
|
||||
Reference:
|
||||
|
||||
* [1] https://machinekoder.com/ros-with-debian-stretch-on-the-beaglebone-black-green-blue/
|
||||
* [2] http://wiki.ros.org/melodic/Installation/Source
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,36 +0,0 @@
|
||||
On a Big Endian-System (Solaris on SPARC)
|
||||
|
||||
```
|
||||
$ echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6
|
||||
0
|
||||
```
|
||||
On a little endian system (Linux on x86)
|
||||
```
|
||||
$ echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6
|
||||
1
|
||||
```
|
||||
The solution above is clever and works great for Linux *86 and Solaris Sparc.
|
||||
|
||||
I needed a shell-only (no Perl) solution that also worked on AIX/Power and HPUX/Itanium. Unfortunately the last two don't play nice: AIX reports "6" and HPUX gives an empty line.
|
||||
|
||||
Using your solution, I was able to craft something that worked on all these Unix systems:
|
||||
```
|
||||
$ echo I | tr -d [:space:] | od -to2 | head -n1 | awk '{print $2}' | cut -c6
|
||||
```
|
||||
Regarding the Python solution someone posted, it does not work in Jython because the JVM treats everything as Big. If anyone can get it to work in Jython, please post!
|
||||
|
||||
Also, I found this, which explains the endianness of various platforms. Some hardware can operate in either mode depending on what the O/S selects: http://labs.hoffmanlabs.com/node/544
|
||||
|
||||
If you're going to use awk this line can be simplified to:
|
||||
```
|
||||
echo -n I | od -to2 | awk '{ print substr($2,6,1); exit}'
|
||||
```
|
||||
For small Linux boxes that don't have 'od' (say OpenWrt) then try 'hexdump':
|
||||
```
|
||||
echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}'
|
||||
```
|
||||
|
||||
Reference:
|
||||
|
||||
* [1] https://serverfault.com/questions/163487/how-to-tell-if-a-linux-system-is-big-endian-or-little-endian
|
||||
* [2] https://wiki.rdu.im/_pages/Knowledge-Base/Computing/Computing.html
|
||||
@@ -1,55 +0,0 @@
|
||||
# Commands
|
||||
|
||||
## Create gif animation using "imagemagick"
|
||||
|
||||
```
|
||||
$ convert -delay 120 -loop 0 *.png animated.gif
|
||||
```
|
||||
|
||||
## Get statistics of the code base
|
||||
|
||||
```
|
||||
$ sudo apt install cloc
|
||||
$ cd ~/Workspace/librav/src
|
||||
$ cloc --exclude-dir=cmake,lcmtypes,third_party .
|
||||
```
|
||||
|
||||
## Create a pair of VSP’s
|
||||
|
||||
```
|
||||
$ socat -d -d pty,raw,echo=0 pty,raw,echo=0
|
||||
```
|
||||
|
||||
```
|
||||
$ cat nmea_test.txt > /dev/pts/6
|
||||
```
|
||||
|
||||
## git subtree
|
||||
|
||||
Adding the sub-project as a remote
|
||||
```
|
||||
$ git remote add -f [remote-name] [remote-url]
|
||||
$ git subtree add --prefix [sub-project-name] [remote-name] [branch-name] --squash
|
||||
```
|
||||
|
||||
Update the sub-project
|
||||
```
|
||||
$ git fetch [remote-name] [branch-name]
|
||||
$ git subtree pull --prefix [sub-project-name] [remote-name] [branch-name] --squash
|
||||
```
|
||||
|
||||
Push to remote
|
||||
```
|
||||
$ git subtree push --prefix=[sub-project-name] [remote-name] [branch-name]
|
||||
```
|
||||
|
||||
Firmware branch update
|
||||
```
|
||||
$ git fetch fw_origin pios_pixcar
|
||||
$ git subtree pull --prefix firmware fw_origin pios_pixcar --squash
|
||||
```
|
||||
|
||||
## Reference
|
||||
|
||||
* [Git subtree: the alternative to Git submodule](https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree)
|
||||
* [Virtual serial port: socat](https://justcheckingonall.wordpress.com/2009/06/09/howto-vsp-socat/)
|
||||
@@ -1,12 +0,0 @@
|
||||
# Enable CAN on Jetson TX2
|
||||
|
||||
```
|
||||
$ sudo modprobe can
|
||||
$ sudo modprobe mttcan
|
||||
$ sudo ip link set can0 type can bitrate 500000
|
||||
$ sudo ip link set up can0
|
||||
```
|
||||
|
||||
Reference:
|
||||
|
||||
* https://devtalk.nvidia.com/default/topic/1006762/jetson-tx2/how-can-i-use-can-bus-in-tx2-/post/5166583/#5166583
|
||||
@@ -1 +0,0 @@
|
||||
* Disable tests to keep minimal dependency by default
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 53 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 540 KiB |
@@ -1,7 +0,0 @@
|
||||
can1 131 [8] 00 00 00 00 00 00 E4 1E
|
||||
can1 141 [8] 00 00 00 02 0E 00 E3 3D
|
||||
can1 151 [8] 01 00 00 EF 00 3C E5 6B
|
||||
can1 200 [8] 00 00 00 00 00 00 EA F4
|
||||
can1 201 [8] 00 00 00 00 00 00 EA F5
|
||||
can1 202 [8] 00 00 00 00 00 00 EA F6
|
||||
can1 203 [8] 00 00 00 00 00 00 EA F7
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# bring up can interface
|
||||
sudo ip link set can0 up type can bitrate 500000
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# enable kernel module: gs_usb
|
||||
sudo modprobe gs_usb
|
||||
|
||||
# bring up can interface
|
||||
sudo ip link set can0 up type can bitrate 500000
|
||||
|
||||
# install can utils
|
||||
sudo apt install -y can-utils
|
||||
@@ -1,9 +0,0 @@
|
||||
# Add source directories
|
||||
add_subdirectory(apps)
|
||||
add_subdirectory(comm)
|
||||
add_subdirectory(scout_base)
|
||||
add_subdirectory(third_party)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(unit_tests)
|
||||
endif()
|
||||
@@ -1,16 +0,0 @@
|
||||
# Dependency libraries
|
||||
#find_package(LIBRARY_NAME REQUIRED)
|
||||
|
||||
# tests
|
||||
add_executable(app_scout_demo scout_demo/scout_demo.cpp)
|
||||
target_link_libraries(app_scout_demo scoutbase)
|
||||
|
||||
# add_executable(demo_scout_can demo_scout_can.cpp)
|
||||
# target_link_libraries(demo_scout_can scoutbase)
|
||||
|
||||
# add_executable(demo_scout_serial demo_scout_serial.cpp)
|
||||
# target_link_libraries(demo_scout_serial scoutbase)
|
||||
|
||||
if(BUILD_MONITOR)
|
||||
add_subdirectory(scout_monitor)
|
||||
endif()
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* demo_scout_can.cpp
|
||||
*
|
||||
* Created on: Jun 12, 2019 05:03
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#include "scout_base/scout_base.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::string device_name;
|
||||
int32_t baud_rate = 0;
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
device_name = {argv[1]};
|
||||
std::cout << "Specified CAN: " << device_name << std::endl;
|
||||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
device_name = {argv[1]};
|
||||
baud_rate = std::stol(argv[2]);
|
||||
std::cout << "Specified serial: " << device_name << "@" << baud_rate << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Usage: app_scout_monitor <interface>" << std::endl
|
||||
<< "Example 1: ./app_scout_demo can0" << std::endl
|
||||
<< "Example 2: ./app_scout_demo /dev/ttyUSB0 115200" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ScoutBase scout;
|
||||
scout.Connect(device_name, baud_rate);
|
||||
|
||||
// light control
|
||||
std::cout << "Light: const off" << std::endl;
|
||||
scout.SetLightCommand({ScoutLightCmd::LightMode::CONST_OFF, 0, ScoutLightCmd::LightMode::CONST_OFF, 0});
|
||||
sleep(3);
|
||||
std::cout << "Light: const on" << std::endl;
|
||||
scout.SetLightCommand({ScoutLightCmd::LightMode::CONST_ON, 0, ScoutLightCmd::LightMode::CONST_ON, 0});
|
||||
sleep(3);
|
||||
std::cout << "Light: breath" << std::endl;
|
||||
scout.SetLightCommand({ScoutLightCmd::LightMode::BREATH, 0, ScoutLightCmd::LightMode::BREATH, 0});
|
||||
sleep(3);
|
||||
std::cout << "Light: custom 90-80" << std::endl;
|
||||
scout.SetLightCommand({ScoutLightCmd::LightMode::CUSTOM, 90, ScoutLightCmd::LightMode::CUSTOM, 80});
|
||||
sleep(3);
|
||||
std::cout << "Light: diabled cmd control" << std::endl;
|
||||
scout.DisableLightCmdControl();
|
||||
|
||||
int count = 0;
|
||||
while (true)
|
||||
{
|
||||
// motion control
|
||||
if (count < 5)
|
||||
{
|
||||
std::cout << "Motor: 0.2, 0" << std::endl;
|
||||
scout.SetMotionCommand(0.2, 0.0);
|
||||
}
|
||||
else if (count < 10)
|
||||
{
|
||||
std::cout << "Motor: 0.8, 0" << std::endl;
|
||||
scout.SetMotionCommand(0.8, 0.0);
|
||||
}
|
||||
else if (count < 15)
|
||||
{
|
||||
std::cout << "Motor: 1.5, 0" << std::endl;
|
||||
scout.SetMotionCommand(1.5, 0.0);
|
||||
}
|
||||
else if (count < 20)
|
||||
{
|
||||
std::cout << "Motor: 1.0, 0.5" << std::endl;
|
||||
scout.SetMotionCommand(1.0, 0.5);
|
||||
}
|
||||
else if (count < 25)
|
||||
{
|
||||
std::cout << "Motor: 0.0, 0" << std::endl;
|
||||
scout.SetMotionCommand(0.0, 0.0);
|
||||
}
|
||||
else if (count < 30)
|
||||
{
|
||||
std::cout << "Motor: -0.5, 0" << std::endl;
|
||||
scout.SetMotionCommand(-0.5, 0.0);
|
||||
}
|
||||
else if (count < 35)
|
||||
{
|
||||
std::cout << "Motor: -1.0, -0.5" << std::endl;
|
||||
scout.SetMotionCommand(-1.0, -0.5);
|
||||
}
|
||||
else if (count < 40)
|
||||
{
|
||||
std::cout << "Motor: 0.0, 0, Light: breath" << std::endl;
|
||||
scout.SetMotionCommand(0.0, 0.0);
|
||||
scout.SetLightCommand({ScoutLightCmd::LightMode::BREATH, 0, ScoutLightCmd::LightMode::BREATH, 0});
|
||||
}
|
||||
|
||||
auto state = scout.GetScoutState();
|
||||
std::cout << "-------------------------------" << std::endl;
|
||||
std::cout << "count: " << count << std::endl;
|
||||
std::cout << "control mode: " << static_cast<int>(state.control_mode) << " , base state: " << static_cast<int>(state.base_state) << std::endl;
|
||||
std::cout << "battery voltage: " << state.battery_voltage << std::endl;
|
||||
std::cout << "velocity (linear, angular): " << state.linear_velocity << ", " << state.angular_velocity << std::endl;
|
||||
std::cout << "-------------------------------" << std::endl;
|
||||
|
||||
sleep(1);
|
||||
++count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
# Dependency libraries
|
||||
set(CURSES_NEED_NCURSES TRUE)
|
||||
find_package(Curses REQUIRED)
|
||||
|
||||
# Add libraries
|
||||
set(SCOUT_MONITOR_SRC
|
||||
src/nshapes.cpp
|
||||
src/ncolors.cpp
|
||||
src/scout_monitor.cpp
|
||||
)
|
||||
add_library(monitor STATIC ${SCOUT_MONITOR_SRC})
|
||||
target_link_libraries(monitor scoutbase ${CURSES_LIBRARIES})
|
||||
target_include_directories(monitor PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<BUILD_INTERFACE:${CURSES_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PRIVATE src)
|
||||
|
||||
add_subdirectory(app)
|
||||
|
||||
# Add executables
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
@@ -1,3 +0,0 @@
|
||||
# Add executables
|
||||
add_executable(app_scout_monitor app_scout_monitor.cpp)
|
||||
target_link_libraries(app_scout_monitor monitor)
|
||||
@@ -1,40 +0,0 @@
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "monitor/scout_monitor.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::string device_name;
|
||||
int32_t baud_rate = 0;
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
device_name = {argv[1]};
|
||||
std::cout << "Specified CAN: " << device_name << std::endl;
|
||||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
device_name = {argv[1]};
|
||||
baud_rate = std::stol(argv[2]);
|
||||
std::cout << "Specified serial: " << device_name << "@" << baud_rate << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Usage: app_scout_monitor <interface>" << std::endl
|
||||
<< "Example 1: ./app_scout_monitor can1" << std::endl
|
||||
<< "Example 2: ./app_scout_monitor /dev/ttyUSB0 115200" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ScoutMonitor monitor;
|
||||
monitor.Run(device_name, baud_rate);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 85 KiB |
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* ncolors.hpp
|
||||
*
|
||||
* Created on: Jun 20, 2019 06:22
|
||||
* Description:
|
||||
*
|
||||
* Original source: https://www.linuxjournal.com/content/about-ncurses-colors-0
|
||||
* This copy is based on the original implementation, modified and
|
||||
* maintained by Ruixiang.
|
||||
*
|
||||
* Copyright (c) 2018 Jim Hall
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef NCOLORS_HPP
|
||||
#define NCOLORS_HPP
|
||||
|
||||
#include <ncurses.h>
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
struct NColors
|
||||
{
|
||||
enum BackgroundColor
|
||||
{
|
||||
BLACK = 0,
|
||||
BLUE,
|
||||
GREEN,
|
||||
CYAN,
|
||||
RED,
|
||||
MAGENTA,
|
||||
YELLOW,
|
||||
WHITE
|
||||
};
|
||||
|
||||
enum ForegroundColor
|
||||
{
|
||||
/*
|
||||
BLACK = 0,
|
||||
BLUE,
|
||||
GREEN,
|
||||
CYAN,
|
||||
RED,
|
||||
MAGENTA,
|
||||
YELLOW,
|
||||
WHITE,*/
|
||||
BRIGHT_BLACK = 8,
|
||||
BRIGHT_BLUE,
|
||||
BRIGHT_GREEN,
|
||||
BRIGHT_CYAN,
|
||||
BRIGHT_RED,
|
||||
BRIGHT_MAGENTA,
|
||||
BRIGHT_YELLOW,
|
||||
BRIGHT_WHITE
|
||||
};
|
||||
|
||||
static void InitColors();
|
||||
|
||||
static void SetColor(int fg, int bg = BLACK);
|
||||
static void UnsetColor(int fg, int bg = BLACK);
|
||||
|
||||
static void WSetColor(WINDOW *win, int fg, int bg = BLACK);
|
||||
static void WUnsetColor(WINDOW *win, int fg, int bg = BLACK);
|
||||
};
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* NCOLORS_HPP */
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* nshapes.hpp
|
||||
*
|
||||
* Created on: Jun 20, 2019 06:21
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef NSHAPES_HPP
|
||||
#define NSHAPES_HPP
|
||||
|
||||
#include <ncurses.h>
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
struct NShapes
|
||||
{
|
||||
static void DrawRectangle(int tl_y, int tl_x, int br_y, int br_x);
|
||||
static void WDrawRectangle(WINDOW *win, int tl_y, int tl_x, int br_y, int br_x);
|
||||
};
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* NSHAPES_HPP */
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* scout_monitor.hpp
|
||||
*
|
||||
* Created on: Jun 12, 2019 01:19
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef SCOUT_MONITOR_HPP
|
||||
#define SCOUT_MONITOR_HPP
|
||||
|
||||
#include "scout_base/scout_base.hpp"
|
||||
|
||||
#include <ncurses.h>
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
class ScoutMonitor
|
||||
{
|
||||
public:
|
||||
ScoutMonitor();
|
||||
~ScoutMonitor();
|
||||
|
||||
void Run(std::string device_name = "", int32_t baud_rate = 0);
|
||||
void Terminate() { keep_running_ = false; }
|
||||
|
||||
private:
|
||||
bool keep_running_ = true;
|
||||
bool test_mode_ = true;
|
||||
|
||||
int term_sx_ = -1;
|
||||
int term_sy_ = -1;
|
||||
|
||||
WINDOW *body_info_win_;
|
||||
int bi_win_sx_;
|
||||
int bi_win_sy_;
|
||||
int bi_origin_x_;
|
||||
int bi_origin_y_;
|
||||
|
||||
WINDOW *system_info_win_;
|
||||
int si_win_sx_;
|
||||
int si_win_sy_;
|
||||
int si_origin_x_;
|
||||
int si_origin_y_;
|
||||
|
||||
WINDOW *scout_cmd_win_;
|
||||
|
||||
ScoutBase scout_base_;
|
||||
ScoutState scout_state_;
|
||||
|
||||
const int linear_axis_length_ = 5;
|
||||
const int angular_axis_length_ = 5;
|
||||
|
||||
const int vehicle_fp_offset_x_ = 9;
|
||||
const int vehicle_fp_offset_y_ = 9;
|
||||
|
||||
bool resizing_detected_;
|
||||
|
||||
void UpdateAll();
|
||||
void ClearAll();
|
||||
|
||||
void CalcDimensions();
|
||||
void HandleResizing();
|
||||
|
||||
void SetTestStateData();
|
||||
void ShowVehicleState(int y, int x);
|
||||
void ShowStatusItemName(int y, int x, std::string name);
|
||||
void ShowFault(int y, int x, bool no_fault);
|
||||
void ShowMotorInfo(int y, int x, double cur, int rpm, int temp, bool is_right);
|
||||
|
||||
void UpdateScoutBodyInfo();
|
||||
void UpdateScoutSystemInfo();
|
||||
void UpdateScoutCmdWindow();
|
||||
};
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* SCOUT_MONITOR_HPP */
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* ncolors.cpp
|
||||
*
|
||||
* Created on: Jun 20, 2019 06:22
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#include "monitor/ncolors.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
int IsBold(int fg)
|
||||
{
|
||||
/* return the intensity bit */
|
||||
|
||||
int i;
|
||||
|
||||
i = 1 << 3;
|
||||
return (i & fg);
|
||||
}
|
||||
|
||||
int ColorNum(int fg, int bg)
|
||||
{
|
||||
int B, bbb, ffff;
|
||||
|
||||
B = 1 << 7;
|
||||
bbb = (7 & bg) << 4;
|
||||
ffff = 7 & fg;
|
||||
|
||||
return (B | bbb | ffff);
|
||||
}
|
||||
|
||||
short CursorColor(int fg)
|
||||
{
|
||||
switch (7 & fg)
|
||||
{ /* RGB */
|
||||
case 0: /* 000 */
|
||||
return (COLOR_BLACK);
|
||||
case 1: /* 001 */
|
||||
return (COLOR_BLUE);
|
||||
case 2: /* 010 */
|
||||
return (COLOR_GREEN);
|
||||
case 3: /* 011 */
|
||||
return (COLOR_CYAN);
|
||||
case 4: /* 100 */
|
||||
return (COLOR_RED);
|
||||
case 5: /* 101 */
|
||||
return (COLOR_MAGENTA);
|
||||
case 6: /* 110 */
|
||||
return (COLOR_YELLOW);
|
||||
case 7: /* 111 */
|
||||
return (COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
void NColors::InitColors()
|
||||
{
|
||||
if (has_colors() != FALSE)
|
||||
start_color();
|
||||
else
|
||||
std::cerr << "Your terminal does not support color" << std::endl;
|
||||
|
||||
int fg, bg;
|
||||
int colorpair;
|
||||
|
||||
for (bg = 0; bg <= 7; bg++)
|
||||
{
|
||||
for (fg = 0; fg <= 7; fg++)
|
||||
{
|
||||
colorpair = ColorNum(fg, bg);
|
||||
init_pair(colorpair, CursorColor(fg), CursorColor(bg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NColors::SetColor(int fg, int bg)
|
||||
{
|
||||
// set the color pair (ColorNum) and bold/bright (A_BOLD)
|
||||
attron(COLOR_PAIR(ColorNum(fg, bg)));
|
||||
if (IsBold(fg))
|
||||
attron(A_BOLD);
|
||||
}
|
||||
|
||||
void NColors::UnsetColor(int fg, int bg)
|
||||
{
|
||||
// unset the color pair (ColorNum) and bold/bright (A_BOLD)
|
||||
attroff(COLOR_PAIR(ColorNum(fg, bg)));
|
||||
if (IsBold(fg))
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
|
||||
void NColors::WSetColor(WINDOW *win, int fg, int bg)
|
||||
{
|
||||
// set the color pair (ColorNum) and bold/bright (A_BOLD)
|
||||
wattron(win, COLOR_PAIR(ColorNum(fg, bg)));
|
||||
if (IsBold(fg))
|
||||
wattron(win, A_BOLD);
|
||||
}
|
||||
|
||||
void NColors::WUnsetColor(WINDOW *win, int fg, int bg)
|
||||
{
|
||||
// unset the color pair (ColorNum) and bold/bright (A_BOLD)
|
||||
wattroff(win, COLOR_PAIR(ColorNum(fg, bg)));
|
||||
if (IsBold(fg))
|
||||
wattroff(win, A_BOLD);
|
||||
}
|
||||
} // namespace wescore
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* nshapers.cpp
|
||||
*
|
||||
* Created on: Jun 20, 2019 06:21
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#include "monitor/nshapes.hpp"
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
void NShapes::DrawRectangle(int tl_y, int tl_x, int br_y, int br_x)
|
||||
{
|
||||
for (int i = tl_y; i <= br_y; ++i)
|
||||
{
|
||||
mvprintw(i, tl_x, "|");
|
||||
mvprintw(i, br_x, "|");
|
||||
}
|
||||
for (int i = tl_x; i <= br_x; ++i)
|
||||
{
|
||||
mvprintw(tl_y, i, "-");
|
||||
mvprintw(br_y, i, "-");
|
||||
}
|
||||
}
|
||||
|
||||
void NShapes::WDrawRectangle(WINDOW *win, int tl_y, int tl_x, int br_y, int br_x)
|
||||
{
|
||||
for (int i = tl_y; i <= br_y; ++i)
|
||||
{
|
||||
mvwprintw(win, i, tl_x, "|");
|
||||
mvwprintw(win, i, br_x, "|");
|
||||
}
|
||||
for (int i = tl_x; i <= br_x; ++i)
|
||||
{
|
||||
mvwprintw(win, tl_y, i, "-");
|
||||
mvwprintw(win, br_y, i, "-");
|
||||
}
|
||||
}
|
||||
} // namespace wescore
|
||||
@@ -1,655 +0,0 @@
|
||||
/*
|
||||
* scout_monitor.cpp
|
||||
*
|
||||
* Created on: Jun 12, 2019 01:19
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Coordinate System:
|
||||
*
|
||||
* o --------------------> x
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* |
|
||||
* v
|
||||
* y
|
||||
*/
|
||||
|
||||
#include "monitor/scout_monitor.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <ratio>
|
||||
#include <thread>
|
||||
|
||||
#include "monitor/nshapes.hpp"
|
||||
#include "monitor/ncolors.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
// reference: https://thispointer.com/c-convert-double-to-string-and-manage-precision-scientific-notation/
|
||||
std::string ConvertFloatToString(double vel, int digit_num = 3)
|
||||
{
|
||||
std::ostringstream streamObj;
|
||||
streamObj << std::fixed;
|
||||
streamObj << std::setprecision(digit_num);
|
||||
streamObj << vel;
|
||||
return streamObj.str();
|
||||
}
|
||||
|
||||
// source: https://github.com/rxdu/stopwatch
|
||||
struct StopWatch
|
||||
{
|
||||
using Clock = std::chrono::high_resolution_clock;
|
||||
using time_point = typename Clock::time_point;
|
||||
using duration = typename Clock::duration;
|
||||
|
||||
StopWatch() { tic_point = Clock::now(); };
|
||||
|
||||
time_point tic_point;
|
||||
|
||||
void tic()
|
||||
{
|
||||
tic_point = Clock::now();
|
||||
};
|
||||
|
||||
double toc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - tic_point).count() / 1000000.0;
|
||||
};
|
||||
|
||||
// for different precisions
|
||||
double stoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
double mtoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
double utoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
double ntoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
// you have to call tic() before calling this function
|
||||
void sleep_until_ms(int64_t period_ms)
|
||||
{
|
||||
int64_t duration = period_ms - std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - tic_point).count();
|
||||
|
||||
if (duration > 0)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(duration));
|
||||
};
|
||||
|
||||
void sleep_until_us(int64_t period_us)
|
||||
{
|
||||
int64_t duration = period_us - std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - tic_point).count();
|
||||
|
||||
if (duration > 0)
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(duration));
|
||||
};
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
ScoutMonitor::ScoutMonitor()
|
||||
{
|
||||
// init ncurses
|
||||
initscr();
|
||||
// raw();
|
||||
cbreak();
|
||||
noecho();
|
||||
nonl();
|
||||
curs_set(FALSE);
|
||||
intrflush(stdscr, FALSE);
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
CalcDimensions();
|
||||
|
||||
// setup sub-windows
|
||||
body_info_win_ = newwin(bi_win_sy_, bi_win_sx_, bi_origin_y_, bi_origin_x_);
|
||||
system_info_win_ = newwin(si_win_sy_, si_win_sx_, si_origin_y_, si_origin_x_);
|
||||
|
||||
scout_state_.linear_velocity = 0;
|
||||
scout_state_.angular_velocity = 0;
|
||||
|
||||
NColors::InitColors();
|
||||
}
|
||||
|
||||
ScoutMonitor::~ScoutMonitor()
|
||||
{
|
||||
delwin(body_info_win_);
|
||||
delwin(system_info_win_);
|
||||
endwin();
|
||||
}
|
||||
|
||||
void ScoutMonitor::UpdateAll()
|
||||
{
|
||||
ClearAll();
|
||||
|
||||
CalcDimensions();
|
||||
if (resizing_detected_)
|
||||
HandleResizing();
|
||||
|
||||
UpdateScoutBodyInfo();
|
||||
UpdateScoutSystemInfo();
|
||||
}
|
||||
|
||||
void ScoutMonitor::SetTestStateData()
|
||||
{
|
||||
scout_state_.base_state = BASE_STATE_NORMAL;
|
||||
scout_state_.battery_voltage = 28.5;
|
||||
|
||||
scout_state_.linear_velocity = 1.234;
|
||||
scout_state_.angular_velocity = -0.6853;
|
||||
|
||||
// scout_state_.fault_code |= FAULT_MOTOR_DRV_OVERHEAT_W;
|
||||
// scout_state_.fault_code |= FAULT_MOTOR_OVERCURRENT_W;
|
||||
// scout_state_.fault_code |= FAULT_MOTOR_DRV_OVERHEAT_F;
|
||||
// scout_state_.fault_code |= FAULT_MOTOR_OVERCURRENT_F;
|
||||
// scout_state_.fault_code |= FAULT_BAT_UNDER_VOL_W;
|
||||
// scout_state_.fault_code |= FAULT_BAT_UNDER_VOL_F;
|
||||
scout_state_.fault_code = 0x0000;
|
||||
// scout_state_.fault_code = 0xffff;
|
||||
|
||||
// scout_state_.front_light_state.mode = CONST_ON;
|
||||
scout_state_.front_light_state.mode = LIGHT_MODE_CUSTOM;
|
||||
scout_state_.front_light_state.custom_value = 50;
|
||||
|
||||
scout_state_.rear_light_state.mode = LIGHT_MODE_CONST_ON;
|
||||
|
||||
scout_state_.motor_states[0].current = 10.1;
|
||||
scout_state_.motor_states[0].rpm = 2000;
|
||||
scout_state_.motor_states[0].temperature = 35;
|
||||
|
||||
scout_state_.motor_states[1].current = 10.1;
|
||||
scout_state_.motor_states[1].rpm = 2000;
|
||||
scout_state_.motor_states[1].temperature = 35;
|
||||
|
||||
scout_state_.motor_states[2].current = 10.1;
|
||||
scout_state_.motor_states[2].rpm = 2000;
|
||||
scout_state_.motor_states[2].temperature = 35;
|
||||
|
||||
scout_state_.motor_states[3].current = 10.1;
|
||||
scout_state_.motor_states[3].rpm = 2000;
|
||||
scout_state_.motor_states[3].temperature = 35;
|
||||
}
|
||||
|
||||
void ScoutMonitor::Run(std::string device_name, int32_t baud_rate)
|
||||
{
|
||||
if (device_name != "")
|
||||
test_mode_ = false;
|
||||
|
||||
if (test_mode_)
|
||||
SetTestStateData();
|
||||
else
|
||||
scout_base_.Connect(device_name, baud_rate);
|
||||
|
||||
StopWatch sw;
|
||||
while (keep_running_)
|
||||
{
|
||||
// label starting point of iteration
|
||||
sw.tic();
|
||||
|
||||
// query for latest robot state
|
||||
if (!test_mode_)
|
||||
scout_state_ = scout_base_.GetScoutState();
|
||||
|
||||
// update window contents
|
||||
UpdateAll();
|
||||
|
||||
// manage window refresh rate
|
||||
sw.sleep_until_ms(100);
|
||||
}
|
||||
}
|
||||
|
||||
void ScoutMonitor::CalcDimensions()
|
||||
{
|
||||
int sy, sx;
|
||||
getmaxyx(stdscr, sy, sx);
|
||||
|
||||
if (sy != term_sy_ || sx != term_sx_)
|
||||
{
|
||||
resizing_detected_ = true;
|
||||
|
||||
term_sy_ = sy;
|
||||
term_sx_ = sx;
|
||||
|
||||
bi_win_sy_ = term_sy_;
|
||||
bi_win_sx_ = term_sx_ * 15 / 24;
|
||||
bi_origin_y_ = 0;
|
||||
bi_origin_x_ = 0;
|
||||
|
||||
si_win_sy_ = term_sy_;
|
||||
si_win_sx_ = term_sx_ * 9 / 24;
|
||||
si_origin_y_ = 0;
|
||||
si_origin_x_ = bi_win_sx_;
|
||||
}
|
||||
}
|
||||
|
||||
void ScoutMonitor::HandleResizing()
|
||||
{
|
||||
delwin(body_info_win_);
|
||||
delwin(system_info_win_);
|
||||
|
||||
body_info_win_ = newwin(bi_win_sy_, bi_win_sx_, bi_origin_y_, bi_origin_x_);
|
||||
system_info_win_ = newwin(si_win_sy_, si_win_sx_, si_origin_y_, si_origin_x_);
|
||||
|
||||
resizing_detected_ = false;
|
||||
}
|
||||
|
||||
void ScoutMonitor::ClearAll()
|
||||
{
|
||||
wclear(body_info_win_);
|
||||
wclear(system_info_win_);
|
||||
}
|
||||
|
||||
void ScoutMonitor::ShowVehicleState(int y, int x)
|
||||
{
|
||||
// show linear velocity
|
||||
const int linear_axis_x = x + vehicle_fp_offset_x_;
|
||||
const int linear_axis_tip_y = y + 2;
|
||||
const int linear_axis_origin_y = linear_axis_tip_y + linear_axis_length_;
|
||||
const int linear_axis_negative_y = linear_axis_origin_y + linear_axis_length_ + 1;
|
||||
mvwprintw(body_info_win_, linear_axis_tip_y - 1, linear_axis_x, "^");
|
||||
for (int i = linear_axis_tip_y; i < linear_axis_origin_y; ++i)
|
||||
mvwprintw(body_info_win_, i, linear_axis_x, "-");
|
||||
mvwprintw(body_info_win_, linear_axis_origin_y, linear_axis_x, "x");
|
||||
for (int i = linear_axis_origin_y + 1; i < linear_axis_negative_y; ++i)
|
||||
mvwprintw(body_info_win_, i, linear_axis_x, "-");
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y, linear_axis_x, "v");
|
||||
double linear_percentage = scout_state_.linear_velocity / ScoutMotionCmd::max_linear_velocity;
|
||||
int linear_bars = std::abs(static_cast<int>(linear_percentage * 5)) + 1;
|
||||
if (std::abs(scout_state_.linear_velocity) < 0.001)
|
||||
linear_bars = 0;
|
||||
if (linear_bars > 5)
|
||||
linear_bars = 5;
|
||||
if (scout_state_.linear_velocity > 0)
|
||||
{
|
||||
for (int i = linear_axis_origin_y - linear_bars; i < linear_axis_origin_y; ++i)
|
||||
{
|
||||
NColors::WSetColor(body_info_win_, NColors::BLACK, NColors::CYAN);
|
||||
mvwprintw(body_info_win_, i, linear_axis_x, "-");
|
||||
NColors::WUnsetColor(body_info_win_, NColors::BLACK, NColors::CYAN);
|
||||
}
|
||||
}
|
||||
else if (scout_state_.linear_velocity < 0)
|
||||
{
|
||||
for (int i = linear_axis_origin_y + linear_bars; i > linear_axis_origin_y; --i)
|
||||
{
|
||||
NColors::WSetColor(body_info_win_, NColors::BLACK, NColors::CYAN);
|
||||
mvwprintw(body_info_win_, i, linear_axis_x, "-");
|
||||
NColors::WUnsetColor(body_info_win_, NColors::BLACK, NColors::CYAN);
|
||||
}
|
||||
}
|
||||
|
||||
// show angular velocity
|
||||
const int angular_axis_y = linear_axis_origin_y;
|
||||
const int angular_axis_origin_x = linear_axis_x;
|
||||
const int angular_axis_positive_x = angular_axis_origin_x + angular_axis_length_ + 1;
|
||||
const int angular_axis_negative_x = angular_axis_origin_x - angular_axis_length_;
|
||||
mvwprintw(body_info_win_, angular_axis_y, angular_axis_negative_x - 1, "<");
|
||||
for (int i = angular_axis_negative_x; i < angular_axis_origin_x; ++i)
|
||||
mvwprintw(body_info_win_, angular_axis_y, i, "-");
|
||||
mvwprintw(body_info_win_, linear_axis_origin_y, linear_axis_x, "x");
|
||||
for (int i = angular_axis_origin_x + 1; i < angular_axis_positive_x; ++i)
|
||||
mvwprintw(body_info_win_, angular_axis_y, i, "-");
|
||||
mvwprintw(body_info_win_, angular_axis_y, angular_axis_positive_x, ">");
|
||||
|
||||
double angular_percentage = scout_state_.angular_velocity / ScoutMotionCmd::max_angular_velocity;
|
||||
int angular_bars = std::abs(static_cast<int>(angular_percentage * 5)) + 1;
|
||||
if (std::abs(scout_state_.angular_velocity) < 0.001)
|
||||
angular_bars = 0;
|
||||
if (angular_bars > 5)
|
||||
angular_bars = 5;
|
||||
if (scout_state_.angular_velocity < 0)
|
||||
{
|
||||
for (int i = angular_axis_origin_x + angular_bars; i > angular_axis_origin_x; --i)
|
||||
{
|
||||
NColors::WSetColor(body_info_win_, NColors::BLACK, NColors::MAGENTA);
|
||||
mvwprintw(body_info_win_, angular_axis_y, i, "-");
|
||||
NColors::WUnsetColor(body_info_win_, NColors::BLACK, NColors::MAGENTA);
|
||||
}
|
||||
}
|
||||
else if (scout_state_.angular_velocity > 0)
|
||||
{
|
||||
for (int i = angular_axis_origin_x - angular_bars; i < angular_axis_origin_x; ++i)
|
||||
{
|
||||
NColors::WSetColor(body_info_win_, NColors::BLACK, NColors::MAGENTA);
|
||||
mvwprintw(body_info_win_, angular_axis_y, i, "-");
|
||||
NColors::WUnsetColor(body_info_win_, NColors::BLACK, NColors::MAGENTA);
|
||||
}
|
||||
}
|
||||
|
||||
// show velocity values
|
||||
std::string linear_vel_str = "linear : " + ConvertFloatToString(scout_state_.linear_velocity);
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y + 2, angular_axis_negative_x - 2, linear_vel_str.c_str());
|
||||
|
||||
std::string angular_vel_str = "angular: " + ConvertFloatToString(scout_state_.angular_velocity);
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y + 3, angular_axis_negative_x - 2, angular_vel_str.c_str());
|
||||
|
||||
// show vehicle base
|
||||
NShapes::WDrawRectangle(body_info_win_, linear_axis_tip_y - 2, angular_axis_negative_x - 4,
|
||||
linear_axis_negative_y + 4, angular_axis_positive_x + 3);
|
||||
|
||||
// show vehicle wheels
|
||||
NShapes::WDrawRectangle(body_info_win_, linear_axis_tip_y - 1, angular_axis_negative_x - 9,
|
||||
linear_axis_tip_y + 4, angular_axis_negative_x - 5);
|
||||
NShapes::WDrawRectangle(body_info_win_, linear_axis_negative_y - 2, angular_axis_negative_x - 9,
|
||||
linear_axis_negative_y + 3, angular_axis_negative_x - 5);
|
||||
NShapes::WDrawRectangle(body_info_win_, linear_axis_tip_y - 1, angular_axis_positive_x + 4,
|
||||
linear_axis_tip_y + 4, angular_axis_positive_x + 8);
|
||||
NShapes::WDrawRectangle(body_info_win_, linear_axis_negative_y - 2, angular_axis_positive_x + 4,
|
||||
linear_axis_negative_y + 3, angular_axis_positive_x + 8);
|
||||
|
||||
// front right motor
|
||||
ShowMotorInfo(linear_axis_tip_y - 1, angular_axis_positive_x + 4, scout_state_.motor_states[0].current,
|
||||
scout_state_.motor_states[0].rpm, scout_state_.motor_states[0].temperature, true);
|
||||
// front left motor
|
||||
ShowMotorInfo(linear_axis_tip_y - 1, angular_axis_negative_x - 9, scout_state_.motor_states[1].current,
|
||||
scout_state_.motor_states[1].rpm, scout_state_.motor_states[1].temperature, false);
|
||||
// rear left motor
|
||||
ShowMotorInfo(linear_axis_negative_y - 2, angular_axis_negative_x - 9, scout_state_.motor_states[2].current,
|
||||
scout_state_.motor_states[2].rpm, scout_state_.motor_states[2].temperature, false);
|
||||
// rear right motor
|
||||
ShowMotorInfo(linear_axis_negative_y - 2, angular_axis_positive_x + 4, scout_state_.motor_states[3].current,
|
||||
scout_state_.motor_states[3].rpm, scout_state_.motor_states[3].temperature, true);
|
||||
|
||||
// show vehicle lights
|
||||
std::string front_mode_str = "Mode: ";
|
||||
if (scout_state_.front_light_state.mode == LIGHT_MODE_CONST_ON)
|
||||
front_mode_str += "ON";
|
||||
else if (scout_state_.front_light_state.mode == LIGHT_MODE_CONST_OFF)
|
||||
front_mode_str += "OFF";
|
||||
else if (scout_state_.front_light_state.mode == LIGHT_MODE_BREATH)
|
||||
front_mode_str += "BREATH";
|
||||
else if (scout_state_.front_light_state.mode == LIGHT_MODE_CUSTOM)
|
||||
front_mode_str += "CUSTOM";
|
||||
mvwprintw(body_info_win_, linear_axis_tip_y - 4, angular_axis_origin_x - 13, front_mode_str.c_str());
|
||||
std::string front_custom_str = "Custom: " + ConvertFloatToString(scout_state_.front_light_state.custom_value, 0);
|
||||
mvwprintw(body_info_win_, linear_axis_tip_y - 4, angular_axis_origin_x + 3, front_custom_str.c_str());
|
||||
if (scout_state_.front_light_state.mode != LIGHT_MODE_CONST_OFF &&
|
||||
!(scout_state_.front_light_state.mode == LIGHT_MODE_CUSTOM && scout_state_.front_light_state.custom_value == 0))
|
||||
{
|
||||
NColors::WSetColor(body_info_win_, NColors::BRIGHT_YELLOW);
|
||||
for (int i = angular_axis_origin_x - 5; i < angular_axis_origin_x - 1; ++i)
|
||||
mvwprintw(body_info_win_, linear_axis_tip_y - 3, i, "v");
|
||||
mvwprintw(body_info_win_, linear_axis_tip_y - 3, angular_axis_origin_x, "v");
|
||||
for (int i = angular_axis_origin_x + 2; i <= angular_axis_origin_x + 5; ++i)
|
||||
mvwprintw(body_info_win_, linear_axis_tip_y - 3, i, "v");
|
||||
NColors::WUnsetColor(body_info_win_, NColors::BRIGHT_YELLOW);
|
||||
}
|
||||
|
||||
std::string rear_mode_str = "Mode: ";
|
||||
if (scout_state_.rear_light_state.mode == LIGHT_MODE_CONST_ON)
|
||||
rear_mode_str += "ON";
|
||||
else if (scout_state_.rear_light_state.mode == LIGHT_MODE_CONST_OFF)
|
||||
rear_mode_str += "OFF";
|
||||
else if (scout_state_.rear_light_state.mode == LIGHT_MODE_BREATH)
|
||||
rear_mode_str += "BREATH";
|
||||
else if (scout_state_.rear_light_state.mode == LIGHT_MODE_CUSTOM)
|
||||
rear_mode_str += "CUSTOM";
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y + 6, angular_axis_origin_x - 13, rear_mode_str.c_str());
|
||||
std::string rear_custom_str = "Custom: " + ConvertFloatToString(scout_state_.rear_light_state.custom_value, 0);
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y + 6, angular_axis_origin_x + 3, rear_custom_str.c_str());
|
||||
if (scout_state_.rear_light_state.mode != LIGHT_MODE_CONST_OFF &&
|
||||
!(scout_state_.rear_light_state.mode == LIGHT_MODE_CUSTOM && scout_state_.rear_light_state.custom_value == 0))
|
||||
{
|
||||
NColors::WSetColor(body_info_win_, NColors::BRIGHT_RED);
|
||||
for (int i = angular_axis_origin_x - 5; i < angular_axis_origin_x - 1; ++i)
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y + 5, i, "^");
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y + 5, angular_axis_origin_x, "^");
|
||||
for (int i = angular_axis_origin_x + 2; i <= angular_axis_origin_x + 5; ++i)
|
||||
mvwprintw(body_info_win_, linear_axis_negative_y + 5, i, "^");
|
||||
NColors::WUnsetColor(body_info_win_, NColors::BRIGHT_RED);
|
||||
}
|
||||
}
|
||||
|
||||
void ScoutMonitor::UpdateScoutBodyInfo()
|
||||
{
|
||||
// for (int i = 0; i < bi_win_sx_; i++)
|
||||
// mvwprintw(body_info_win_, bi_win_sy_ - 1, i, "-");
|
||||
|
||||
ShowVehicleState(bi_win_sy_ / 2 - vehicle_fp_offset_y_, bi_win_sx_ / 2 - vehicle_fp_offset_x_);
|
||||
|
||||
wrefresh(body_info_win_);
|
||||
}
|
||||
|
||||
void ScoutMonitor::UpdateScoutSystemInfo()
|
||||
{
|
||||
for (int i = 0; i < si_win_sy_; i++)
|
||||
mvwprintw(system_info_win_, i, 0, "|");
|
||||
|
||||
const int state_title_col = (si_win_sx_ - 24) / 2;
|
||||
const int state_value_col = state_title_col + 20;
|
||||
const int state_div_col = state_value_col - 2;
|
||||
|
||||
// system state
|
||||
const int sec1 = static_cast<int>(std::round((si_win_sy_ - 20) / 2.0));
|
||||
ShowStatusItemName(sec1, state_title_col, "System state");
|
||||
|
||||
if (scout_state_.base_state == BASE_STATE_NORMAL)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::GREEN);
|
||||
mvwprintw(system_info_win_, sec1, state_value_col, "NORMAL");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::GREEN);
|
||||
}
|
||||
else if (scout_state_.base_state == BASE_STATE_ESTOP)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::YELLOW);
|
||||
mvwprintw(system_info_win_, sec1, state_value_col, "ESTOP");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::YELLOW);
|
||||
}
|
||||
else if (scout_state_.base_state == BASE_STATE_EXCEPTION)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::RED);
|
||||
mvwprintw(system_info_win_, sec1, state_value_col, "EXCEPT");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::RED);
|
||||
}
|
||||
|
||||
// control mode
|
||||
ShowStatusItemName(sec1 + 1, state_title_col, "Control mode");
|
||||
if (scout_state_.control_mode == CTRL_MODE_REMOTE)
|
||||
mvwprintw(system_info_win_, sec1 + 1, state_value_col, "REMOTE");
|
||||
else if (scout_state_.control_mode == CTRL_MODE_CMD_CAN)
|
||||
mvwprintw(system_info_win_, sec1 + 1, state_value_col, "CMD");
|
||||
else if (scout_state_.control_mode == CTRL_MODE_CMD_UART)
|
||||
mvwprintw(system_info_win_, sec1 + 1, state_value_col, "CMD");
|
||||
// mvwprintw(system_info_win_, sec1 + 1, state_value_col, std::to_string(scout_state_.control_mode).c_str());
|
||||
|
||||
// battery voltage
|
||||
ShowStatusItemName(sec1 + 2, state_title_col, "Battery voltage");
|
||||
std::string bat_vol_str = ConvertFloatToString(scout_state_.battery_voltage, 1) + " v";
|
||||
mvwprintw(system_info_win_, sec1 + 2, state_value_col, bat_vol_str.c_str());
|
||||
|
||||
const int fault_col_1 = state_value_col;
|
||||
const int fault_col_2 = fault_col_1 + 2;
|
||||
const int fault_col_3 = fault_col_2 + 2;
|
||||
|
||||
const int sec2 = sec1 + 4;
|
||||
mvwprintw(system_info_win_, sec2, state_title_col, "System faults");
|
||||
|
||||
// motor driver over heat;
|
||||
ShowStatusItemName(sec2 + 1, state_title_col, "-Drv over-heat");
|
||||
if ((scout_state_.fault_code & FAULT_MOTOR_DRV_OVERHEAT_W) == 0 &&
|
||||
(scout_state_.fault_code & FAULT_MOTOR_DRV_OVERHEAT_F) == 0)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::GREEN);
|
||||
mvwprintw(system_info_win_, sec2 + 1, fault_col_1, "N");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scout_state_.fault_code & FAULT_MOTOR_DRV_OVERHEAT_W)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::YELLOW);
|
||||
mvwprintw(system_info_win_, sec2 + 1, fault_col_2, "W");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::YELLOW);
|
||||
}
|
||||
if (scout_state_.fault_code & FAULT_MOTOR_DRV_OVERHEAT_F)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::RED);
|
||||
mvwprintw(system_info_win_, sec2 + 1, fault_col_3, "P");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::RED);
|
||||
}
|
||||
}
|
||||
|
||||
// motor driver over current
|
||||
ShowStatusItemName(sec2 + 2, state_title_col, "-Mt over-current");
|
||||
if ((scout_state_.fault_code & FAULT_MOTOR_OVERCURRENT_W) == 0 &&
|
||||
(scout_state_.fault_code & FAULT_MOTOR_OVERCURRENT_F) == 0)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::GREEN);
|
||||
mvwprintw(system_info_win_, sec2 + 2, fault_col_1, "N");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scout_state_.fault_code & FAULT_MOTOR_OVERCURRENT_W)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::YELLOW);
|
||||
mvwprintw(system_info_win_, sec2 + 2, fault_col_2, "W");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::YELLOW);
|
||||
}
|
||||
if (scout_state_.fault_code & FAULT_MOTOR_OVERCURRENT_F)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::RED);
|
||||
mvwprintw(system_info_win_, sec2 + 2, fault_col_3, "P");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::RED);
|
||||
}
|
||||
}
|
||||
|
||||
// battery under voltage
|
||||
ShowStatusItemName(sec2 + 3, state_title_col, "-Bat under volt");
|
||||
if ((scout_state_.fault_code & FAULT_BAT_UNDER_VOL_W) == 0 &&
|
||||
(scout_state_.fault_code & FAULT_BAT_UNDER_VOL_F) == 0)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::GREEN);
|
||||
mvwprintw(system_info_win_, sec2 + 3, fault_col_1, "N");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scout_state_.fault_code & FAULT_BAT_UNDER_VOL_W)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::YELLOW);
|
||||
mvwprintw(system_info_win_, sec2 + 3, fault_col_2, "W");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::YELLOW);
|
||||
}
|
||||
if (scout_state_.fault_code & FAULT_BAT_UNDER_VOL_F)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::RED);
|
||||
mvwprintw(system_info_win_, sec2 + 3, fault_col_3, "F");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::RED);
|
||||
}
|
||||
}
|
||||
|
||||
// battery over voltage
|
||||
ShowStatusItemName(sec2 + 4, state_title_col, "-Bat over volt");
|
||||
ShowFault(sec2 + 4, fault_col_1, (scout_state_.fault_code & FAULT_BAT_OVER_VOL_F) == 0);
|
||||
|
||||
const int sec3 = sec2 + 6;
|
||||
mvwprintw(system_info_win_, sec3, state_title_col, "Comm faults");
|
||||
|
||||
// CAN cmd checksum
|
||||
ShowStatusItemName(sec3 + 1, state_title_col, "-CAN cmd checksum");
|
||||
ShowFault(sec3 + 1, fault_col_1, (scout_state_.fault_code & FAULT_CAN_CHECKSUM_ERROR) == 0);
|
||||
|
||||
// motor comm
|
||||
ShowStatusItemName(sec3 + 2, state_title_col, "-Motor 1 comm");
|
||||
ShowFault(sec3 + 2, fault_col_1, (scout_state_.fault_code & FAULT_MOTOR1_COMM_F) == 0);
|
||||
|
||||
ShowStatusItemName(sec3 + 3, state_title_col, "-Motor 2 comm");
|
||||
ShowFault(sec3 + 3, fault_col_1, (scout_state_.fault_code & FAULT_MOTOR2_COMM_F) == 0);
|
||||
|
||||
ShowStatusItemName(sec3 + 4, state_title_col, "-Motor 3 comm");
|
||||
ShowFault(sec3 + 4, fault_col_1, (scout_state_.fault_code & FAULT_MOTOR3_COMM_F) == 0);
|
||||
|
||||
ShowStatusItemName(sec3 + 5, state_title_col, "-Motor 4 comm");
|
||||
ShowFault(sec3 + 5, fault_col_1, (scout_state_.fault_code & FAULT_MOTOR4_COMM_F) == 0);
|
||||
|
||||
const int sec4 = sec3 + 8;
|
||||
NColors::WSetColor(system_info_win_, NColors::GREEN);
|
||||
mvwprintw(system_info_win_, sec4, state_title_col + 1, "N: Normal");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::GREEN);
|
||||
|
||||
NColors::WSetColor(system_info_win_, NColors::YELLOW);
|
||||
mvwprintw(system_info_win_, sec4, state_title_col + 12, "W: Warning");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::YELLOW);
|
||||
|
||||
NColors::WSetColor(system_info_win_, NColors::RED);
|
||||
mvwprintw(system_info_win_, sec4 + 1, state_title_col + 1, "F: Fault P: Protection");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::RED);
|
||||
|
||||
wrefresh(system_info_win_);
|
||||
}
|
||||
|
||||
void ScoutMonitor::ShowStatusItemName(int y, int x, std::string name)
|
||||
{
|
||||
const int state_value_col = x + 20;
|
||||
const int state_div_col = state_value_col - 2;
|
||||
|
||||
mvwprintw(system_info_win_, y, x, name.c_str());
|
||||
mvwprintw(system_info_win_, y, state_div_col, ":");
|
||||
}
|
||||
|
||||
void ScoutMonitor::ShowFault(int y, int x, bool no_fault)
|
||||
{
|
||||
const int fault_col_1 = x;
|
||||
const int fault_col_2 = x + 2;
|
||||
const int fault_col_3 = fault_col_2 + 2;
|
||||
|
||||
if (no_fault)
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::GREEN);
|
||||
mvwprintw(system_info_win_, y, fault_col_1, "N");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
NColors::WSetColor(system_info_win_, NColors::RED);
|
||||
mvwprintw(system_info_win_, y, fault_col_3, "F");
|
||||
NColors::WUnsetColor(system_info_win_, NColors::RED);
|
||||
}
|
||||
}
|
||||
|
||||
// (y,x): position of the top left point of corresponding wheel
|
||||
void ScoutMonitor::ShowMotorInfo(int y, int x, double cur, int rpm, int temp, bool is_right)
|
||||
{
|
||||
int col_title = x;
|
||||
if (is_right)
|
||||
col_title += 6;
|
||||
else
|
||||
col_title -= 9;
|
||||
|
||||
std::string cur_str = "CUR:" + ConvertFloatToString(cur, 1);
|
||||
mvwprintw(body_info_win_, y + 1, col_title, cur_str.c_str());
|
||||
|
||||
std::string rpm_str = "RPM:" + ConvertFloatToString(rpm, 0);
|
||||
mvwprintw(body_info_win_, y + 2, col_title, rpm_str.c_str());
|
||||
|
||||
std::string temp_str = "TMP:" + ConvertFloatToString(temp, 0);
|
||||
mvwprintw(body_info_win_, y + 3, col_title, temp_str.c_str());
|
||||
}
|
||||
} // namespace wescore
|
||||
@@ -1,15 +0,0 @@
|
||||
# Add executables
|
||||
add_executable(test_scout_monitor test_scout_monitor.cpp)
|
||||
target_link_libraries(test_scout_monitor monitor)
|
||||
|
||||
add_executable(test_scout_monitor_virtual test_scout_monitor_virtual.cpp)
|
||||
target_link_libraries(test_scout_monitor_virtual monitor)
|
||||
|
||||
# add_executable(test_ncurses test_ncurses.cpp)
|
||||
# target_link_libraries(test_ncurses monitor)
|
||||
|
||||
# add_executable(test_ncolor test_ncolor.c)
|
||||
# target_link_libraries(test_ncolor monitor)
|
||||
|
||||
# add_executable(test_ncolor2 test_ncolor2.cpp)
|
||||
# target_link_libraries(test_ncolor2 monitor)
|
||||
@@ -1,158 +0,0 @@
|
||||
/* color-demo.c */
|
||||
// source: https://www.linuxjournal.com/content/about-ncurses-colors-0
|
||||
|
||||
#include <curses.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int is_bold(int fg);
|
||||
void init_colorpairs(void);
|
||||
short curs_color(int fg);
|
||||
int colornum(int fg, int bg);
|
||||
void setcolor(int fg, int bg);
|
||||
void unsetcolor(int fg, int bg);
|
||||
|
||||
void init_colorpairs(void)
|
||||
{
|
||||
int fg, bg;
|
||||
int colorpair;
|
||||
|
||||
for (bg = 0; bg <= 7; bg++)
|
||||
{
|
||||
for (fg = 0; fg <= 7; fg++)
|
||||
{
|
||||
colorpair = colornum(fg, bg);
|
||||
init_pair(colorpair, curs_color(fg), curs_color(bg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
short curs_color(int fg)
|
||||
{
|
||||
switch (7 & fg)
|
||||
{ /* RGB */
|
||||
case 0: /* 000 */
|
||||
return (COLOR_BLACK);
|
||||
case 1: /* 001 */
|
||||
return (COLOR_BLUE);
|
||||
case 2: /* 010 */
|
||||
return (COLOR_GREEN);
|
||||
case 3: /* 011 */
|
||||
return (COLOR_CYAN);
|
||||
case 4: /* 100 */
|
||||
return (COLOR_RED);
|
||||
case 5: /* 101 */
|
||||
return (COLOR_MAGENTA);
|
||||
case 6: /* 110 */
|
||||
return (COLOR_YELLOW);
|
||||
case 7: /* 111 */
|
||||
return (COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
int colornum(int fg, int bg)
|
||||
{
|
||||
int B, bbb, ffff;
|
||||
|
||||
B = 1 << 7;
|
||||
bbb = (7 & bg) << 4;
|
||||
ffff = 7 & fg;
|
||||
|
||||
return (B | bbb | ffff);
|
||||
}
|
||||
|
||||
void setcolor(int fg, int bg)
|
||||
{
|
||||
/* set the color pair (colornum) and bold/bright (A_BOLD) */
|
||||
|
||||
attron(COLOR_PAIR(colornum(fg, bg)));
|
||||
if (is_bold(fg))
|
||||
{
|
||||
attron(A_BOLD);
|
||||
}
|
||||
}
|
||||
|
||||
void unsetcolor(int fg, int bg)
|
||||
{
|
||||
/* unset the color pair (colornum) and
|
||||
bold/bright (A_BOLD) */
|
||||
|
||||
attroff(COLOR_PAIR(colornum(fg, bg)));
|
||||
if (is_bold(fg))
|
||||
{
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
}
|
||||
|
||||
int is_bold(int fg)
|
||||
{
|
||||
/* return the intensity bit */
|
||||
|
||||
int i;
|
||||
|
||||
i = 1 << 3;
|
||||
return (i & fg);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fg, bg;
|
||||
|
||||
/* initialize curses */
|
||||
|
||||
initscr();
|
||||
keypad(stdscr, TRUE);
|
||||
cbreak();
|
||||
noecho();
|
||||
|
||||
/* initialize colors */
|
||||
|
||||
if (has_colors() == FALSE)
|
||||
{
|
||||
endwin();
|
||||
puts("Your terminal does not support color");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
start_color();
|
||||
init_colorpairs();
|
||||
|
||||
/* draw test pattern */
|
||||
|
||||
if ((LINES < 24) || (COLS < 80))
|
||||
{
|
||||
endwin();
|
||||
puts("Your terminal needs to be at least 80x24");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
mvaddstr(0, 35, "COLOR DEMO");
|
||||
mvaddstr(2, 0, "low intensity text colors (0-7)");
|
||||
mvaddstr(12, 0, "high intensity text colors (8-15)");
|
||||
|
||||
for (bg = 0; bg <= 7; bg++)
|
||||
{
|
||||
for (fg = 0; fg <= 7; fg++)
|
||||
{
|
||||
setcolor(fg, bg);
|
||||
mvaddstr(fg + 3, bg * 10, "...test...");
|
||||
unsetcolor(fg, bg);
|
||||
}
|
||||
|
||||
for (fg = 8; fg <= 15; fg++)
|
||||
{
|
||||
setcolor(fg, bg);
|
||||
mvaddstr(fg + 5, bg * 10, "...test...");
|
||||
unsetcolor(fg, bg);
|
||||
}
|
||||
}
|
||||
|
||||
mvaddstr(LINES - 1, 0, "press any key to quit");
|
||||
|
||||
refresh();
|
||||
|
||||
getch();
|
||||
endwin();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#include "monitor/ncolors.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fg, bg;
|
||||
|
||||
/* initialize curses */
|
||||
|
||||
initscr();
|
||||
keypad(stdscr, TRUE);
|
||||
cbreak();
|
||||
noecho();
|
||||
|
||||
/* initialize colors */
|
||||
|
||||
if (has_colors() == FALSE)
|
||||
{
|
||||
endwin();
|
||||
puts("Your terminal does not support color");
|
||||
return 1;
|
||||
}
|
||||
|
||||
NColors::InitColors();
|
||||
|
||||
/* draw test pattern */
|
||||
|
||||
if ((LINES < 24) || (COLS < 80))
|
||||
{
|
||||
endwin();
|
||||
puts("Your terminal needs to be at least 80x24");
|
||||
return 2;
|
||||
}
|
||||
|
||||
mvaddstr(0, 35, "COLOR DEMO");
|
||||
mvaddstr(2, 0, "low intensity text colors (0-7)");
|
||||
mvaddstr(12, 0, "high intensity text colors (8-15)");
|
||||
|
||||
for (bg = 0; bg <= 7; bg++)
|
||||
{
|
||||
for (fg = 0; fg <= 7; fg++)
|
||||
{
|
||||
NColors::SetColor(fg, bg);
|
||||
mvaddstr(fg + 3, bg * 10, "...test...");
|
||||
NColors::UnsetColor(fg, bg);
|
||||
}
|
||||
|
||||
for (fg = 8; fg <= 15; fg++)
|
||||
{
|
||||
NColors::SetColor(fg, bg);
|
||||
mvaddstr(fg + 5, bg * 10, "...test...");
|
||||
NColors::UnsetColor(fg, bg);
|
||||
}
|
||||
}
|
||||
|
||||
mvaddstr(LINES - 1, 0, "press any key to quit");
|
||||
|
||||
refresh();
|
||||
|
||||
getch();
|
||||
endwin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
#include <panel.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NLINES 10
|
||||
#define NCOLS 40
|
||||
|
||||
void init_wins(WINDOW **wins, int n);
|
||||
void win_show(WINDOW *win, char *label, int label_color);
|
||||
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
|
||||
|
||||
int main()
|
||||
{ WINDOW *my_wins[3];
|
||||
PANEL *my_panels[3];
|
||||
PANEL *top;
|
||||
int ch;
|
||||
|
||||
/* Initialize curses */
|
||||
initscr();
|
||||
start_color();
|
||||
cbreak();
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
/* Initialize all the colors */
|
||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||
init_pair(3, COLOR_BLUE, COLOR_BLACK);
|
||||
init_pair(4, COLOR_CYAN, COLOR_BLACK);
|
||||
|
||||
init_wins(my_wins, 3);
|
||||
|
||||
/* Attach a panel to each window */ /* Order is bottom up */
|
||||
my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
|
||||
my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */
|
||||
my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */
|
||||
|
||||
/* Set up the user pointers to the next panel */
|
||||
set_panel_userptr(my_panels[0], my_panels[1]);
|
||||
set_panel_userptr(my_panels[1], my_panels[2]);
|
||||
set_panel_userptr(my_panels[2], my_panels[0]);
|
||||
|
||||
/* Update the stacking order. 2nd panel will be on top */
|
||||
update_panels();
|
||||
|
||||
/* Show it on the screen */
|
||||
attron(COLOR_PAIR(4));
|
||||
mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
|
||||
attroff(COLOR_PAIR(4));
|
||||
doupdate();
|
||||
|
||||
top = my_panels[2];
|
||||
while((ch = getch()) != KEY_F(1))
|
||||
{ switch(ch)
|
||||
{ case 9:
|
||||
top = (PANEL *)panel_userptr(top);
|
||||
top_panel(top);
|
||||
break;
|
||||
}
|
||||
update_panels();
|
||||
doupdate();
|
||||
}
|
||||
endwin();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Put all the windows */
|
||||
void init_wins(WINDOW **wins, int n)
|
||||
{ int x, y, i;
|
||||
char label[80];
|
||||
|
||||
y = 2;
|
||||
x = 10;
|
||||
for(i = 0; i < n; ++i)
|
||||
{ wins[i] = newwin(NLINES, NCOLS, y, x);
|
||||
sprintf(label, "Window Number %d", i + 1);
|
||||
win_show(wins[i], label, i + 1);
|
||||
y += 3;
|
||||
x += 7;
|
||||
}
|
||||
}
|
||||
|
||||
/* Show the window with a border and a label */
|
||||
void win_show(WINDOW *win, char *label, int label_color)
|
||||
{ int startx, starty, height, width;
|
||||
|
||||
getbegyx(win, starty, startx);
|
||||
getmaxyx(win, height, width);
|
||||
|
||||
box(win, 0, 0);
|
||||
mvwaddch(win, 2, 0, ACS_LTEE);
|
||||
mvwhline(win, 2, 1, ACS_HLINE, width - 2);
|
||||
mvwaddch(win, 2, width - 1, ACS_RTEE);
|
||||
|
||||
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
|
||||
}
|
||||
|
||||
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
|
||||
{ int length, x, y;
|
||||
float temp;
|
||||
|
||||
if(win == NULL)
|
||||
win = stdscr;
|
||||
getyx(win, y, x);
|
||||
if(startx != 0)
|
||||
x = startx;
|
||||
if(starty != 0)
|
||||
y = starty;
|
||||
if(width == 0)
|
||||
width = 80;
|
||||
|
||||
length = strlen(string);
|
||||
temp = (width - length)/ 2;
|
||||
x = startx + (int)temp;
|
||||
wattron(win, color);
|
||||
mvwprintw(win, y, x, "%s", string);
|
||||
wattroff(win, color);
|
||||
refresh();
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "monitor/scout_monitor.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
ScoutMonitor monitor;
|
||||
|
||||
void SignalHandler(int s)
|
||||
{
|
||||
printf("Caught signal %d\n", s);
|
||||
monitor.Terminate();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sigaction sigIntHandler;
|
||||
sigIntHandler.sa_handler = SignalHandler;
|
||||
sigemptyset(&sigIntHandler.sa_mask);
|
||||
sigIntHandler.sa_flags = 0;
|
||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||
|
||||
std::cout << "scout monitor started" << std::endl;
|
||||
monitor.Run("can1");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "monitor/scout_monitor.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
ScoutMonitor monitor;
|
||||
|
||||
void SignalHandler(int s)
|
||||
{
|
||||
printf("Caught signal %d\n", s);
|
||||
monitor.Terminate();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sigaction sigIntHandler;
|
||||
sigIntHandler.sa_handler = SignalHandler;
|
||||
sigemptyset(&sigIntHandler.sa_mask);
|
||||
sigIntHandler.sa_flags = 0;
|
||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||
|
||||
std::cout << "scout monitor started" << std::endl;
|
||||
monitor.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
# Add source directories
|
||||
add_subdirectory(async_io)
|
||||
add_subdirectory(scout_protocol)
|
||||
@@ -1,22 +0,0 @@
|
||||
# Dependency libraries
|
||||
# find_package(LIB_NAME REQUIRED)
|
||||
|
||||
# Add libraries
|
||||
set(ASYNC_IO_LIB_SRC
|
||||
src/async_serial.cpp
|
||||
src/async_can.cpp
|
||||
src/asyncio_utils.cpp
|
||||
)
|
||||
add_library(asyncio STATIC ${ASYNC_IO_LIB_SRC})
|
||||
set_target_properties(asyncio PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_definitions(asyncio PUBLIC "-DASIO_ENABLE_OLD_SERVICES -DASIO_HAS_POSIX_STREAM_DESCRIPTOR")
|
||||
target_link_libraries(asyncio asio pthread)
|
||||
target_include_directories(asyncio PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PRIVATE src)
|
||||
|
||||
# Add executables
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* async_can.hpp
|
||||
*
|
||||
* Created on: Jun 10, 2019 02:16
|
||||
* Description: code based on uavcan and libmavconn
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 UAVCAN Team
|
||||
*
|
||||
* Distributed under the MIT License, available in the file LICENSE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* libmavconn
|
||||
* Copyright 2013,2014,2015,2016 Vladimir Ermakov, All rights reserved.
|
||||
*
|
||||
* This file is part of the mavros package and subject to the license terms
|
||||
* in the top-level LICENSE file of the mavros repository.
|
||||
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
|
||||
*/
|
||||
|
||||
#ifndef ASYNC_CAN_HPP
|
||||
#define ASYNC_CAN_HPP
|
||||
|
||||
#include <linux/can.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#include "asio.hpp"
|
||||
#include "asio/posix/basic_stream_descriptor.hpp"
|
||||
|
||||
// #include "async_io/device_error.hpp"
|
||||
// #include "async_io/msg_buffer.hpp"
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
using steady_clock = std::chrono::steady_clock;
|
||||
using lock_guard = std::lock_guard<std::recursive_mutex>;
|
||||
|
||||
class ASyncCAN : public std::enable_shared_from_this<ASyncCAN>
|
||||
{
|
||||
public:
|
||||
static constexpr auto DEFAULT_DEVICE = "can1";
|
||||
static constexpr std::size_t MAX_TXQ_SIZE = 1000;
|
||||
|
||||
using ReceiveCallback = std::function<void(can_frame *rx_frame)>;
|
||||
using ClosedCallback = std::function<void(void)>;
|
||||
|
||||
using Ptr = std::shared_ptr<ASyncCAN>;
|
||||
using ConstPtr = std::shared_ptr<ASyncCAN const>;
|
||||
using WeakPtr = std::weak_ptr<ASyncCAN>;
|
||||
|
||||
struct IOStat
|
||||
{
|
||||
std::size_t tx_total_frames; // total bytes transferred
|
||||
std::size_t rx_total_frames; // total bytes received
|
||||
float tx_speed; // current transfer speed [Frames/s]
|
||||
float rx_speed; // current receive speed [Frames/s]
|
||||
};
|
||||
|
||||
public:
|
||||
ASyncCAN(std::string device = DEFAULT_DEVICE);
|
||||
~ASyncCAN();
|
||||
|
||||
// do not allow copy
|
||||
ASyncCAN(const ASyncCAN &other) = delete;
|
||||
ASyncCAN &operator=(const ASyncCAN &other) = delete;
|
||||
|
||||
std::size_t conn_id;
|
||||
int can_fd_;
|
||||
|
||||
static Ptr open_url(std::string url);
|
||||
void open(std::string device);
|
||||
void close();
|
||||
|
||||
void set_receive_callback(ReceiveCallback cb) { receive_cb = cb; }
|
||||
void set_closed_callback(ClosedCallback cb) { port_closed_cb = cb; }
|
||||
|
||||
inline bool is_open() { return true; }
|
||||
IOStat get_iostat();
|
||||
|
||||
void send_frame(const can_frame &tx_frame);
|
||||
|
||||
private:
|
||||
// monotonic counter (increment only)
|
||||
bool can_interface_opened_ = false;
|
||||
static std::atomic<std::size_t> conn_id_counter;
|
||||
|
||||
struct can_frame rcv_frame;
|
||||
|
||||
// port statistics
|
||||
std::atomic<std::size_t> tx_total_frames;
|
||||
std::atomic<std::size_t> rx_total_frames;
|
||||
std::size_t last_tx_total_frames;
|
||||
std::size_t last_rx_total_frames;
|
||||
std::chrono::time_point<steady_clock> last_iostat;
|
||||
std::recursive_mutex iostat_mutex;
|
||||
|
||||
// io service
|
||||
asio::io_service io_service;
|
||||
asio::posix::basic_stream_descriptor<> stream;
|
||||
std::thread io_thread;
|
||||
|
||||
// callback objects
|
||||
ClosedCallback port_closed_cb;
|
||||
ReceiveCallback receive_cb;
|
||||
|
||||
// internal processing
|
||||
void do_read(struct can_frame &rec_frame, asio::posix::basic_stream_descriptor<> &stream);
|
||||
void do_write(bool check_tx_state);
|
||||
|
||||
void call_receive_callback(can_frame *rx_frame);
|
||||
void default_receive_callback(can_frame *rx_frame);
|
||||
|
||||
void iostat_tx_add(std::size_t bytes);
|
||||
void iostat_rx_add(std::size_t bytes);
|
||||
};
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* ASYNC_CAN_HPP */
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* async_serial.hpp
|
||||
*
|
||||
* Created on: Nov 23, 2018 22:18
|
||||
* Description: asynchronous serial communication using asio
|
||||
* adapted from code in libmavconn
|
||||
*
|
||||
* Main changes: 1. Removed dependency on Boost (asio standalone
|
||||
* and C++ STL only)
|
||||
* 2. Removed dependency on console-bridge
|
||||
* 3. Removed mavlink related code
|
||||
* 4. Removed UDP/TCP related code
|
||||
*
|
||||
* Author: Vladimir Ermakov <vooon341@gmail.com>
|
||||
* Ruixiang Du <ruixiang.du@gmail.com>
|
||||
*
|
||||
* Additioanl reference:
|
||||
* [1] http://www.webalice.it/fede.tft/serial_port/serial_port.html
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* libmavconn
|
||||
* Copyright 2013,2014,2015,2016 Vladimir Ermakov, All rights reserved.
|
||||
*
|
||||
* This file is part of the mavros package and subject to the license terms
|
||||
* in the top-level LICENSE file of the mavros repository.
|
||||
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
|
||||
*/
|
||||
|
||||
#ifndef ASYNC_SERIAL_HPP
|
||||
#define ASYNC_SERIAL_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
|
||||
#include "asio.hpp"
|
||||
|
||||
#include "async_io/device_error.hpp"
|
||||
#include "async_io/msg_buffer.hpp"
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
using steady_clock = std::chrono::steady_clock;
|
||||
using lock_guard = std::lock_guard<std::recursive_mutex>;
|
||||
|
||||
/// Note: instance of ASyncSerial MUST be managed by a std::shared_ptr<ASyncSerial>
|
||||
class ASyncSerial : public std::enable_shared_from_this<ASyncSerial>
|
||||
{
|
||||
public:
|
||||
static constexpr auto DEFAULT_DEVICE = "/dev/ttyUSB0";
|
||||
static constexpr auto DEFAULT_BAUDRATE = 115200;
|
||||
static constexpr std::size_t MAX_TXQ_SIZE = 1000;
|
||||
|
||||
/**
|
||||
* @param buf: pointer to a buffer
|
||||
* @param bufsize: size of the buffer (the value should be constant in most cases)
|
||||
* @param bytes_received: number of bytes received inside the buffer
|
||||
*/
|
||||
using ReceiveCallback = std::function<void(uint8_t *buf, const size_t bufsize, size_t bytes_received)>;
|
||||
using ClosedCallback = std::function<void(void)>;
|
||||
|
||||
using Ptr = std::shared_ptr<ASyncSerial>;
|
||||
using ConstPtr = std::shared_ptr<ASyncSerial const>;
|
||||
using WeakPtr = std::weak_ptr<ASyncSerial>;
|
||||
|
||||
struct IOStat
|
||||
{
|
||||
std::size_t tx_total_bytes; //!< total bytes transferred
|
||||
std::size_t rx_total_bytes; //!< total bytes received
|
||||
float tx_speed; //!< current transfer speed [B/s]
|
||||
float rx_speed; //!< current receive speed [B/s]
|
||||
};
|
||||
|
||||
public:
|
||||
ASyncSerial(std::string device = DEFAULT_DEVICE, unsigned baudrate = DEFAULT_BAUDRATE, bool hwflow = false);
|
||||
~ASyncSerial();
|
||||
|
||||
// do not allow copy
|
||||
ASyncSerial(const ASyncSerial &other) = delete;
|
||||
ASyncSerial &operator=(const ASyncSerial &other) = delete;
|
||||
|
||||
std::size_t conn_id;
|
||||
|
||||
static Ptr open_url(std::string url);
|
||||
void open(std::string device = "", unsigned baudrate = 0, bool hwflow = false);
|
||||
void close();
|
||||
|
||||
void set_baud(unsigned baudrate) { serial_dev_.set_option(asio::serial_port_base::baud_rate(baudrate)); }
|
||||
|
||||
void send_bytes(const uint8_t *bytes, size_t length);
|
||||
void set_receive_callback(ReceiveCallback cb) { receive_cb = cb; }
|
||||
void set_closed_callback(ClosedCallback cb) { port_closed_cb = cb; }
|
||||
|
||||
inline bool is_open() { return serial_dev_.is_open(); }
|
||||
IOStat get_iostat();
|
||||
|
||||
private:
|
||||
// monotonic counter (increment only)
|
||||
static std::atomic<std::size_t> conn_id_counter;
|
||||
|
||||
// port properties
|
||||
std::string device_ = DEFAULT_DEVICE;
|
||||
unsigned baudrate_ = DEFAULT_BAUDRATE;
|
||||
bool hwflow_ = false;
|
||||
|
||||
// port statistics
|
||||
std::atomic<std::size_t> tx_total_bytes;
|
||||
std::atomic<std::size_t> rx_total_bytes;
|
||||
std::size_t last_tx_total_bytes;
|
||||
std::size_t last_rx_total_bytes;
|
||||
std::chrono::time_point<steady_clock> last_iostat;
|
||||
std::recursive_mutex iostat_mutex;
|
||||
|
||||
// io service
|
||||
asio::io_service io_service;
|
||||
std::thread io_thread;
|
||||
asio::serial_port serial_dev_;
|
||||
|
||||
std::atomic<bool> tx_in_progress;
|
||||
std::deque<MsgBuffer> tx_q;
|
||||
std::array<uint8_t, MsgBuffer::MAX_SIZE> rx_buf;
|
||||
std::recursive_mutex mutex;
|
||||
|
||||
// callback objects
|
||||
ClosedCallback port_closed_cb;
|
||||
ReceiveCallback receive_cb;
|
||||
|
||||
// internal processing
|
||||
void do_read();
|
||||
void do_write(bool check_tx_state);
|
||||
|
||||
void call_receive_callback(uint8_t *buf, const std::size_t bufsize, std::size_t bytes_received);
|
||||
void default_receive_callback(uint8_t *buf, const std::size_t bufsize, std::size_t bytes_received);
|
||||
|
||||
void iostat_tx_add(std::size_t bytes);
|
||||
void iostat_rx_add(std::size_t bytes);
|
||||
};
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* ASYNC_SERIAL_HPP */
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* @brief MAVConn device error class
|
||||
* @file device_error.hpp
|
||||
* @author Vladimir Ermakov <vooon341@gmail.com>
|
||||
*/
|
||||
/*
|
||||
* libmavconn
|
||||
* Copyright 2013,2014,2015,2016 Vladimir Ermakov, All rights reserved.
|
||||
*
|
||||
* This file is part of the mavros package and subject to the license terms
|
||||
* in the top-level LICENSE file of the mavros repository.
|
||||
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_ERROR_HPP
|
||||
#define DEVICE_ERROR_HPP
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
class DeviceError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
DeviceError(const char *module, T msg) : std::runtime_error(make_message(module, msg))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static std::string make_message(const char *module, T msg)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "DeviceError:" << module << ":" << msg_to_string(msg);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static std::string msg_to_string(const char *description)
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
static std::string msg_to_string(int errnum)
|
||||
{
|
||||
return std::strerror(errnum);
|
||||
}
|
||||
|
||||
static std::string msg_to_string(std::system_error &err)
|
||||
{
|
||||
return err.what();
|
||||
}
|
||||
};
|
||||
} // namespace mavconn
|
||||
|
||||
#endif /* DEVICE_ERROR_HPP */
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* @brief MAVConn message buffer class (internal)
|
||||
* @file msgbuffer.hpp
|
||||
* @author Vladimir Ermakov <vooon341@gmail.com>
|
||||
*/
|
||||
/*
|
||||
* libmavconn
|
||||
* Copyright 2014,2015,2016 Vladimir Ermakov, All rights reserved.
|
||||
*
|
||||
* This file is part of the mavros package and subject to the license terms
|
||||
* in the top-level LICENSE file of the mavros repository.
|
||||
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Message buffer for internal use in libmavconn
|
||||
*/
|
||||
struct MsgBuffer
|
||||
{
|
||||
//! Maximum buffer size with padding for CRC bytes (280 + padding)
|
||||
static constexpr ssize_t MAX_PACKET_LEN = 255;
|
||||
static constexpr ssize_t MAX_SIZE = MAX_PACKET_LEN + 16;
|
||||
uint8_t data[MAX_SIZE];
|
||||
ssize_t len;
|
||||
ssize_t pos;
|
||||
|
||||
MsgBuffer() : pos(0),
|
||||
len(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Buffer constructor for send_bytes()
|
||||
* @param[in] nbytes should be less than MAX_SIZE
|
||||
*/
|
||||
MsgBuffer(const uint8_t *bytes, ssize_t nbytes) : pos(0),
|
||||
len(nbytes)
|
||||
{
|
||||
assert(0 < nbytes && nbytes < MAX_SIZE);
|
||||
std::memcpy(data, bytes, nbytes);
|
||||
}
|
||||
|
||||
virtual ~MsgBuffer()
|
||||
{
|
||||
pos = 0;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
uint8_t *dpos()
|
||||
{
|
||||
return data + pos;
|
||||
}
|
||||
|
||||
ssize_t nbytes()
|
||||
{
|
||||
return len - pos;
|
||||
}
|
||||
};
|
||||
} // namespace wescore
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* async_can.cpp
|
||||
*
|
||||
* Created on: Jun 10, 2019 02:25
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
* Copyright (c) 2016 UAVCAN Team
|
||||
*/
|
||||
|
||||
// This is needed to enable necessary declarations in sys/
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "async_io/async_can.hpp"
|
||||
|
||||
#include <net/if.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "asyncio_utils.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
using asio::buffer;
|
||||
using asio::io_service;
|
||||
using std::error_code;
|
||||
|
||||
std::atomic<size_t> ASyncCAN::conn_id_counter{0};
|
||||
|
||||
ASyncCAN::ASyncCAN(std::string device) : tx_total_frames(0),
|
||||
rx_total_frames(0),
|
||||
last_tx_total_frames(0),
|
||||
last_rx_total_frames(0),
|
||||
last_iostat(steady_clock::now()),
|
||||
io_service(),
|
||||
stream(io_service)
|
||||
{
|
||||
conn_id = conn_id_counter.fetch_add(1);
|
||||
open(device);
|
||||
}
|
||||
|
||||
ASyncCAN::~ASyncCAN()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void ASyncCAN::open(std::string device)
|
||||
{
|
||||
const size_t iface_name_size = strlen(device.c_str()) + 1;
|
||||
if (iface_name_size > IFNAMSIZ)
|
||||
return;
|
||||
|
||||
can_fd_ = socket(PF_CAN, SOCK_RAW | SOCK_NONBLOCK, CAN_RAW);
|
||||
if (can_fd_ < 0)
|
||||
return;
|
||||
|
||||
struct ifreq ifr;
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
memcpy(ifr.ifr_name, device.c_str(), iface_name_size);
|
||||
|
||||
const int ioctl_result = ioctl(can_fd_, SIOCGIFINDEX, &ifr);
|
||||
if (ioctl_result < 0)
|
||||
close();
|
||||
|
||||
struct sockaddr_can addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.can_family = AF_CAN;
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
|
||||
const int bind_result = bind(can_fd_, (struct sockaddr *)&addr, sizeof(addr));
|
||||
if (bind_result < 0)
|
||||
close();
|
||||
;
|
||||
|
||||
can_interface_opened_ = true;
|
||||
|
||||
// NOTE: shared_from_this() should not be used in constructors
|
||||
|
||||
// give some work to io_service before start
|
||||
stream.assign(can_fd_);
|
||||
io_service.post(std::bind(&ASyncCAN::do_read, this, std::ref(rcv_frame), std::ref(stream)));
|
||||
|
||||
// run io_service for async io
|
||||
io_thread = std::thread([this]() {
|
||||
set_this_thread_name("mcan%zu", conn_id);
|
||||
io_service.run();
|
||||
});
|
||||
}
|
||||
|
||||
void ASyncCAN::close()
|
||||
{
|
||||
// lock_guard lock(mutex);
|
||||
// if (!is_open())
|
||||
// return;
|
||||
|
||||
const int close_result = ::close(can_fd_);
|
||||
can_fd_ = -1;
|
||||
|
||||
io_service.stop();
|
||||
|
||||
if (io_thread.joinable())
|
||||
io_thread.join();
|
||||
|
||||
io_service.reset();
|
||||
|
||||
can_interface_opened_ = false;
|
||||
|
||||
if (port_closed_cb)
|
||||
port_closed_cb();
|
||||
}
|
||||
|
||||
ASyncCAN::IOStat ASyncCAN::get_iostat()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(iostat_mutex);
|
||||
IOStat stat;
|
||||
|
||||
stat.tx_total_frames = tx_total_frames;
|
||||
stat.rx_total_frames = rx_total_frames;
|
||||
|
||||
auto d_tx = stat.tx_total_frames - last_tx_total_frames;
|
||||
auto d_rx = stat.rx_total_frames - last_rx_total_frames;
|
||||
last_tx_total_frames = stat.tx_total_frames;
|
||||
last_rx_total_frames = stat.rx_total_frames;
|
||||
|
||||
auto now = steady_clock::now();
|
||||
auto dt = now - last_iostat;
|
||||
last_iostat = now;
|
||||
|
||||
float dt_s = std::chrono::duration_cast<std::chrono::seconds>(dt).count();
|
||||
|
||||
stat.tx_speed = d_tx / dt_s;
|
||||
stat.rx_speed = d_rx / dt_s;
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
void ASyncCAN::iostat_tx_add(size_t frame)
|
||||
{
|
||||
tx_total_frames += frame;
|
||||
}
|
||||
|
||||
void ASyncCAN::iostat_rx_add(size_t frame)
|
||||
{
|
||||
rx_total_frames += frame;
|
||||
}
|
||||
|
||||
void ASyncCAN::send_frame(const can_frame &tx_frame)
|
||||
{
|
||||
iostat_tx_add(1);
|
||||
stream.async_write_some(asio::buffer(&tx_frame, sizeof(tx_frame)),
|
||||
[](error_code error, size_t bytes_transferred) {
|
||||
// std::cout << "frame sent" << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
void ASyncCAN::call_receive_callback(can_frame *rx_frame)
|
||||
{
|
||||
// keep track of statistics
|
||||
iostat_rx_add(1);
|
||||
|
||||
// call the actual parser
|
||||
if (receive_cb)
|
||||
receive_cb(rx_frame);
|
||||
else
|
||||
default_receive_callback(rx_frame);
|
||||
}
|
||||
|
||||
void ASyncCAN::default_receive_callback(can_frame *rx_frame)
|
||||
{
|
||||
// do nothing
|
||||
// std::cerr << "no callback function set" << std::endl;
|
||||
std::cout << std::hex << rx_frame->can_id << " ";
|
||||
for (int i = 0; i < rx_frame->can_dlc; i++)
|
||||
std::cout << std::hex << int(rx_frame->data[i]) << " ";
|
||||
std::cout << std::dec << std::endl;
|
||||
}
|
||||
|
||||
void ASyncCAN::do_read(struct can_frame &rec_frame, asio::posix::basic_stream_descriptor<> &stream)
|
||||
{
|
||||
auto sthis = shared_from_this();
|
||||
stream.async_read_some(
|
||||
asio::buffer(&rcv_frame, sizeof(rcv_frame)),
|
||||
[sthis](error_code error, size_t bytes_transferred) {
|
||||
if (error)
|
||||
{
|
||||
std::cerr << "read error in connection " << sthis->conn_id << " : "
|
||||
<< error.message().c_str() << std::endl;
|
||||
sthis->close();
|
||||
return;
|
||||
}
|
||||
|
||||
sthis->call_receive_callback(&sthis->rcv_frame);
|
||||
sthis->do_read(std::ref(sthis->rcv_frame), std::ref(sthis->stream));
|
||||
});
|
||||
}
|
||||
@@ -1,342 +0,0 @@
|
||||
/*
|
||||
* async_serial.cpp
|
||||
*
|
||||
* Created on: Nov 23, 2018 22:24
|
||||
* Description: asynchronous serial communication using asio
|
||||
* adapted from code in libmavconn
|
||||
*
|
||||
* Main changes: 1. Removed dependency on Boost (asio standalone
|
||||
* and C++ STL only)
|
||||
* 2. Removed dependency on console-bridge
|
||||
* 3. Removed mavlink related code
|
||||
* 4. Removed UDP/TCP related code
|
||||
*
|
||||
* Author: Vladimir Ermakov <vooon341@gmail.com>
|
||||
* Ruixiang Du <ruixiang.du@gmail.com>
|
||||
*/
|
||||
/*
|
||||
* libmavconn
|
||||
* Copyright 2013,2014,2015,2016 Vladimir Ermakov, All rights reserved.
|
||||
*
|
||||
* This file is part of the mavros package and subject to the license terms
|
||||
* in the top-level LICENSE file of the mavros repository.
|
||||
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "async_io/async_serial.hpp"
|
||||
#include "asyncio_utils.hpp"
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <linux/serial.h>
|
||||
#endif
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
using asio::buffer;
|
||||
using asio::io_service;
|
||||
using std::error_code;
|
||||
|
||||
std::atomic<size_t> ASyncSerial::conn_id_counter{0};
|
||||
|
||||
ASyncSerial::ASyncSerial(std::string device, unsigned baudrate, bool hwflow) : device_(device),
|
||||
baudrate_(baudrate),
|
||||
hwflow_(hwflow), tx_total_bytes(0),
|
||||
rx_total_bytes(0),
|
||||
last_tx_total_bytes(0),
|
||||
last_rx_total_bytes(0),
|
||||
last_iostat(steady_clock::now()),
|
||||
tx_in_progress(false),
|
||||
tx_q{},
|
||||
rx_buf{},
|
||||
io_service(),
|
||||
serial_dev_(io_service)
|
||||
{
|
||||
conn_id = conn_id_counter.fetch_add(1);
|
||||
}
|
||||
|
||||
ASyncSerial::~ASyncSerial()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void ASyncSerial::open(std::string device, unsigned baudrate, bool hwflow)
|
||||
{
|
||||
using SPB = asio::serial_port_base;
|
||||
|
||||
if (device != "")
|
||||
{
|
||||
device_ = device;
|
||||
baudrate_ = baudrate;
|
||||
hwflow_ = hwflow;
|
||||
}
|
||||
|
||||
std::cout << "connection: " << conn_id << " , device: " << device_ << " @ " << baudrate_ << "bps" << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
serial_dev_.open(device_);
|
||||
|
||||
// Set baudrate and 8N1 mode
|
||||
serial_dev_.set_option(SPB::baud_rate(baudrate_));
|
||||
serial_dev_.set_option(SPB::character_size(8));
|
||||
serial_dev_.set_option(SPB::parity(SPB::parity::none));
|
||||
serial_dev_.set_option(SPB::stop_bits(SPB::stop_bits::one));
|
||||
serial_dev_.set_option(SPB::flow_control((hwflow_) ? SPB::flow_control::hardware : SPB::flow_control::none));
|
||||
|
||||
#if defined(__linux__)
|
||||
// Enable low latency mode on Linux
|
||||
{
|
||||
int fd = serial_dev_.native_handle();
|
||||
|
||||
struct serial_struct ser_info;
|
||||
ioctl(fd, TIOCGSERIAL, &ser_info);
|
||||
|
||||
ser_info.flags |= ASYNC_LOW_LATENCY;
|
||||
|
||||
ioctl(fd, TIOCSSERIAL, &ser_info);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (std::system_error &err)
|
||||
{
|
||||
throw DeviceError("serial", err);
|
||||
}
|
||||
|
||||
// NOTE: shared_from_this() should not be used in constructors
|
||||
|
||||
// TODO is the following step necessary?
|
||||
// give some work to io_service before start
|
||||
io_service.post(std::bind(&ASyncSerial::do_read, this));
|
||||
|
||||
// run io_service for async io
|
||||
io_thread = std::thread([this]() {
|
||||
set_this_thread_name("mserial%zu", conn_id);
|
||||
io_service.run();
|
||||
});
|
||||
}
|
||||
|
||||
void ASyncSerial::close()
|
||||
{
|
||||
lock_guard lock(mutex);
|
||||
if (!is_open())
|
||||
return;
|
||||
|
||||
serial_dev_.cancel();
|
||||
serial_dev_.close();
|
||||
|
||||
io_service.stop();
|
||||
|
||||
if (io_thread.joinable())
|
||||
io_thread.join();
|
||||
|
||||
io_service.reset();
|
||||
|
||||
if (port_closed_cb)
|
||||
port_closed_cb();
|
||||
}
|
||||
|
||||
ASyncSerial::IOStat ASyncSerial::get_iostat()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(iostat_mutex);
|
||||
IOStat stat;
|
||||
|
||||
stat.tx_total_bytes = tx_total_bytes;
|
||||
stat.rx_total_bytes = rx_total_bytes;
|
||||
|
||||
auto d_tx = stat.tx_total_bytes - last_tx_total_bytes;
|
||||
auto d_rx = stat.rx_total_bytes - last_rx_total_bytes;
|
||||
last_tx_total_bytes = stat.tx_total_bytes;
|
||||
last_rx_total_bytes = stat.rx_total_bytes;
|
||||
|
||||
auto now = steady_clock::now();
|
||||
auto dt = now - last_iostat;
|
||||
last_iostat = now;
|
||||
|
||||
float dt_s = std::chrono::duration_cast<std::chrono::seconds>(dt).count();
|
||||
|
||||
stat.tx_speed = d_tx / dt_s;
|
||||
stat.rx_speed = d_rx / dt_s;
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
void ASyncSerial::iostat_tx_add(size_t bytes)
|
||||
{
|
||||
tx_total_bytes += bytes;
|
||||
}
|
||||
|
||||
void ASyncSerial::iostat_rx_add(size_t bytes)
|
||||
{
|
||||
rx_total_bytes += bytes;
|
||||
}
|
||||
|
||||
void ASyncSerial::send_bytes(const uint8_t *bytes, size_t length)
|
||||
{
|
||||
if (!is_open())
|
||||
{
|
||||
std::cerr << "send: channel closed! connection id: " << conn_id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
lock_guard lock(mutex);
|
||||
if (tx_q.size() >= MAX_TXQ_SIZE)
|
||||
throw std::length_error("ASyncSerial::send_bytes: TX queue overflow");
|
||||
tx_q.emplace_back(bytes, length);
|
||||
io_service.post(std::bind(&ASyncSerial::do_write, shared_from_this(), true));
|
||||
}
|
||||
|
||||
void ASyncSerial::call_receive_callback(uint8_t *buf, const std::size_t bufsize, std::size_t bytes_received)
|
||||
{
|
||||
assert(bufsize >= bytes_received);
|
||||
|
||||
// keep track of statistics
|
||||
iostat_rx_add(bytes_received);
|
||||
|
||||
// call the actual parser
|
||||
if (receive_cb)
|
||||
receive_cb(buf, bufsize, bytes_received);
|
||||
else
|
||||
default_receive_callback(buf, bufsize, bytes_received);
|
||||
}
|
||||
|
||||
void ASyncSerial::default_receive_callback(uint8_t *buf, const size_t bufsize, size_t bytes_received)
|
||||
{
|
||||
// do nothing
|
||||
std::cerr << "no callback function set" << std::endl;
|
||||
}
|
||||
|
||||
void ASyncSerial::do_read(void)
|
||||
{
|
||||
auto sthis = shared_from_this();
|
||||
serial_dev_.async_read_some(
|
||||
buffer(rx_buf),
|
||||
[sthis](error_code error, size_t bytes_transferred) {
|
||||
if (error)
|
||||
{
|
||||
std::cerr << "read error in connection " << sthis->conn_id << " : "
|
||||
<< error.message().c_str() << std::endl;
|
||||
sthis->close();
|
||||
return;
|
||||
}
|
||||
|
||||
sthis->call_receive_callback(sthis->rx_buf.data(), sthis->rx_buf.size(), bytes_transferred);
|
||||
sthis->do_read();
|
||||
});
|
||||
|
||||
// std::cout << rx_buf.data() << std::endl;
|
||||
}
|
||||
|
||||
void ASyncSerial::do_write(bool check_tx_state)
|
||||
{
|
||||
if (check_tx_state && tx_in_progress)
|
||||
return;
|
||||
|
||||
lock_guard lock(mutex);
|
||||
if (tx_q.empty())
|
||||
return;
|
||||
|
||||
tx_in_progress = true;
|
||||
auto sthis = shared_from_this();
|
||||
auto &buf_ref = tx_q.front();
|
||||
serial_dev_.async_write_some(
|
||||
buffer(buf_ref.dpos(), buf_ref.nbytes()),
|
||||
[sthis, &buf_ref](error_code error, size_t bytes_transferred) {
|
||||
assert(bytes_transferred <= buf_ref.len);
|
||||
|
||||
if (error)
|
||||
{
|
||||
std::cerr << "write error in connection " << sthis->conn_id << " : "
|
||||
<< error.message().c_str() << std::endl;
|
||||
sthis->close();
|
||||
return;
|
||||
}
|
||||
|
||||
sthis->iostat_tx_add(bytes_transferred);
|
||||
lock_guard lock(sthis->mutex);
|
||||
|
||||
if (sthis->tx_q.empty())
|
||||
{
|
||||
sthis->tx_in_progress = false;
|
||||
return;
|
||||
}
|
||||
|
||||
buf_ref.pos += bytes_transferred;
|
||||
if (buf_ref.nbytes() == 0)
|
||||
sthis->tx_q.pop_front();
|
||||
|
||||
if (!sthis->tx_q.empty())
|
||||
sthis->do_write(false);
|
||||
else
|
||||
sthis->tx_in_progress = false;
|
||||
});
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------//
|
||||
|
||||
namespace
|
||||
{
|
||||
ASyncSerial::Ptr url_parse_serial(
|
||||
std::string path, std::string query, bool hwflow)
|
||||
{
|
||||
std::string file_path;
|
||||
int baudrate;
|
||||
|
||||
url_parse_host(path, file_path, baudrate, ASyncSerial::DEFAULT_DEVICE, ASyncSerial::DEFAULT_BAUDRATE);
|
||||
url_parse_query(query);
|
||||
|
||||
return std::make_shared<ASyncSerial>(file_path, baudrate, hwflow);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ASyncSerial::Ptr ASyncSerial::open_url(std::string url)
|
||||
{
|
||||
/* Based on code found here:
|
||||
* http://stackoverflow.com/questions/2616011/easy-way-to-parse-a-url-in-c-cross-platform
|
||||
*/
|
||||
|
||||
const std::string proto_end("://");
|
||||
std::string proto;
|
||||
std::string host;
|
||||
std::string path;
|
||||
std::string query;
|
||||
|
||||
auto proto_it = std::search(
|
||||
url.begin(), url.end(),
|
||||
proto_end.begin(), proto_end.end());
|
||||
if (proto_it == url.end())
|
||||
{
|
||||
// looks like file path
|
||||
std::cout << "URL: " << url.c_str() << " looks like file path" << std::endl;
|
||||
return url_parse_serial(url, "", false);
|
||||
}
|
||||
|
||||
// copy protocol
|
||||
proto.reserve(std::distance(url.begin(), proto_it));
|
||||
std::transform(url.begin(), proto_it,
|
||||
std::back_inserter(proto),
|
||||
std::ref(tolower));
|
||||
|
||||
// copy host
|
||||
std::advance(proto_it, proto_end.length());
|
||||
auto path_it = std::find(proto_it, url.end(), '/');
|
||||
std::transform(proto_it, path_it,
|
||||
std::back_inserter(host),
|
||||
std::ref(tolower));
|
||||
|
||||
// copy path, and query if exists
|
||||
auto query_it = std::find(path_it, url.end(), '?');
|
||||
path.assign(path_it, query_it);
|
||||
if (query_it != url.end())
|
||||
++query_it;
|
||||
query.assign(query_it, url.end());
|
||||
|
||||
if (proto == "serial")
|
||||
return url_parse_serial(path, query, false);
|
||||
else if (proto == "serial-hwfc")
|
||||
return url_parse_serial(path, query, true);
|
||||
else
|
||||
throw DeviceError("url", "Unknown URL type");
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* asyncio_utils.cpp
|
||||
*
|
||||
* Created on: Jul 24, 2019 01:46
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#include "asyncio_utils.hpp"
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
void url_parse_host(std::string host,
|
||||
std::string &host_out, int &port_out,
|
||||
const std::string def_host, const int def_port)
|
||||
{
|
||||
std::string port;
|
||||
|
||||
auto sep_it = std::find(host.begin(), host.end(), ':');
|
||||
if (sep_it == host.end())
|
||||
{
|
||||
// host
|
||||
if (!host.empty())
|
||||
{
|
||||
host_out = host;
|
||||
port_out = def_port;
|
||||
}
|
||||
else
|
||||
{
|
||||
host_out = def_host;
|
||||
port_out = def_port;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (sep_it == host.begin())
|
||||
{
|
||||
// :port
|
||||
host_out = def_host;
|
||||
}
|
||||
else
|
||||
{
|
||||
// host:port
|
||||
host_out.assign(host.begin(), sep_it);
|
||||
}
|
||||
|
||||
port.assign(sep_it + 1, host.end());
|
||||
port_out = std::stoi(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse ?ids=sid,cid
|
||||
*/
|
||||
void url_parse_query(std::string query)
|
||||
{
|
||||
const std::string ids_end("ids=");
|
||||
std::string sys, comp;
|
||||
|
||||
if (query.empty())
|
||||
return;
|
||||
|
||||
auto ids_it = std::search(query.begin(), query.end(),
|
||||
ids_end.begin(), ids_end.end());
|
||||
if (ids_it == query.end())
|
||||
{
|
||||
std::cerr << "URL: unknown query arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::advance(ids_it, ids_end.length());
|
||||
auto comma_it = std::find(ids_it, query.end(), ',');
|
||||
if (comma_it == query.end())
|
||||
{
|
||||
std::cerr << "URL: no comma in ids= query" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
sys.assign(ids_it, comma_it);
|
||||
comp.assign(comma_it + 1, query.end());
|
||||
}
|
||||
} // namespace wescore
|
||||
@@ -1,63 +0,0 @@
|
||||
/**
|
||||
* @brief MAVConn async serial utility class
|
||||
* @file async_utils.hpp
|
||||
* @author Vladimir Ermakov <vooon341@gmail.com>
|
||||
*/
|
||||
/*
|
||||
* libmavconn
|
||||
* Copyright 2013,2014,2015,2016 Vladimir Ermakov, All rights reserved.
|
||||
*
|
||||
* This file is part of the mavros package and subject to the license terms
|
||||
* in the top-level LICENSE file of the mavros repository.
|
||||
* https://github.com/mavlink/mavros/tree/master/LICENSE.md
|
||||
*/
|
||||
|
||||
#ifndef ASYNCIO_UTILS_HPP
|
||||
#define ASYNCIO_UTILS_HPP
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
template <typename... Args>
|
||||
std::string format(const std::string &fmt, Args... args)
|
||||
{
|
||||
// C++11 specify that string store elements continously
|
||||
std::string ret;
|
||||
|
||||
auto sz = std::snprintf(nullptr, 0, fmt.c_str(), args...);
|
||||
ret.reserve(sz + 1);
|
||||
ret.resize(sz); // to be sure there have room for \0
|
||||
std::snprintf(&ret.front(), ret.capacity() + 1, fmt.c_str(), args...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
bool set_this_thread_name(const std::string &name, Args &&... args)
|
||||
{
|
||||
auto new_name = format(name, std::forward<Args>(args)...);
|
||||
|
||||
#ifdef __APPLE__
|
||||
return pthread_setname_np(new_name.c_str()) == 0;
|
||||
#else
|
||||
pthread_t pth = pthread_self();
|
||||
return pthread_setname_np(pth, new_name.c_str()) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse host:port pairs
|
||||
*/
|
||||
void url_parse_host(std::string host,
|
||||
std::string &host_out, int &port_out,
|
||||
const std::string def_host, const int def_port);
|
||||
|
||||
/**
|
||||
* Parse ?ids=sid,cid
|
||||
*/
|
||||
void url_parse_query(std::string query);
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* ASYNCIO_UTILS_HPP */
|
||||
@@ -1,12 +0,0 @@
|
||||
# Add executables
|
||||
add_executable(test_aserial test_aserial.cpp)
|
||||
target_link_libraries(test_aserial asyncio)
|
||||
|
||||
add_executable(test_aserial_comm test_aserial_comm.cpp)
|
||||
target_link_libraries(test_aserial_comm asyncio)
|
||||
|
||||
add_executable(test_asio_can test_asio_can.cpp)
|
||||
target_link_libraries(test_asio_can asio pthread)
|
||||
|
||||
add_executable(test_acan test_acan.cpp)
|
||||
target_link_libraries(test_acan asyncio)
|
||||
@@ -1,60 +0,0 @@
|
||||
#include <iostream>
|
||||
#include "async_io/async_can.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
void parse_buffer(uint8_t *buf, const size_t bufsize, size_t bytes_received)
|
||||
{
|
||||
std::cout << "parser called" << std::endl;
|
||||
|
||||
// mavlink::mavlink_status_t status;
|
||||
// mavlink::mavlink_message_t message;
|
||||
|
||||
for (; bytes_received > 0; bytes_received--)
|
||||
{
|
||||
auto c = *buf++;
|
||||
|
||||
// // based on mavlink_parse_char()
|
||||
// auto msg_received = static_cast<Framing>(mavlink::mavlink_frame_char_buffer(&m_buffer, &m_status, c, &message, &status));
|
||||
// if (msg_received == Framing::bad_crc || msg_received == Framing::bad_signature) {
|
||||
// mavlink::_mav_parse_error(&m_status);
|
||||
// m_status.msg_received = mavlink::MAVLINK_FRAMING_INCOMPLETE;
|
||||
// m_status.parse_state = mavlink::MAVLINK_PARSE_STATE_IDLE;
|
||||
// if (c == MAVLINK_STX) {
|
||||
// m_status.parse_state = mavlink::MAVLINK_PARSE_STATE_GOT_STX;
|
||||
// m_buffer.len = 0;
|
||||
// mavlink::mavlink_start_checksum(&m_buffer);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (msg_received != Framing::incomplete) {
|
||||
// log_recv(pfx, message, msg_received);
|
||||
|
||||
// if (message_received_cb)
|
||||
// message_received_cb(&message, msg_received);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::shared_ptr<ASyncCAN> canbus = std::make_shared<ASyncCAN>("can1");
|
||||
|
||||
// canbus->set_receive_callback(parse_buffer);
|
||||
|
||||
// if (canbus->is_open())
|
||||
// std::cout << "can bus connected" << std::endl;
|
||||
|
||||
struct can_frame frame;
|
||||
frame.can_id = 0x123;
|
||||
frame.can_dlc = 2;
|
||||
frame.data[0] = 0x11;
|
||||
frame.data[1] = 0x23;
|
||||
|
||||
while (1)
|
||||
{
|
||||
// canbus->send_bytes(data, 3);
|
||||
canbus->send_frame(frame);
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* test_interface.cpp
|
||||
*
|
||||
* Created on: Dec 25, 2016
|
||||
* Author: rdu
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "async_io/async_serial.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
void parse_buffer(uint8_t *buf, const size_t bufsize, size_t bytes_received)
|
||||
{
|
||||
std::cout << "parser called" << std::endl;
|
||||
|
||||
for (; bytes_received > 0; bytes_received--)
|
||||
{
|
||||
auto c = *buf++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// ASyncSerial::Ptr serial = ASyncSerial::open_url("/dev/ttyUSB0:115200");
|
||||
std::shared_ptr<ASyncSerial> serial = std::make_shared<ASyncSerial>("/dev/ttyO5", 115200);
|
||||
|
||||
serial->set_receive_callback(parse_buffer);
|
||||
|
||||
if (serial->is_open())
|
||||
std::cout << "serial port opened" << std::endl;
|
||||
|
||||
uint8_t data[8] = {'a','b','c'};
|
||||
|
||||
while (1)
|
||||
{
|
||||
// serial->send_bytes(data, 3);
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* test_interface.cpp
|
||||
*
|
||||
* Created on: Dec 25, 2016
|
||||
* Author: rdu
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "async_io/async_serial.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
void parse_buffer(uint8_t *buf, const size_t bufsize, size_t bytes_received)
|
||||
{
|
||||
// std::cout << "parser called" << std::endl;
|
||||
|
||||
// for (int i = 0; i < bytes_received; ++i)
|
||||
// {
|
||||
// // auto c = *buf++;
|
||||
// std::cout << std::hex << static_cast<int>(buf[i]) << std::dec << " ";
|
||||
// }
|
||||
|
||||
if (bytes_received > 2)
|
||||
{
|
||||
for (int i = 0; i < bytes_received - 1; ++i)
|
||||
{
|
||||
uint8_t first = buf[i];
|
||||
uint8_t second = buf[i + 1];
|
||||
|
||||
if (first == 0xB5 && second == 0x62)
|
||||
std::cout << "- start bytes found" << std::endl;
|
||||
// std::cout << std::hex << static_cast<int>(buf[i]) << std::dec << " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::string device_name;
|
||||
int baud;
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
device_name = {argv[1]};
|
||||
baud = std::stoi(argv[2]);
|
||||
std::cout << "Specified device: " << device_name << ", baud: " << baud << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Usage: test_aserial_comm <interface> <baud>" << std::endl
|
||||
<< "Example: ./test_aserial_comm /dev/ttyUSB0 115200" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::shared_ptr<ASyncSerial> serial = std::make_shared<ASyncSerial>(device_name, baud);
|
||||
|
||||
serial->set_receive_callback(parse_buffer);
|
||||
|
||||
if (serial->is_open())
|
||||
std::cout << "serial port opened" << std::endl;
|
||||
|
||||
uint8_t data[8] = {'a', 'b', 'c'};
|
||||
|
||||
int count = 0;
|
||||
uint8_t idx = 0;
|
||||
const unsigned baudrates[] = {9600, 57600, 115200};
|
||||
while (1)
|
||||
{
|
||||
// serial->send_bytes(data, 3);
|
||||
if (++count == 15)
|
||||
{
|
||||
count = 0;
|
||||
std::cout << "----------------------------------------" << std::endl;
|
||||
std::cout << "change baud rate to " << baudrates[idx % 3] << std::endl;
|
||||
std::cout << "----------------------------------------" << std::endl;
|
||||
serial->set_baud(baudrates[idx % 3]);
|
||||
idx++;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
// source: https://stackoverflow.com/questions/10467178/boostasio-over-socketcan
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/raw.h>
|
||||
|
||||
#define ASIO_ENABLE_OLD_SERVICES
|
||||
#define ASIO_HAS_POSIX_STREAM_DESCRIPTOR
|
||||
|
||||
#include "asio.hpp"
|
||||
#include <functional>
|
||||
|
||||
#include "asio/posix/basic_stream_descriptor.hpp"
|
||||
|
||||
void data_send(void)
|
||||
{
|
||||
std::cout << "omg sent" << std::endl;
|
||||
}
|
||||
|
||||
void data_rec(struct can_frame &rec_frame,
|
||||
asio::posix::basic_stream_descriptor<> &stream)
|
||||
{
|
||||
std::cout << std::hex << rec_frame.can_id << " ";
|
||||
for (int i = 0; i < rec_frame.can_dlc; i++)
|
||||
{
|
||||
std::cout << std::hex << int(rec_frame.data[i]) << " ";
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
stream.async_read_some(
|
||||
asio::buffer(&rec_frame, sizeof(rec_frame)),
|
||||
std::bind(data_rec, std::ref(rec_frame), std::ref(stream)));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct sockaddr_can addr;
|
||||
struct can_frame frame;
|
||||
struct can_frame rec_frame;
|
||||
struct ifreq ifr;
|
||||
|
||||
int natsock = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
|
||||
strcpy(ifr.ifr_name, "can1");
|
||||
ioctl(natsock, SIOCGIFINDEX, &ifr);
|
||||
|
||||
addr.can_family = AF_CAN;
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
if (bind(natsock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
||||
{
|
||||
perror("Error in socket bind");
|
||||
return -2;
|
||||
}
|
||||
|
||||
frame.can_id = 0x123;
|
||||
frame.can_dlc = 2;
|
||||
frame.data[0] = 0x11;
|
||||
frame.data[1] = 0x23;
|
||||
|
||||
asio::io_service ios;
|
||||
asio::posix::basic_stream_descriptor<> stream(ios);
|
||||
stream.assign(natsock);
|
||||
|
||||
stream.async_write_some(asio::buffer(&frame, sizeof(frame)),
|
||||
std::bind(data_send));
|
||||
stream.async_read_some(
|
||||
asio::buffer(&rec_frame, sizeof(rec_frame)),
|
||||
std::bind(data_rec, std::ref(rec_frame), std::ref(stream)));
|
||||
ios.run();
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
## Add libraries
|
||||
set(SCOUT_PROTOCOL_SRC
|
||||
src/scout_can_parser.c
|
||||
src/scout_uart_parser.c
|
||||
)
|
||||
add_library(scout_protocol STATIC ${SCOUT_PROTOCOL_SRC})
|
||||
set_target_properties(scout_protocol PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
target_include_directories(scout_protocol PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<BUILD_INTERFACE:${Boost_INCLUDE_DIRS}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PRIVATE src)
|
||||
@@ -1,3 +0,0 @@
|
||||
## AgileX Protocol
|
||||
|
||||
This module is implemented in C, designed for exchanging information with AgileX mobile bases.
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* scout_can_parser.h
|
||||
*
|
||||
* Created on: Aug 31, 2019 04:23
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef SCOUT_CAN_PARSER_H
|
||||
#define SCOUT_CAN_PARSER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "scout_protocol/scout_protocol.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/can.h>
|
||||
#else
|
||||
struct can_frame
|
||||
{
|
||||
uint32_t can_id;
|
||||
uint8_t can_dlc;
|
||||
uint8_t data[8]__attribute__((aligned(8)));
|
||||
};
|
||||
#endif
|
||||
|
||||
bool DecodeScoutStatusMsgFromCAN(const struct can_frame *rx_frame, ScoutStatusMessage *msg);
|
||||
bool DecodeScoutControlMsgFromCAN(const struct can_frame *rx_frame, ScoutControlMessage *msg);
|
||||
|
||||
void EncodeScoutStatusMsgToCAN(const ScoutStatusMessage *msg, struct can_frame *tx_frame);
|
||||
void EncodeScoutControlMsgToCAN(const ScoutControlMessage *msg, struct can_frame *tx_frame);
|
||||
|
||||
void EncodeScoutMotionControlMsgToCAN(const MotionControlMessage *msg, struct can_frame *tx_frame);
|
||||
void EncodeScoutLightControlMsgToCAN(const LightControlMessage *msg, struct can_frame *tx_frame);
|
||||
|
||||
uint8_t CalcScoutCANChecksum(uint16_t id, uint8_t *data, uint8_t dlc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SCOUT_CAN_PARSER_H */
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
* scout_protocol.h
|
||||
*
|
||||
* Created on: Aug 07, 2019 21:49
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef SCOUT_PROTOCOL_H
|
||||
#define SCOUT_PROTOCOL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SCOUT_CMD_BUF_LEN 32
|
||||
#define SCOUT_STATUS_BUF_LEN 32
|
||||
#define SCOUT_FRAME_SIZE 13
|
||||
|
||||
#define SCOUT_MOTOR1_ID ((uint8_t)0x00)
|
||||
#define SCOUT_MOTOR2_ID ((uint8_t)0x01)
|
||||
#define SCOUT_MOTOR3_ID ((uint8_t)0x02)
|
||||
#define SCOUT_MOTOR4_ID ((uint8_t)0x03)
|
||||
|
||||
// UART Definitions
|
||||
#define UART_FRAME_SYSTEM_STATUS_ID ((uint8_t)0x01)
|
||||
#define UART_FRAME_MOTION_STATUS_ID ((uint8_t)0x02)
|
||||
#define UART_FRAME_MOTOR1_DRIVER_STATUS_ID ((uint8_t)0x03)
|
||||
#define UART_FRAME_MOTOR2_DRIVER_STATUS_ID ((uint8_t)0x04)
|
||||
#define UART_FRAME_MOTOR3_DRIVER_STATUS_ID ((uint8_t)0x05)
|
||||
#define UART_FRAME_MOTOR4_DRIVER_STATUS_ID ((uint8_t)0x06)
|
||||
#define UART_FRAME_LIGHT_STATUS_ID ((uint8_t)0x07)
|
||||
|
||||
#define UART_FRAME_MOTION_CONTROL_ID ((uint8_t)0x01)
|
||||
#define UART_FRAME_LIGHT_CONTROL_ID ((uint8_t)0x02)
|
||||
|
||||
// CAN Definitions
|
||||
#define CAN_MSG_MOTION_CONTROL_CMD_ID ((uint32_t)0x130)
|
||||
#define CAN_MSG_MOTION_CONTROL_STATUS_ID ((uint32_t)0x131)
|
||||
#define CAN_MSG_LIGHT_CONTROL_CMD_ID ((uint32_t)0x140)
|
||||
#define CAN_MSG_LIGHT_CONTROL_STATUS_ID ((uint32_t)0x141)
|
||||
#define CAN_MSG_SYSTEM_STATUS_STATUS_ID ((uint32_t)0x151)
|
||||
#define CAN_MSG_MOTOR1_DRIVER_STATUS_ID ((uint32_t)0x200)
|
||||
#define CAN_MSG_MOTOR2_DRIVER_STATUS_ID ((uint32_t)0x201)
|
||||
#define CAN_MSG_MOTOR3_DRIVER_STATUS_ID ((uint32_t)0x202)
|
||||
#define CAN_MSG_MOTOR4_DRIVER_STATUS_ID ((uint32_t)0x203)
|
||||
|
||||
/*--------------------- Control/State Constants ------------------------*/
|
||||
|
||||
// Motion Control
|
||||
#define CTRL_MODE_REMOTE ((uint8_t)0x00)
|
||||
#define CTRL_MODE_CMD_CAN ((uint8_t)0x01)
|
||||
#define CTRL_MODE_CMD_UART ((uint8_t)0x02)
|
||||
#define CTRL_MODE_COMMANDED ((uint8_t)0x03)
|
||||
|
||||
#define FAULT_CLR_NONE ((uint8_t)0x00)
|
||||
#define FAULT_CLR_BAT_UNDER_VOL ((uint8_t)0x01)
|
||||
#define FAULT_CLR_BAT_OVER_VOL ((uint8_t)0x02)
|
||||
#define FAULT_CLR_MOTOR1_COMM ((uint8_t)0x03)
|
||||
#define FAULT_CLR_MOTOR2_COMM ((uint8_t)0x04)
|
||||
#define FAULT_CLR_MOTOR3_COMM ((uint8_t)0x05)
|
||||
#define FAULT_CLR_MOTOR4_COMM ((uint8_t)0x06)
|
||||
#define FAULT_CLR_MOTOR_DRV_OVERHEAT ((uint8_t)0x07)
|
||||
#define FAULT_CLR_MOTOR_OVERCURRENT ((uint8_t)0x08)
|
||||
|
||||
// Light Control
|
||||
#define LIGHT_DISABLE_CTRL ((uint8_t)0x00)
|
||||
#define LIGHT_ENABLE_CTRL ((uint8_t)0x01)
|
||||
|
||||
#define LIGHT_MODE_CONST_OFF ((uint8_t)0x00)
|
||||
#define LIGHT_MODE_CONST_ON ((uint8_t)0x01)
|
||||
#define LIGHT_MODE_BREATH ((uint8_t)0x02)
|
||||
#define LIGHT_MODE_CUSTOM ((uint8_t)0x03)
|
||||
|
||||
// System Status Feedback
|
||||
#define BASE_STATE_NORMAL ((uint8_t)0x00)
|
||||
#define BASE_STATE_ESTOP ((uint8_t)0x01)
|
||||
#define BASE_STATE_EXCEPTION ((uint8_t)0x02)
|
||||
|
||||
#define FAULT_CAN_CHECKSUM_ERROR ((uint16_t)0x0100)
|
||||
#define FAULT_MOTOR_DRV_OVERHEAT_W ((uint16_t)0x0200)
|
||||
#define FAULT_MOTOR_OVERCURRENT_W ((uint16_t)0x0400)
|
||||
#define FAULT_BAT_UNDER_VOL_W ((uint16_t)0x0800)
|
||||
#define FAULT_HIGH_BYTE_RESERVED1 ((uint16_t)0x1000)
|
||||
#define FAULT_HIGH_BYTE_RESERVED2 ((uint16_t)0x2000)
|
||||
#define FAULT_HIGH_BYTE_RESERVED3 ((uint16_t)0x4000)
|
||||
#define FAULT_HIGH_BYTE_RESERVED4 ((uint16_t)0x8000)
|
||||
|
||||
#define FAULT_BAT_UNDER_VOL_F ((uint16_t)0x0001)
|
||||
#define FAULT_BAT_OVER_VOL_F ((uint16_t)0x0002)
|
||||
#define FAULT_MOTOR1_COMM_F ((uint16_t)0x0004)
|
||||
#define FAULT_MOTOR2_COMM_F ((uint16_t)0x0008)
|
||||
#define FAULT_MOTOR3_COMM_F ((uint16_t)0x0010)
|
||||
#define FAULT_MOTOR4_COMM_F ((uint16_t)0x0020)
|
||||
#define FAULT_MOTOR_DRV_OVERHEAT_F ((uint16_t)0x0040)
|
||||
#define FAULT_MOTOR_OVERCURRENT_F ((uint16_t)0x0080)
|
||||
|
||||
/*-------------------- Control/Feedback Messages -----------------------*/
|
||||
|
||||
/* No padding in the struct */
|
||||
// reference: https://stackoverflow.com/questions/3318410/pragma-pack-effect
|
||||
#pragma pack(push, 1)
|
||||
|
||||
// Note: id could be different for UART and CAN protocol
|
||||
|
||||
// Motion Control
|
||||
typedef struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t control_mode;
|
||||
uint8_t fault_clear_flag;
|
||||
int8_t linear_velocity_cmd;
|
||||
int8_t angular_velocity_cmd;
|
||||
uint8_t reserved0;
|
||||
uint8_t reserved1;
|
||||
uint8_t count;
|
||||
uint8_t checksum;
|
||||
} cmd;
|
||||
uint8_t raw[8];
|
||||
} data;
|
||||
} MotionControlMessage;
|
||||
|
||||
typedef struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t high_byte;
|
||||
uint8_t low_byte;
|
||||
} linear_velocity;
|
||||
struct
|
||||
{
|
||||
uint8_t high_byte;
|
||||
uint8_t low_byte;
|
||||
} angular_velocity;
|
||||
uint8_t reserved0;
|
||||
uint8_t reserved1;
|
||||
uint8_t count;
|
||||
uint8_t checksum;
|
||||
} status;
|
||||
uint8_t raw[8];
|
||||
} data;
|
||||
} MotionStatusMessage;
|
||||
|
||||
// System Status Feedback
|
||||
typedef struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t base_state;
|
||||
uint8_t control_mode;
|
||||
struct
|
||||
{
|
||||
uint8_t high_byte;
|
||||
uint8_t low_byte;
|
||||
} battery_voltage;
|
||||
struct
|
||||
{
|
||||
uint8_t high_byte;
|
||||
uint8_t low_byte;
|
||||
} fault_code;
|
||||
uint8_t count;
|
||||
uint8_t checksum;
|
||||
} status;
|
||||
uint8_t raw[8];
|
||||
} data;
|
||||
} SystemStatusMessage;
|
||||
|
||||
// Light Control
|
||||
typedef struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t light_ctrl_enable;
|
||||
uint8_t front_light_mode;
|
||||
uint8_t front_light_custom;
|
||||
uint8_t rear_light_mode;
|
||||
uint8_t rear_light_custom;
|
||||
uint8_t reserved0;
|
||||
uint8_t count;
|
||||
uint8_t checksum;
|
||||
} cmd;
|
||||
uint8_t raw[8];
|
||||
} data;
|
||||
} LightControlMessage;
|
||||
|
||||
typedef struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t light_ctrl_enable;
|
||||
uint8_t front_light_mode;
|
||||
uint8_t front_light_custom;
|
||||
uint8_t rear_light_mode;
|
||||
uint8_t rear_light_custom;
|
||||
uint8_t reserved0;
|
||||
uint8_t count;
|
||||
uint8_t checksum;
|
||||
} status;
|
||||
uint8_t raw[8];
|
||||
} data;
|
||||
} LightStatusMessage;
|
||||
|
||||
// Motor Driver Feedback
|
||||
typedef struct
|
||||
{
|
||||
uint8_t motor_id;
|
||||
union {
|
||||
struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t high_byte;
|
||||
uint8_t low_byte;
|
||||
} current;
|
||||
struct
|
||||
{
|
||||
uint8_t high_byte;
|
||||
uint8_t low_byte;
|
||||
} rpm;
|
||||
int8_t temperature;
|
||||
uint8_t reserved0;
|
||||
uint8_t count;
|
||||
uint8_t checksum;
|
||||
} status;
|
||||
uint8_t raw[8];
|
||||
} data;
|
||||
} MotorDriverStatusMessage;
|
||||
|
||||
// For convenience to access status/control message
|
||||
typedef enum
|
||||
{
|
||||
ScoutStatusNone = 0x00,
|
||||
ScoutMotionStatusMsg = 0x01,
|
||||
ScoutLightStatusMsg = 0x02,
|
||||
ScoutSystemStatusMsg = 0x03,
|
||||
ScoutMotorDriverStatusMsg = 0x04
|
||||
} ScoutStatusMsgType;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ScoutStatusMsgType msg_type;
|
||||
|
||||
// only one of the following fields is updated, as specified by msg_type
|
||||
MotionStatusMessage motion_status_msg;
|
||||
LightStatusMessage light_status_msg;
|
||||
SystemStatusMessage system_status_msg;
|
||||
MotorDriverStatusMessage motor_driver_status_msg;
|
||||
} ScoutStatusMessage;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ScoutControlNone = 0x20,
|
||||
ScoutMotionControlMsg = 0x21,
|
||||
ScoutLightControlMsg = 0x22
|
||||
} ScoutControlMsgType;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ScoutControlMsgType msg_type;
|
||||
|
||||
// only one of the following fields is updated, as specified by msg_type
|
||||
MotionControlMessage motion_control_msg;
|
||||
LightControlMessage light_control_msg;
|
||||
} ScoutControlMessage;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SCOUT_PROTOCOL_H */
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* scout_uart_parser.h
|
||||
*
|
||||
* Created on: Aug 14, 2019 12:01
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef SCOUT_UART_PARSER_H
|
||||
#define SCOUT_UART_PARSER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "scout_protocol/scout_protocol.h"
|
||||
|
||||
bool DecodeScoutStatusMsgFromUART(uint8_t c, ScoutStatusMessage *msg);
|
||||
bool DecodeScoutControlMsgFromUART(uint8_t c, ScoutControlMessage *msg);
|
||||
|
||||
void EncodeScoutStatusMsgToUART(const ScoutStatusMessage *msg, uint8_t *buf, uint8_t *len);
|
||||
void EncodeScoutControlMsgToUART(const ScoutControlMessage *msg, uint8_t *buf, uint8_t *len);
|
||||
|
||||
void EncodeMotionControlMsgToUART(const MotionControlMessage *msg, uint8_t *buf, uint8_t *len);
|
||||
void EncodeLightControlMsgToUART(const LightControlMessage *msg, uint8_t *buf, uint8_t *len);
|
||||
|
||||
uint8_t CalcScoutUARTChecksum(uint8_t *buf, uint8_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SCOUT_UART_PARSER_H */
|
||||
@@ -1,197 +0,0 @@
|
||||
/*
|
||||
* scout_can_parser.c
|
||||
*
|
||||
* Created on: Aug 31, 2019 04:25
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#include "scout_protocol/scout_can_parser.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
bool DecodeScoutStatusMsgFromCAN(const struct can_frame *rx_frame, ScoutStatusMessage *msg)
|
||||
{
|
||||
msg->msg_type = ScoutStatusNone;
|
||||
|
||||
switch (rx_frame->can_id)
|
||||
{
|
||||
// in the current implementation, both MsgType and can_frame include 8 * uint8_t
|
||||
case CAN_MSG_MOTION_CONTROL_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotionStatusMsg;
|
||||
// msg->motion_status_msg.id = CAN_MSG_MOTION_CONTROL_STATUS_ID;
|
||||
memcpy(msg->motion_status_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
case CAN_MSG_LIGHT_CONTROL_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutLightStatusMsg;
|
||||
// msg->light_status_msg.id = CAN_MSG_LIGHT_CONTROL_STATUS_ID;
|
||||
memcpy(msg->light_status_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
case CAN_MSG_SYSTEM_STATUS_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutSystemStatusMsg;
|
||||
// msg->system_status_msg.id = CAN_MSG_SYSTEM_STATUS_STATUS_ID;
|
||||
memcpy(msg->system_status_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
case CAN_MSG_MOTOR1_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
// msg->motor_driver_status_msg.id = CAN_MSG_MOTOR1_DRIVER_STATUS_ID;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR1_ID;
|
||||
memcpy(msg->motor_driver_status_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
case CAN_MSG_MOTOR2_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
// msg->motor_driver_status_msg.id = CAN_MSG_MOTOR2_DRIVER_STATUS_ID;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR2_ID;
|
||||
memcpy(msg->motor_driver_status_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
case CAN_MSG_MOTOR3_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
// msg->motor_driver_status_msg.id = CAN_MSG_MOTOR3_DRIVER_STATUS_ID;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR3_ID;
|
||||
memcpy(msg->motor_driver_status_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
case CAN_MSG_MOTOR4_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
// msg->motor_driver_status_msg.id = CAN_MSG_MOTOR4_DRIVER_STATUS_ID;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR4_ID;
|
||||
memcpy(msg->motor_driver_status_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DecodeScoutControlMsgFromCAN(const struct can_frame *rx_frame, ScoutControlMessage *msg)
|
||||
{
|
||||
msg->msg_type = ScoutControlNone;
|
||||
|
||||
switch (rx_frame->can_id)
|
||||
{
|
||||
// in the current implementation, both MsgType and can_frame include 8 * uint8_t
|
||||
case CAN_MSG_MOTION_CONTROL_CMD_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotionControlMsg;
|
||||
// msg->motion_control_msg.id = CAN_MSG_MOTION_CONTROL_CMD_ID;
|
||||
memcpy(msg->motion_control_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
case CAN_MSG_LIGHT_CONTROL_CMD_ID:
|
||||
{
|
||||
msg->msg_type = ScoutLightControlMsg;
|
||||
// msg->light_control_msg.id = CAN_MSG_LIGHT_CONTROL_STATUS_ID;
|
||||
memcpy(msg->light_control_msg.data.raw, rx_frame->data, rx_frame->can_dlc * sizeof(uint8_t));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EncodeScoutStatusMsgToCAN(const ScoutStatusMessage *msg, struct can_frame *tx_frame)
|
||||
{
|
||||
switch (msg->msg_type)
|
||||
{
|
||||
// in the current implementation, both MsgType and can_frame include 8 * uint8_t
|
||||
case ScoutMotionStatusMsg:
|
||||
{
|
||||
tx_frame->can_id = CAN_MSG_MOTION_CONTROL_STATUS_ID;
|
||||
tx_frame->can_dlc = 8;
|
||||
memcpy(tx_frame->data, msg->motion_status_msg.data.raw, tx_frame->can_dlc);
|
||||
break;
|
||||
}
|
||||
case ScoutLightStatusMsg:
|
||||
{
|
||||
tx_frame->can_id = CAN_MSG_LIGHT_CONTROL_STATUS_ID;
|
||||
tx_frame->can_dlc = 8;
|
||||
memcpy(tx_frame->data, msg->light_status_msg.data.raw, tx_frame->can_dlc);
|
||||
break;
|
||||
}
|
||||
case ScoutSystemStatusMsg:
|
||||
{
|
||||
tx_frame->can_id = CAN_MSG_SYSTEM_STATUS_STATUS_ID;
|
||||
tx_frame->can_dlc = 8;
|
||||
memcpy(tx_frame->data, msg->system_status_msg.data.raw, tx_frame->can_dlc);
|
||||
break;
|
||||
}
|
||||
case ScoutMotorDriverStatusMsg:
|
||||
{
|
||||
if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR1_ID)
|
||||
tx_frame->can_id = CAN_MSG_MOTOR1_DRIVER_STATUS_ID;
|
||||
else if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR2_ID)
|
||||
tx_frame->can_id = CAN_MSG_MOTOR2_DRIVER_STATUS_ID;
|
||||
else if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR3_ID)
|
||||
tx_frame->can_id = CAN_MSG_MOTOR3_DRIVER_STATUS_ID;
|
||||
else if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR4_ID)
|
||||
tx_frame->can_id = CAN_MSG_MOTOR4_DRIVER_STATUS_ID;
|
||||
tx_frame->can_dlc = 8;
|
||||
memcpy(tx_frame->data, msg->motor_driver_status_msg.data.raw, tx_frame->can_dlc);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
tx_frame->data[7] = CalcScoutCANChecksum(tx_frame->can_id, tx_frame->data, tx_frame->can_dlc);
|
||||
}
|
||||
|
||||
void EncodeScoutControlMsgToCAN(const ScoutControlMessage *msg, struct can_frame *tx_frame)
|
||||
{
|
||||
switch (msg->msg_type)
|
||||
{
|
||||
case ScoutMotionControlMsg:
|
||||
{
|
||||
EncodeScoutMotionControlMsgToCAN(&(msg->motion_control_msg), tx_frame);
|
||||
break;
|
||||
}
|
||||
case ScoutLightControlMsg:
|
||||
{
|
||||
EncodeScoutLightControlMsgToCAN(&(msg->light_control_msg), tx_frame);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EncodeScoutMotionControlMsgToCAN(const MotionControlMessage *msg, struct can_frame *tx_frame)
|
||||
{
|
||||
tx_frame->can_id = CAN_MSG_MOTION_CONTROL_CMD_ID;
|
||||
tx_frame->can_dlc = 8;
|
||||
memcpy(tx_frame->data, msg->data.raw, tx_frame->can_dlc);
|
||||
tx_frame->data[7] = CalcScoutCANChecksum(tx_frame->can_id, tx_frame->data, tx_frame->can_dlc);
|
||||
}
|
||||
|
||||
void EncodeScoutLightControlMsgToCAN(const LightControlMessage *msg, struct can_frame *tx_frame)
|
||||
{
|
||||
tx_frame->can_id = CAN_MSG_LIGHT_CONTROL_CMD_ID;
|
||||
tx_frame->can_dlc = 8;
|
||||
memcpy(tx_frame->data, msg->data.raw, tx_frame->can_dlc);
|
||||
tx_frame->data[7] = CalcScoutCANChecksum(tx_frame->can_id, tx_frame->data, tx_frame->can_dlc);
|
||||
}
|
||||
|
||||
uint8_t CalcScoutCANChecksum(uint16_t id, uint8_t *data, uint8_t dlc)
|
||||
{
|
||||
uint8_t checksum = 0x00;
|
||||
checksum = (uint8_t)(id & 0x00ff) + (uint8_t)(id >> 8) + dlc;
|
||||
for (int i = 0; i < (dlc - 1); ++i)
|
||||
checksum += data[i];
|
||||
return checksum;
|
||||
}
|
||||
@@ -1,640 +0,0 @@
|
||||
/*
|
||||
* scout_uart_parser.c
|
||||
*
|
||||
* Created on: Aug 14, 2019 12:02
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#include "scout_protocol/scout_uart_parser.h"
|
||||
|
||||
// #define PRINT_CPP_DEBUG_INFO
|
||||
// #define PRINT_JLINK_DEBUG_INFO
|
||||
// #define USE_XOR_CHECKSUM
|
||||
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
#undef PRINT_JLINK_DEBUG_INFO
|
||||
#endif
|
||||
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
#define < iostream >
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
#include "segger/jlink_rtt.h"
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WAIT_FOR_SOF1 = 0,
|
||||
WAIT_FOR_SOF2,
|
||||
WAIT_FOR_FRAME_LEN,
|
||||
WAIT_FOR_FRAME_TYPE,
|
||||
WAIT_FOR_FRAME_ID,
|
||||
WAIT_FOR_PAYLOAD,
|
||||
WAIT_FOR_FRAME_COUNT,
|
||||
WAIT_FOR_CHECKSUM
|
||||
} ScoutSerialDecodeState;
|
||||
|
||||
#define PAYLOAD_BUFFER_SIZE (SCOUT_FRAME_SIZE * 2)
|
||||
|
||||
#define FRAME_SOF_LEN ((uint8_t)2)
|
||||
#define FRAME_FIXED_FIELD_LEN ((uint8_t)4)
|
||||
|
||||
#define FRAME_SOF1 ((uint8_t)0x5a)
|
||||
#define FRAME_SOF2 ((uint8_t)0xa5)
|
||||
|
||||
#define FRAME_TYPE_CONTROL ((uint8_t)0x55)
|
||||
#define FRAME_TYPE_STATUS ((uint8_t)0xaa)
|
||||
|
||||
#define FRAME_NONE_ID ((uint8_t)0x00)
|
||||
|
||||
typedef union {
|
||||
ScoutStatusMessage status_msg;
|
||||
ScoutControlMessage control_msg;
|
||||
} ScoutDecodedMessage;
|
||||
|
||||
// frame buffer
|
||||
static uint8_t frame_id = 0;
|
||||
static uint8_t frame_type = 0;
|
||||
static uint8_t frame_len = 0;
|
||||
static uint8_t frame_cnt = 0;
|
||||
static uint8_t frame_checksum = 0;
|
||||
static uint8_t internal_checksum = 0;
|
||||
static uint8_t payload_buffer[PAYLOAD_BUFFER_SIZE];
|
||||
static size_t payload_data_pos = 0;
|
||||
|
||||
// statisctics
|
||||
static uint32_t frame_parsed = 0;
|
||||
static uint32_t frame_with_wrong_checksum = 0;
|
||||
|
||||
static bool ParseChar(uint8_t c, ScoutDecodedMessage *msg);
|
||||
static uint8_t CalcBufferedFrameChecksum();
|
||||
static bool ConstructStatusMessage(ScoutStatusMessage *msg);
|
||||
static bool ConstructControlMessage(ScoutControlMessage *msg);
|
||||
|
||||
void EncodeScoutStatusMsgToUART(const ScoutStatusMessage *msg, uint8_t *buf, uint8_t *len)
|
||||
{
|
||||
// SOF
|
||||
buf[0] = FRAME_SOF1;
|
||||
buf[1] = FRAME_SOF2;
|
||||
|
||||
// frame len, type, ID
|
||||
buf[2] = 0x0a;
|
||||
buf[3] = FRAME_TYPE_STATUS;
|
||||
|
||||
switch (msg->msg_type)
|
||||
{
|
||||
// in the current implementation, both MsgType and can_frame include 8 * uint8_t
|
||||
case ScoutMotionStatusMsg:
|
||||
{
|
||||
buf[4] = UART_FRAME_MOTION_STATUS_ID;
|
||||
buf[5] = msg->motion_status_msg.data.status.linear_velocity.high_byte;
|
||||
buf[6] = msg->motion_status_msg.data.status.linear_velocity.low_byte;
|
||||
buf[7] = msg->motion_status_msg.data.status.angular_velocity.high_byte;
|
||||
buf[8] = msg->motion_status_msg.data.status.angular_velocity.low_byte;
|
||||
buf[9] = 0;
|
||||
buf[10] = 0;
|
||||
buf[11] = msg->motion_status_msg.data.status.count;
|
||||
break;
|
||||
}
|
||||
case ScoutLightStatusMsg:
|
||||
{
|
||||
buf[4] = UART_FRAME_LIGHT_STATUS_ID;
|
||||
buf[5] = msg->light_status_msg.data.status.light_ctrl_enable;
|
||||
buf[6] = msg->light_status_msg.data.status.front_light_mode;
|
||||
buf[7] = msg->light_status_msg.data.status.front_light_custom;
|
||||
buf[8] = msg->light_status_msg.data.status.rear_light_mode;
|
||||
buf[9] = msg->light_status_msg.data.status.rear_light_custom;
|
||||
buf[10] = 0;
|
||||
buf[11] = msg->light_status_msg.data.status.count;
|
||||
break;
|
||||
}
|
||||
case ScoutSystemStatusMsg:
|
||||
{
|
||||
buf[4] = UART_FRAME_SYSTEM_STATUS_ID;
|
||||
buf[5] = msg->system_status_msg.data.status.base_state;
|
||||
buf[6] = msg->system_status_msg.data.status.control_mode;
|
||||
buf[7] = msg->system_status_msg.data.status.battery_voltage.high_byte;
|
||||
buf[8] = msg->system_status_msg.data.status.battery_voltage.low_byte;
|
||||
buf[9] = msg->system_status_msg.data.status.fault_code.high_byte;
|
||||
buf[10] = msg->system_status_msg.data.status.fault_code.low_byte;
|
||||
buf[11] = msg->system_status_msg.data.status.count;
|
||||
break;
|
||||
}
|
||||
case ScoutMotorDriverStatusMsg:
|
||||
{
|
||||
if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR1_ID)
|
||||
buf[4] = UART_FRAME_MOTOR1_DRIVER_STATUS_ID;
|
||||
else if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR2_ID)
|
||||
buf[4] = UART_FRAME_MOTOR2_DRIVER_STATUS_ID;
|
||||
else if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR3_ID)
|
||||
buf[4] = UART_FRAME_MOTOR3_DRIVER_STATUS_ID;
|
||||
else if (msg->motor_driver_status_msg.motor_id == SCOUT_MOTOR4_ID)
|
||||
buf[4] = UART_FRAME_MOTOR4_DRIVER_STATUS_ID;
|
||||
buf[5] = msg->motor_driver_status_msg.data.status.current.high_byte;
|
||||
buf[6] = msg->motor_driver_status_msg.data.status.current.low_byte;
|
||||
buf[7] = msg->motor_driver_status_msg.data.status.rpm.high_byte;
|
||||
buf[8] = msg->motor_driver_status_msg.data.status.rpm.low_byte;
|
||||
buf[9] = msg->motor_driver_status_msg.data.status.temperature;
|
||||
buf[10] = 0;
|
||||
buf[11] = msg->motor_driver_status_msg.data.status.count;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
buf[12] = CalcScoutUARTChecksum(buf, buf[2] + FRAME_SOF_LEN);
|
||||
|
||||
// length: SOF + Frame + Checksum
|
||||
*len = buf[2] + FRAME_SOF_LEN + 1;
|
||||
}
|
||||
|
||||
void EncodeScoutControlMsgToUART(const ScoutControlMessage *msg, uint8_t *buf, uint8_t *len)
|
||||
{
|
||||
switch (msg->msg_type)
|
||||
{
|
||||
case ScoutMotionControlMsg:
|
||||
{
|
||||
EncodeMotionControlMsgToUART(&(msg->motion_control_msg), buf, len);
|
||||
break;
|
||||
}
|
||||
case ScoutLightControlMsg:
|
||||
{
|
||||
EncodeLightControlMsgToUART(&(msg->light_control_msg), buf, len);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EncodeMotionControlMsgToUART(const MotionControlMessage *msg, uint8_t *buf, uint8_t *len)
|
||||
{
|
||||
// SOF
|
||||
buf[0] = FRAME_SOF1;
|
||||
buf[1] = FRAME_SOF2;
|
||||
|
||||
// frame len, type, ID
|
||||
buf[2] = 0x0a;
|
||||
buf[3] = FRAME_TYPE_CONTROL;
|
||||
buf[4] = UART_FRAME_MOTION_CONTROL_ID;
|
||||
|
||||
// frame payload
|
||||
buf[5] = msg->data.cmd.control_mode;
|
||||
buf[6] = msg->data.cmd.fault_clear_flag;
|
||||
buf[7] = msg->data.cmd.linear_velocity_cmd;
|
||||
buf[8] = msg->data.cmd.angular_velocity_cmd;
|
||||
buf[9] = 0x00;
|
||||
buf[10] = 0x00;
|
||||
|
||||
// frame count, checksum
|
||||
buf[11] = msg->data.cmd.count;
|
||||
buf[12] = CalcScoutUARTChecksum(buf, buf[2] + FRAME_SOF_LEN);
|
||||
|
||||
// length: SOF + Frame + Checksum
|
||||
*len = buf[2] + FRAME_SOF_LEN + 1;
|
||||
}
|
||||
|
||||
void EncodeLightControlMsgToUART(const LightControlMessage *msg, uint8_t *buf, uint8_t *len)
|
||||
{
|
||||
// SOF
|
||||
buf[0] = FRAME_SOF1;
|
||||
buf[1] = FRAME_SOF2;
|
||||
|
||||
// frame len, type, ID
|
||||
buf[2] = 0x0a;
|
||||
buf[3] = FRAME_TYPE_CONTROL;
|
||||
buf[4] = UART_FRAME_LIGHT_CONTROL_ID;
|
||||
|
||||
// frame payload
|
||||
buf[5] = msg->data.cmd.light_ctrl_enable;
|
||||
buf[6] = msg->data.cmd.front_light_mode;
|
||||
buf[7] = msg->data.cmd.front_light_custom;
|
||||
buf[8] = msg->data.cmd.rear_light_mode;
|
||||
buf[9] = msg->data.cmd.rear_light_custom;
|
||||
buf[10] = 0x00;
|
||||
|
||||
// frame count, checksum
|
||||
buf[11] = msg->data.cmd.count;
|
||||
buf[12] = CalcScoutUARTChecksum(buf, buf[2] + FRAME_SOF_LEN);
|
||||
|
||||
// length: SOF + Frame + Checksum
|
||||
*len = buf[2] + FRAME_SOF_LEN + 1;
|
||||
}
|
||||
|
||||
bool DecodeScoutStatusMsgFromUART(uint8_t c, ScoutStatusMessage *msg)
|
||||
{
|
||||
static ScoutDecodedMessage decoded_msg;
|
||||
|
||||
bool result = ParseChar(c, &decoded_msg);
|
||||
if (result)
|
||||
*msg = decoded_msg.status_msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DecodeScoutControlMsgFromUART(uint8_t c, ScoutControlMessage *msg)
|
||||
{
|
||||
static ScoutDecodedMessage decoded_msg;
|
||||
|
||||
bool result = ParseChar(c, &decoded_msg);
|
||||
if (result)
|
||||
*msg = decoded_msg.control_msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t CalcScoutUARTChecksum(uint8_t *buf, uint8_t len)
|
||||
{
|
||||
uint8_t checksum = 0;
|
||||
|
||||
#ifdef USE_XOR_CHECKSUM
|
||||
for (int i = 0; i < len; ++i)
|
||||
checksum ^= buf[i];
|
||||
#else
|
||||
for (int i = 0; i < len; ++i)
|
||||
checksum += buf[i];
|
||||
#endif
|
||||
|
||||
return checksum;
|
||||
}
|
||||
|
||||
uint8_t CalcBufferedFrameChecksum()
|
||||
{
|
||||
uint8_t checksum = 0x00;
|
||||
|
||||
#ifdef USE_XOR_CHECKSUM
|
||||
checksum ^= FRAME_SOF1;
|
||||
checksum ^= FRAME_SOF2;
|
||||
checksum ^= frame_len;
|
||||
checksum ^= frame_type;
|
||||
checksum ^= frame_id;
|
||||
for (size_t i = 0; i < payload_data_pos; ++i)
|
||||
checksum ^= payload_buffer[i];
|
||||
checksum ^= frame_cnt;
|
||||
#else
|
||||
checksum += FRAME_SOF1;
|
||||
checksum += FRAME_SOF2;
|
||||
checksum += frame_len;
|
||||
checksum += frame_type;
|
||||
checksum += frame_id;
|
||||
for (size_t i = 0; i < payload_data_pos; ++i)
|
||||
checksum += payload_buffer[i];
|
||||
checksum += frame_cnt;
|
||||
#endif
|
||||
|
||||
return checksum;
|
||||
}
|
||||
|
||||
bool ParseChar(uint8_t c, ScoutDecodedMessage *msg)
|
||||
{
|
||||
static ScoutSerialDecodeState decode_state = WAIT_FOR_SOF1;
|
||||
|
||||
bool new_frame_parsed = false;
|
||||
switch (decode_state)
|
||||
{
|
||||
case WAIT_FOR_SOF1:
|
||||
{
|
||||
if (c == FRAME_SOF1)
|
||||
{
|
||||
frame_id = FRAME_NONE_ID;
|
||||
frame_type = 0;
|
||||
frame_len = 0;
|
||||
frame_cnt = 0;
|
||||
frame_checksum = 0;
|
||||
internal_checksum = 0;
|
||||
payload_data_pos = 0;
|
||||
memset(payload_buffer, 0, PAYLOAD_BUFFER_SIZE);
|
||||
|
||||
decode_state = WAIT_FOR_SOF2;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "found sof1" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "found sof1\n");
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WAIT_FOR_SOF2:
|
||||
{
|
||||
if (c == FRAME_SOF2)
|
||||
{
|
||||
decode_state = WAIT_FOR_FRAME_LEN;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "found sof2" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "found sof2\n");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
decode_state = WAIT_FOR_SOF1;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "failed to find sof2" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "failed to find sof2\n");
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WAIT_FOR_FRAME_LEN:
|
||||
{
|
||||
frame_len = c;
|
||||
decode_state = WAIT_FOR_FRAME_TYPE;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "frame len: " << std::hex << static_cast<int>(frame_len) << std::dec << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkRTTPrintf(0, "frame len: %d\n", frame_len);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case WAIT_FOR_FRAME_TYPE:
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case FRAME_TYPE_CONTROL:
|
||||
{
|
||||
frame_type = FRAME_TYPE_CONTROL;
|
||||
decode_state = WAIT_FOR_FRAME_ID;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "control type frame received" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "control type frame received\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case FRAME_TYPE_STATUS:
|
||||
{
|
||||
frame_type = FRAME_TYPE_STATUS;
|
||||
decode_state = WAIT_FOR_FRAME_ID;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "status type frame received" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "status type frame received\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cerr << "ERROR: Not expecting frame of a type other than FRAME_TYPE_STATUS" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "ERROR: Not expecting frame of a type other than FRAME_TYPE_STATUS\n");
|
||||
#endif
|
||||
decode_state = WAIT_FOR_SOF1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WAIT_FOR_FRAME_ID:
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case UART_FRAME_SYSTEM_STATUS_ID:
|
||||
case UART_FRAME_MOTION_STATUS_ID:
|
||||
case UART_FRAME_MOTOR1_DRIVER_STATUS_ID:
|
||||
case UART_FRAME_MOTOR2_DRIVER_STATUS_ID:
|
||||
case UART_FRAME_MOTOR3_DRIVER_STATUS_ID:
|
||||
case UART_FRAME_MOTOR4_DRIVER_STATUS_ID:
|
||||
case UART_FRAME_LIGHT_STATUS_ID:
|
||||
{
|
||||
frame_id = c;
|
||||
decode_state = WAIT_FOR_PAYLOAD;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "frame id: " << std::hex << static_cast<int>(frame_id) << std::dec << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkRTTPrintf(0, "frame id: %d\n", frame_id);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cerr << "ERROR: Unknown frame id" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "ERROR: Unknown frame id\n");
|
||||
#endif
|
||||
decode_state = WAIT_FOR_SOF1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WAIT_FOR_PAYLOAD:
|
||||
{
|
||||
payload_buffer[payload_data_pos++] = c;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "1 byte added: " << std::hex << static_cast<int>(c) << std::dec << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkRTTPrintf(0, "1 byte added: %d\n", c);
|
||||
#endif
|
||||
if (payload_data_pos == (frame_len - FRAME_FIXED_FIELD_LEN))
|
||||
decode_state = WAIT_FOR_FRAME_COUNT;
|
||||
break;
|
||||
}
|
||||
case WAIT_FOR_FRAME_COUNT:
|
||||
{
|
||||
frame_cnt = c;
|
||||
decode_state = WAIT_FOR_CHECKSUM;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "frame count: " << std::hex << static_cast<int>(frame_cnt) << std::dec << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkRTTPrintf(0, "frame count: %d\n", frame_cnt);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case WAIT_FOR_CHECKSUM:
|
||||
{
|
||||
frame_checksum = c;
|
||||
internal_checksum = CalcBufferedFrameChecksum();
|
||||
new_frame_parsed = true;
|
||||
decode_state = WAIT_FOR_SOF1;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "--- frame checksum: " << std::hex << static_cast<int>(frame_checksum) << std::dec << std::endl;
|
||||
std::cout << "--- internal frame checksum: " << std::hex << static_cast<int>(internal_checksum) << std::dec << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkRTTPrintf(0, "--- frame checksum: : %d\n", frame_checksum);
|
||||
JLinkRTTPrintf(0, "--- internal frame checksum: : %d\n", internal_checksum);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (new_frame_parsed)
|
||||
{
|
||||
if (frame_checksum == internal_checksum)
|
||||
{
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "checksum correct" << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "checksum correct\n");
|
||||
#endif
|
||||
if (frame_type == FRAME_TYPE_STATUS)
|
||||
ConstructStatusMessage(&(msg->status_msg));
|
||||
else if (frame_type == FRAME_TYPE_CONTROL)
|
||||
ConstructControlMessage(&(msg->control_msg));
|
||||
++frame_parsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
++frame_with_wrong_checksum;
|
||||
#ifdef PRINT_CPP_DEBUG_INFO
|
||||
std::cout << "checksum is NOT correct" << std::endl;
|
||||
std::cout << std::hex << static_cast<int>(frame_id) << " , " << static_cast<int>(frame_len) << " , " << static_cast<int>(frame_cnt) << " , " << static_cast<int>(frame_checksum) << " : " << std::dec << std::endl;
|
||||
std::cout << "payload: ";
|
||||
for (int i = 0; i < payload_data_pos; ++i)
|
||||
std::cout << std::hex << static_cast<int>(payload_buffer[i]) << std::dec << " ";
|
||||
std::cout << std::endl;
|
||||
std::cout << "--- frame checksum: " << std::hex << static_cast<int>(frame_checksum) << std::dec << std::endl;
|
||||
std::cout << "--- internal frame checksum: " << std::hex << static_cast<int>(internal_checksum) << std::dec << std::endl;
|
||||
#elif (defined(PRINT_JLINK_DEBUG_INFO))
|
||||
JLinkWriteString(0, "checksum is NOT correct\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return new_frame_parsed;
|
||||
}
|
||||
|
||||
bool ConstructControlMessage(ScoutControlMessage *msg)
|
||||
{
|
||||
if (msg == NULL)
|
||||
return false;
|
||||
|
||||
switch (frame_id)
|
||||
{
|
||||
case UART_FRAME_MOTION_CONTROL_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotionControlMsg;
|
||||
msg->motion_control_msg.data.cmd.control_mode = payload_buffer[0];
|
||||
msg->motion_control_msg.data.cmd.fault_clear_flag = payload_buffer[1];
|
||||
msg->motion_control_msg.data.cmd.linear_velocity_cmd = payload_buffer[2];
|
||||
msg->motion_control_msg.data.cmd.angular_velocity_cmd = payload_buffer[3];
|
||||
msg->motion_control_msg.data.cmd.reserved0 = payload_buffer[4];
|
||||
msg->motion_control_msg.data.cmd.reserved1 = payload_buffer[5];
|
||||
msg->motion_control_msg.data.cmd.count = frame_cnt;
|
||||
msg->motion_control_msg.data.cmd.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
case UART_FRAME_LIGHT_CONTROL_ID:
|
||||
{
|
||||
msg->msg_type = ScoutLightControlMsg;
|
||||
msg->light_control_msg.data.cmd.light_ctrl_enable = payload_buffer[0];
|
||||
msg->light_control_msg.data.cmd.front_light_mode = payload_buffer[1];
|
||||
msg->light_control_msg.data.cmd.front_light_custom = payload_buffer[2];
|
||||
msg->light_control_msg.data.cmd.rear_light_mode = payload_buffer[3];
|
||||
msg->light_control_msg.data.cmd.rear_light_custom = payload_buffer[4];
|
||||
msg->light_control_msg.data.cmd.reserved0 = payload_buffer[5];
|
||||
msg->light_control_msg.data.cmd.count = frame_cnt;
|
||||
msg->light_control_msg.data.cmd.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConstructStatusMessage(ScoutStatusMessage *msg)
|
||||
{
|
||||
if (msg == NULL)
|
||||
return false;
|
||||
|
||||
switch (frame_id)
|
||||
{
|
||||
case UART_FRAME_SYSTEM_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutSystemStatusMsg;
|
||||
msg->system_status_msg.data.status.base_state = payload_buffer[0];
|
||||
msg->system_status_msg.data.status.control_mode = payload_buffer[1];
|
||||
msg->system_status_msg.data.status.battery_voltage.high_byte = payload_buffer[2];
|
||||
msg->system_status_msg.data.status.battery_voltage.low_byte = payload_buffer[3];
|
||||
msg->system_status_msg.data.status.fault_code.high_byte = payload_buffer[4];
|
||||
msg->system_status_msg.data.status.fault_code.low_byte = payload_buffer[5];
|
||||
msg->system_status_msg.data.status.count = frame_cnt;
|
||||
msg->system_status_msg.data.status.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
case UART_FRAME_MOTION_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotionStatusMsg;
|
||||
msg->motion_status_msg.data.status.linear_velocity.high_byte = payload_buffer[0];
|
||||
msg->motion_status_msg.data.status.linear_velocity.low_byte = payload_buffer[1];
|
||||
msg->motion_status_msg.data.status.angular_velocity.high_byte = payload_buffer[2];
|
||||
msg->motion_status_msg.data.status.angular_velocity.low_byte = payload_buffer[3];
|
||||
msg->motion_status_msg.data.status.reserved0 = 0x00;
|
||||
msg->motion_status_msg.data.status.reserved0 = 0x00;
|
||||
msg->motion_status_msg.data.status.count = frame_cnt;
|
||||
msg->motion_status_msg.data.status.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
case UART_FRAME_MOTOR1_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR1_ID;
|
||||
msg->motor_driver_status_msg.data.status.current.high_byte = payload_buffer[0];
|
||||
msg->motor_driver_status_msg.data.status.current.low_byte = payload_buffer[1];
|
||||
msg->motor_driver_status_msg.data.status.rpm.high_byte = payload_buffer[2];
|
||||
msg->motor_driver_status_msg.data.status.rpm.low_byte = payload_buffer[3];
|
||||
msg->motor_driver_status_msg.data.status.temperature = payload_buffer[4];
|
||||
msg->motor_driver_status_msg.data.status.reserved0 = 0x00;
|
||||
msg->motor_driver_status_msg.data.status.count = frame_cnt;
|
||||
msg->motor_driver_status_msg.data.status.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
case UART_FRAME_MOTOR2_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR2_ID;
|
||||
msg->motor_driver_status_msg.data.status.current.high_byte = payload_buffer[0];
|
||||
msg->motor_driver_status_msg.data.status.current.low_byte = payload_buffer[1];
|
||||
msg->motor_driver_status_msg.data.status.rpm.high_byte = payload_buffer[2];
|
||||
msg->motor_driver_status_msg.data.status.rpm.low_byte = payload_buffer[3];
|
||||
msg->motor_driver_status_msg.data.status.temperature = payload_buffer[4];
|
||||
msg->motor_driver_status_msg.data.status.reserved0 = 0x00;
|
||||
msg->motor_driver_status_msg.data.status.count = frame_cnt;
|
||||
msg->motor_driver_status_msg.data.status.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
case UART_FRAME_MOTOR3_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR3_ID;
|
||||
msg->motor_driver_status_msg.data.status.current.high_byte = payload_buffer[0];
|
||||
msg->motor_driver_status_msg.data.status.current.low_byte = payload_buffer[1];
|
||||
msg->motor_driver_status_msg.data.status.rpm.high_byte = payload_buffer[2];
|
||||
msg->motor_driver_status_msg.data.status.rpm.low_byte = payload_buffer[3];
|
||||
msg->motor_driver_status_msg.data.status.temperature = payload_buffer[4];
|
||||
msg->motor_driver_status_msg.data.status.reserved0 = 0x00;
|
||||
msg->motor_driver_status_msg.data.status.count = frame_cnt;
|
||||
msg->motor_driver_status_msg.data.status.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
case UART_FRAME_MOTOR4_DRIVER_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutMotorDriverStatusMsg;
|
||||
msg->motor_driver_status_msg.motor_id = SCOUT_MOTOR4_ID;
|
||||
msg->motor_driver_status_msg.data.status.current.high_byte = payload_buffer[0];
|
||||
msg->motor_driver_status_msg.data.status.current.low_byte = payload_buffer[1];
|
||||
msg->motor_driver_status_msg.data.status.rpm.high_byte = payload_buffer[2];
|
||||
msg->motor_driver_status_msg.data.status.rpm.low_byte = payload_buffer[3];
|
||||
msg->motor_driver_status_msg.data.status.temperature = payload_buffer[4];
|
||||
msg->motor_driver_status_msg.data.status.reserved0 = 0x00;
|
||||
msg->motor_driver_status_msg.data.status.count = frame_cnt;
|
||||
msg->motor_driver_status_msg.data.status.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
case UART_FRAME_LIGHT_STATUS_ID:
|
||||
{
|
||||
msg->msg_type = ScoutLightStatusMsg;
|
||||
msg->light_status_msg.data.status.light_ctrl_enable = payload_buffer[0];
|
||||
msg->light_status_msg.data.status.front_light_mode = payload_buffer[1];
|
||||
msg->light_status_msg.data.status.front_light_custom = payload_buffer[2];
|
||||
msg->light_status_msg.data.status.rear_light_mode = payload_buffer[3];
|
||||
msg->light_status_msg.data.status.rear_light_custom = payload_buffer[4];
|
||||
msg->light_status_msg.data.status.reserved0 = 0x00;
|
||||
msg->light_status_msg.data.status.count = frame_cnt;
|
||||
msg->light_status_msg.data.status.checksum = frame_checksum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
## Add libraries
|
||||
set(SCOUT_BASE_SRC
|
||||
src/scout_base.cpp
|
||||
)
|
||||
add_library(scoutbase STATIC ${SCOUT_BASE_SRC})
|
||||
set_target_properties(scoutbase PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
target_link_libraries(scoutbase asyncio scout_protocol)
|
||||
target_include_directories(scoutbase PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<BUILD_INTERFACE:${Boost_INCLUDE_DIRS}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PRIVATE src)
|
||||
|
||||
## Add executables
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* scout_base.hpp
|
||||
*
|
||||
* Created on: Jun 04, 2019 01:22
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef SCOUT_BASE_HPP
|
||||
#define SCOUT_BASE_HPP
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <functional>
|
||||
|
||||
#include "async_io/async_can.hpp"
|
||||
#include "async_io/async_serial.hpp"
|
||||
|
||||
#include "scout_protocol/scout_protocol.h"
|
||||
#include "scout_protocol/scout_can_parser.h"
|
||||
#include "scout_protocol/scout_uart_parser.h"
|
||||
|
||||
#include "scout_base/scout_types.hpp"
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
class ScoutBase
|
||||
{
|
||||
public:
|
||||
ScoutBase() = default;
|
||||
~ScoutBase();
|
||||
|
||||
// do not allow copy
|
||||
ScoutBase(const ScoutBase &scout) = delete;
|
||||
ScoutBase &operator=(const ScoutBase &scout) = delete;
|
||||
|
||||
public:
|
||||
// connect to roboot from CAN or serial
|
||||
void Connect(std::string dev_name, int32_t baud_rate = 0);
|
||||
|
||||
// disconnect from roboot, only valid for serial port
|
||||
void Disconnect();
|
||||
|
||||
// cmd thread runs at 100Hz (10ms) by default
|
||||
void SetCmdThreadPeriodMs(int32_t period_ms) { cmd_thread_period_ms_ = period_ms; };
|
||||
|
||||
// motion control
|
||||
void SetMotionCommand(double linear_vel, double angular_vel,
|
||||
ScoutMotionCmd::FaultClearFlag fault_clr_flag = ScoutMotionCmd::FaultClearFlag::NO_FAULT);
|
||||
|
||||
// light control
|
||||
void SetLightCommand(ScoutLightCmd cmd);
|
||||
void DisableLightCmdControl();
|
||||
|
||||
// get robot state
|
||||
ScoutState GetScoutState();
|
||||
|
||||
private:
|
||||
// hardware communication interface
|
||||
std::shared_ptr<ASyncCAN> can_if_;
|
||||
std::shared_ptr<ASyncSerial> serial_if_;
|
||||
|
||||
// CAN priority higher than serial if both connected
|
||||
bool can_connected_ = false;
|
||||
bool serial_connected_ = false;
|
||||
|
||||
// serial port related variables
|
||||
uint8_t tx_cmd_len_;
|
||||
uint8_t tx_buffer_[SCOUT_CMD_BUF_LEN];
|
||||
|
||||
// cmd/status update related variables
|
||||
std::thread cmd_thread_;
|
||||
std::mutex scout_state_mutex_;
|
||||
std::mutex motion_cmd_mutex_;
|
||||
std::mutex light_cmd_mutex_;
|
||||
|
||||
ScoutState scout_state_;
|
||||
ScoutMotionCmd current_motion_cmd_;
|
||||
ScoutLightCmd current_light_cmd_;
|
||||
|
||||
int32_t cmd_thread_period_ms_ = 10;
|
||||
bool cmd_thread_started_ = false;
|
||||
|
||||
bool light_ctrl_enabled_ = false;
|
||||
bool light_ctrl_requested_ = false;
|
||||
|
||||
// internal functions
|
||||
void ConfigureCANBus(const std::string &can_if_name = "can1");
|
||||
void ConfigureSerial(const std::string uart_name = "/dev/ttyUSB0", int32_t baud_rate = 115200);
|
||||
|
||||
void StartCmdThread();
|
||||
void ControlLoop(int32_t period_ms);
|
||||
|
||||
void SendMotionCmd(uint8_t count);
|
||||
void SendLightCmd(uint8_t count);
|
||||
|
||||
void ParseCANFrame(can_frame *rx_frame);
|
||||
void ParseUARTBuffer(uint8_t *buf, const size_t bufsize, size_t bytes_received);
|
||||
|
||||
void NewStatusMsgReceivedCallback(const ScoutStatusMessage &msg);
|
||||
|
||||
public:
|
||||
static void UpdateScoutState(const ScoutStatusMessage &status_msg, ScoutState &state);
|
||||
};
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* SCOUT_BASE_HPP */
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* scout_state.hpp
|
||||
*
|
||||
* Created on: Jun 11, 2019 08:48
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2019 Ruixiang Du (rdu)
|
||||
*/
|
||||
|
||||
#ifndef SCOUT_STATE_HPP
|
||||
#define SCOUT_STATE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
struct ScoutState
|
||||
{
|
||||
enum MotorID
|
||||
{
|
||||
FRONT_RIGHT = 0,
|
||||
FRONT_LEFT = 1,
|
||||
REAR_LEFT = 2,
|
||||
REAR_RIGHT = 3
|
||||
};
|
||||
|
||||
struct MotorState
|
||||
{
|
||||
double current = 0; // in A
|
||||
double rpm = 0;
|
||||
double temperature = 0;
|
||||
};
|
||||
|
||||
struct LightState
|
||||
{
|
||||
uint8_t mode = 0;
|
||||
uint8_t custom_value = 0;
|
||||
};
|
||||
|
||||
// base state
|
||||
uint8_t base_state = 0;
|
||||
uint8_t control_mode = 0;
|
||||
uint16_t fault_code = 0;
|
||||
double battery_voltage = 0.0;
|
||||
|
||||
// motor state
|
||||
MotorState motor_states[4];
|
||||
|
||||
// light state
|
||||
bool light_control_enabled = false;
|
||||
LightState front_light_state;
|
||||
LightState rear_light_state;
|
||||
|
||||
// motion state
|
||||
double linear_velocity = 0;
|
||||
double angular_velocity = 0;
|
||||
};
|
||||
|
||||
struct ScoutMotionCmd
|
||||
{
|
||||
enum class FaultClearFlag
|
||||
{
|
||||
NO_FAULT = 0x00,
|
||||
BAT_UNDER_VOL = 0x01,
|
||||
BAT_OVER_VOL = 0x02,
|
||||
MOTOR1_COMM = 0x03,
|
||||
MOTOR2_COMM = 0x04,
|
||||
MOTOR3_COMM = 0x05,
|
||||
MOTOR4_COMM = 0x06,
|
||||
MOTOR_DRV_OVERHEAT = 0x07,
|
||||
MOTOR_OVERCURRENT = 0x08
|
||||
};
|
||||
|
||||
ScoutMotionCmd(int8_t linear = 0, int8_t angular = 0,
|
||||
FaultClearFlag fault_clr_flag = FaultClearFlag::NO_FAULT)
|
||||
: linear_velocity(linear), angular_velocity(angular),
|
||||
fault_clear_flag(fault_clr_flag) {}
|
||||
|
||||
int8_t linear_velocity;
|
||||
int8_t angular_velocity;
|
||||
FaultClearFlag fault_clear_flag;
|
||||
|
||||
static constexpr double max_linear_velocity = 1.5; // 1.5 m/s
|
||||
static constexpr double min_linear_velocity = -1.5; // -1.5 m/s
|
||||
static constexpr double max_angular_velocity = 0.5235; // 0.5235 rad/s
|
||||
static constexpr double min_angular_velocity = -0.5235; // -0.5235 rad/s
|
||||
};
|
||||
|
||||
struct ScoutLightCmd
|
||||
{
|
||||
enum class LightMode
|
||||
{
|
||||
CONST_OFF = 0x00,
|
||||
CONST_ON = 0x01,
|
||||
BREATH = 0x02,
|
||||
CUSTOM = 0x03
|
||||
};
|
||||
|
||||
ScoutLightCmd() = default;
|
||||
ScoutLightCmd(LightMode f_mode, uint8_t f_value, LightMode r_mode, uint8_t r_value) : front_mode(f_mode), front_custom_value(f_value),
|
||||
rear_mode(r_mode), rear_custom_value(r_value) {}
|
||||
|
||||
LightMode front_mode;
|
||||
uint8_t front_custom_value;
|
||||
LightMode rear_mode;
|
||||
uint8_t rear_custom_value;
|
||||
};
|
||||
} // namespace wescore
|
||||
|
||||
#endif /* SCOUT_STATE_HPP */
|
||||
@@ -1,391 +0,0 @@
|
||||
#include "scout_base/scout_base.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <ratio>
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
// source: https://github.com/rxdu/stopwatch
|
||||
struct StopWatch
|
||||
{
|
||||
using Clock = std::chrono::high_resolution_clock;
|
||||
using time_point = typename Clock::time_point;
|
||||
using duration = typename Clock::duration;
|
||||
|
||||
StopWatch() { tic_point = Clock::now(); };
|
||||
|
||||
time_point tic_point;
|
||||
|
||||
void tic()
|
||||
{
|
||||
tic_point = Clock::now();
|
||||
};
|
||||
|
||||
double toc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - tic_point).count() / 1000000.0;
|
||||
};
|
||||
|
||||
// for different precisions
|
||||
double stoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
double mtoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
double utoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
double ntoc()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(Clock::now() - tic_point).count();
|
||||
};
|
||||
|
||||
// you have to call tic() before calling this function
|
||||
void sleep_until_ms(int64_t period_ms)
|
||||
{
|
||||
int64_t duration = period_ms - std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - tic_point).count();
|
||||
|
||||
if (duration > 0)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(duration));
|
||||
};
|
||||
|
||||
void sleep_until_us(int64_t period_us)
|
||||
{
|
||||
int64_t duration = period_us - std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - tic_point).count();
|
||||
|
||||
if (duration > 0)
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(duration));
|
||||
};
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace wescore
|
||||
{
|
||||
ScoutBase::~ScoutBase()
|
||||
{
|
||||
if (serial_connected_)
|
||||
serial_if_->close();
|
||||
|
||||
if (cmd_thread_.joinable())
|
||||
cmd_thread_.join();
|
||||
}
|
||||
|
||||
void ScoutBase::Connect(std::string dev_name, int32_t baud_rate)
|
||||
{
|
||||
if (baud_rate == 0)
|
||||
{
|
||||
ConfigureCANBus(dev_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfigureSerial(dev_name, baud_rate);
|
||||
|
||||
if (!serial_connected_)
|
||||
std::cerr << "ERROR: Failed to connect to serial port" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ScoutBase::Disconnect()
|
||||
{
|
||||
if (serial_connected_)
|
||||
{
|
||||
if (serial_if_->is_open())
|
||||
serial_if_->close();
|
||||
}
|
||||
}
|
||||
|
||||
void ScoutBase::ConfigureCANBus(const std::string &can_if_name)
|
||||
{
|
||||
can_if_ = std::make_shared<ASyncCAN>(can_if_name);
|
||||
|
||||
can_if_->set_receive_callback(std::bind(&ScoutBase::ParseCANFrame, this, std::placeholders::_1));
|
||||
|
||||
can_connected_ = true;
|
||||
}
|
||||
|
||||
void ScoutBase::ConfigureSerial(const std::string uart_name, int32_t baud_rate)
|
||||
{
|
||||
serial_if_ = std::make_shared<ASyncSerial>(uart_name, baud_rate);
|
||||
serial_if_->open();
|
||||
|
||||
if (serial_if_->is_open())
|
||||
serial_connected_ = true;
|
||||
|
||||
serial_if_->set_receive_callback(std::bind(&ScoutBase::ParseUARTBuffer, this,
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2,
|
||||
std::placeholders::_3));
|
||||
}
|
||||
|
||||
void ScoutBase::StartCmdThread()
|
||||
{
|
||||
current_motion_cmd_.linear_velocity = 0;
|
||||
current_motion_cmd_.angular_velocity = 0;
|
||||
current_motion_cmd_.fault_clear_flag = ScoutMotionCmd::FaultClearFlag::NO_FAULT;
|
||||
|
||||
cmd_thread_ = std::thread(std::bind(&ScoutBase::ControlLoop, this, cmd_thread_period_ms_));
|
||||
cmd_thread_started_ = true;
|
||||
}
|
||||
|
||||
void ScoutBase::SendMotionCmd(uint8_t count)
|
||||
{
|
||||
// motion control message
|
||||
MotionControlMessage m_msg;
|
||||
|
||||
if (can_connected_)
|
||||
m_msg.data.cmd.control_mode = CTRL_MODE_CMD_CAN;
|
||||
else if (serial_connected_)
|
||||
m_msg.data.cmd.control_mode = CTRL_MODE_CMD_UART;
|
||||
|
||||
motion_cmd_mutex_.lock();
|
||||
m_msg.data.cmd.fault_clear_flag = static_cast<uint8_t>(current_motion_cmd_.fault_clear_flag);
|
||||
m_msg.data.cmd.linear_velocity_cmd = current_motion_cmd_.linear_velocity;
|
||||
m_msg.data.cmd.angular_velocity_cmd = current_motion_cmd_.angular_velocity;
|
||||
motion_cmd_mutex_.unlock();
|
||||
|
||||
m_msg.data.cmd.reserved0 = 0;
|
||||
m_msg.data.cmd.reserved1 = 0;
|
||||
m_msg.data.cmd.count = count;
|
||||
|
||||
if (can_connected_)
|
||||
m_msg.data.cmd.checksum = CalcScoutCANChecksum(CAN_MSG_MOTION_CONTROL_CMD_ID, m_msg.data.raw, 8);
|
||||
// serial_connected_: checksum will be calculated later when packed into a complete serial frame
|
||||
|
||||
if (can_connected_)
|
||||
{
|
||||
// send to can bus
|
||||
can_frame m_frame;
|
||||
EncodeScoutMotionControlMsgToCAN(&m_msg, &m_frame);
|
||||
can_if_->send_frame(m_frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
// send to serial port
|
||||
EncodeMotionControlMsgToUART(&m_msg, tx_buffer_, &tx_cmd_len_);
|
||||
serial_if_->send_bytes(tx_buffer_, tx_cmd_len_);
|
||||
}
|
||||
}
|
||||
|
||||
void ScoutBase::SendLightCmd(uint8_t count)
|
||||
{
|
||||
LightControlMessage l_msg;
|
||||
|
||||
light_cmd_mutex_.lock();
|
||||
if (light_ctrl_enabled_)
|
||||
{
|
||||
l_msg.data.cmd.light_ctrl_enable = LIGHT_ENABLE_CTRL;
|
||||
|
||||
l_msg.data.cmd.front_light_mode = static_cast<uint8_t>(current_light_cmd_.front_mode);
|
||||
l_msg.data.cmd.front_light_custom = current_light_cmd_.front_custom_value;
|
||||
l_msg.data.cmd.rear_light_mode = static_cast<uint8_t>(current_light_cmd_.rear_mode);
|
||||
l_msg.data.cmd.rear_light_custom = current_light_cmd_.rear_custom_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_msg.data.cmd.light_ctrl_enable = LIGHT_DISABLE_CTRL;
|
||||
|
||||
l_msg.data.cmd.front_light_mode = LIGHT_MODE_CONST_OFF;
|
||||
l_msg.data.cmd.front_light_custom = 0;
|
||||
l_msg.data.cmd.rear_light_mode = LIGHT_MODE_CONST_OFF;
|
||||
l_msg.data.cmd.rear_light_custom = 0;
|
||||
}
|
||||
light_ctrl_requested_ = false;
|
||||
light_cmd_mutex_.unlock();
|
||||
|
||||
l_msg.data.cmd.reserved0 = 0;
|
||||
l_msg.data.cmd.count = count;
|
||||
|
||||
if (can_connected_)
|
||||
l_msg.data.cmd.checksum = CalcScoutCANChecksum(CAN_MSG_LIGHT_CONTROL_CMD_ID, l_msg.data.raw, 8);
|
||||
// serial_connected_: checksum will be calculated later when packed into a complete serial frame
|
||||
|
||||
if (can_connected_)
|
||||
{
|
||||
// send to can bus
|
||||
can_frame l_frame;
|
||||
EncodeScoutLightControlMsgToCAN(&l_msg, &l_frame);
|
||||
|
||||
can_if_->send_frame(l_frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
// send to serial port
|
||||
EncodeLightControlMsgToUART(&l_msg, tx_buffer_, &tx_cmd_len_);
|
||||
serial_if_->send_bytes(tx_buffer_, tx_cmd_len_);
|
||||
}
|
||||
|
||||
// std::cout << "cmd: " << static_cast<int>(l_msg.data.cmd.front_light_mode) << " , " << static_cast<int>(l_msg.data.cmd.front_light_custom) << " , "
|
||||
// << static_cast<int>(l_msg.data.cmd.rear_light_mode) << " , " << static_cast<int>(l_msg.data.cmd.rear_light_custom) << std::endl;
|
||||
// std::cout << "can: ";
|
||||
// for (int i = 0; i < 8; ++i)
|
||||
// std::cout << static_cast<int>(l_frame.data[i]) << " ";
|
||||
// std::cout << "uart: ";
|
||||
// for (int i = 0; i < tx_cmd_len_; ++i)
|
||||
// std::cout << static_cast<int>(tx_buffer_[i]) << " ";
|
||||
// std::cout << std::endl;
|
||||
}
|
||||
|
||||
void ScoutBase::ControlLoop(int32_t period_ms)
|
||||
{
|
||||
StopWatch ctrl_sw;
|
||||
uint8_t cmd_count = 0;
|
||||
uint8_t light_cmd_count = 0;
|
||||
while (true)
|
||||
{
|
||||
ctrl_sw.tic();
|
||||
|
||||
// motion control message
|
||||
SendMotionCmd(cmd_count++);
|
||||
|
||||
// check if there is request for light control
|
||||
if (light_ctrl_requested_)
|
||||
SendLightCmd(light_cmd_count++);
|
||||
|
||||
ctrl_sw.sleep_until_ms(period_ms);
|
||||
// std::cout << "control loop update frequency: " << 1.0 / ctrl_sw.toc() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
ScoutState ScoutBase::GetScoutState()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(scout_state_mutex_);
|
||||
return scout_state_;
|
||||
}
|
||||
|
||||
void ScoutBase::SetMotionCommand(double linear_vel, double angular_vel, ScoutMotionCmd::FaultClearFlag fault_clr_flag)
|
||||
{
|
||||
// make sure cmd thread is started before attempting to send commands
|
||||
if (!cmd_thread_started_)
|
||||
StartCmdThread();
|
||||
|
||||
if (linear_vel < ScoutMotionCmd::min_linear_velocity)
|
||||
linear_vel = ScoutMotionCmd::min_linear_velocity;
|
||||
if (linear_vel > ScoutMotionCmd::max_linear_velocity)
|
||||
linear_vel = ScoutMotionCmd::max_linear_velocity;
|
||||
if (angular_vel < ScoutMotionCmd::min_angular_velocity)
|
||||
angular_vel = ScoutMotionCmd::min_angular_velocity;
|
||||
if (angular_vel > ScoutMotionCmd::max_angular_velocity)
|
||||
angular_vel = ScoutMotionCmd::max_angular_velocity;
|
||||
|
||||
std::lock_guard<std::mutex> guard(motion_cmd_mutex_);
|
||||
current_motion_cmd_.linear_velocity = static_cast<int8_t>(linear_vel / ScoutMotionCmd::max_linear_velocity * 100.0);
|
||||
current_motion_cmd_.angular_velocity = static_cast<int8_t>(angular_vel / ScoutMotionCmd::max_angular_velocity * 100.0);
|
||||
current_motion_cmd_.fault_clear_flag = fault_clr_flag;
|
||||
}
|
||||
|
||||
void ScoutBase::SetLightCommand(ScoutLightCmd cmd)
|
||||
{
|
||||
if (!cmd_thread_started_)
|
||||
StartCmdThread();
|
||||
|
||||
std::lock_guard<std::mutex> guard(light_cmd_mutex_);
|
||||
current_light_cmd_ = cmd;
|
||||
light_ctrl_enabled_ = true;
|
||||
light_ctrl_requested_ = true;
|
||||
}
|
||||
|
||||
void ScoutBase::DisableLightCmdControl()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(light_cmd_mutex_);
|
||||
light_ctrl_enabled_ = false;
|
||||
light_ctrl_requested_ = true;
|
||||
}
|
||||
|
||||
void ScoutBase::ParseCANFrame(can_frame *rx_frame)
|
||||
{
|
||||
// validate checksum, discard frame if fails
|
||||
if (!rx_frame->data[7] == CalcScoutCANChecksum(rx_frame->can_id, rx_frame->data, rx_frame->can_dlc))
|
||||
{
|
||||
std::cerr << "ERROR: checksum mismatch, discard frame with id " << rx_frame->can_id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise, update robot state with new frame
|
||||
ScoutStatusMessage status_msg;
|
||||
DecodeScoutStatusMsgFromCAN(rx_frame, &status_msg);
|
||||
NewStatusMsgReceivedCallback(status_msg);
|
||||
}
|
||||
|
||||
void ScoutBase::ParseUARTBuffer(uint8_t *buf, const size_t bufsize, size_t bytes_received)
|
||||
{
|
||||
// std::cout << "bytes received from serial: " << bytes_received << std::endl;
|
||||
ScoutStatusMessage status_msg;
|
||||
for (int i = 0; i < bytes_received; ++i)
|
||||
{
|
||||
if (DecodeScoutStatusMsgFromUART(buf[i], &status_msg))
|
||||
NewStatusMsgReceivedCallback(status_msg);
|
||||
}
|
||||
}
|
||||
|
||||
void ScoutBase::NewStatusMsgReceivedCallback(const ScoutStatusMessage &msg)
|
||||
{
|
||||
// std::cout << "new status msg received" << std::endl;
|
||||
std::lock_guard<std::mutex> guard(scout_state_mutex_);
|
||||
UpdateScoutState(msg, scout_state_);
|
||||
}
|
||||
|
||||
void ScoutBase::UpdateScoutState(const ScoutStatusMessage &status_msg, ScoutState &state)
|
||||
{
|
||||
switch (status_msg.msg_type)
|
||||
{
|
||||
case ScoutMotionStatusMsg:
|
||||
{
|
||||
// std::cout << "motion control feedback received" << std::endl;
|
||||
const MotionStatusMessage &msg = status_msg.motion_status_msg;
|
||||
state.linear_velocity = static_cast<int16_t>(static_cast<uint16_t>(msg.data.status.linear_velocity.low_byte) | static_cast<uint16_t>(msg.data.status.linear_velocity.high_byte) << 8) / 1000.0;
|
||||
state.angular_velocity = static_cast<int16_t>(static_cast<uint16_t>(msg.data.status.angular_velocity.low_byte) | static_cast<uint16_t>(msg.data.status.angular_velocity.high_byte) << 8) / 1000.0;
|
||||
break;
|
||||
}
|
||||
case ScoutLightStatusMsg:
|
||||
{
|
||||
// std::cout << "light control feedback received" << std::endl;
|
||||
const LightStatusMessage &msg = status_msg.light_status_msg;
|
||||
if (msg.data.status.light_ctrl_enable == LIGHT_DISABLE_CTRL)
|
||||
state.light_control_enabled = false;
|
||||
else
|
||||
state.light_control_enabled = true;
|
||||
state.front_light_state.mode = msg.data.status.front_light_mode;
|
||||
state.front_light_state.custom_value = msg.data.status.front_light_custom;
|
||||
state.rear_light_state.mode = msg.data.status.rear_light_mode;
|
||||
state.rear_light_state.custom_value = msg.data.status.rear_light_custom;
|
||||
break;
|
||||
}
|
||||
case ScoutSystemStatusMsg:
|
||||
{
|
||||
// std::cout << "system status feedback received" << std::endl;
|
||||
const SystemStatusMessage &msg = status_msg.system_status_msg;
|
||||
state.control_mode = msg.data.status.control_mode;
|
||||
state.base_state = msg.data.status.base_state;
|
||||
state.battery_voltage = (static_cast<uint16_t>(msg.data.status.battery_voltage.low_byte) | static_cast<uint16_t>(msg.data.status.battery_voltage.high_byte) << 8) / 10.0;
|
||||
state.fault_code = (static_cast<uint16_t>(msg.data.status.fault_code.low_byte) | static_cast<uint16_t>(msg.data.status.fault_code.high_byte) << 8);
|
||||
break;
|
||||
}
|
||||
case ScoutMotorDriverStatusMsg:
|
||||
{
|
||||
// std::cout << "motor 1 driver feedback received" << std::endl;
|
||||
const MotorDriverStatusMessage &msg = status_msg.motor_driver_status_msg;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
state.motor_states[status_msg.motor_driver_status_msg.motor_id].current = (static_cast<uint16_t>(msg.data.status.current.low_byte) | static_cast<uint16_t>(msg.data.status.current.high_byte) << 8) / 10.0;
|
||||
state.motor_states[status_msg.motor_driver_status_msg.motor_id].rpm = static_cast<int16_t>(static_cast<uint16_t>(msg.data.status.rpm.low_byte) | static_cast<uint16_t>(msg.data.status.rpm.high_byte) << 8);
|
||||
state.motor_states[status_msg.motor_driver_status_msg.motor_id].temperature = msg.data.status.temperature;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace wescore
|
||||
@@ -1,16 +0,0 @@
|
||||
# Dependency libraries
|
||||
#find_package(LIBRARY_NAME REQUIRED)
|
||||
|
||||
# tests
|
||||
add_executable(test_scout_base test_scout_base.cpp)
|
||||
target_link_libraries(test_scout_base scoutbase)
|
||||
|
||||
# add_executable(test_scout_serial test_scout_serial.cpp)
|
||||
# target_link_libraries(test_scout_serial scoutbase)
|
||||
|
||||
# add_executable(test_can_msg test_can_msg.cpp)
|
||||
# target_link_libraries(test_can_msg scoutbase)
|
||||
|
||||
# add_executable(test_serial_parser test_serial_parser.cpp)
|
||||
# target_link_libraries(test_serial_parser scoutbase)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "scout_base/details/scout_can_parser.hpp"
|
||||
|
||||
using namespace wescore;
|
||||
|
||||
void print_msg(uint8_t data[8])
|
||||
{
|
||||
for (int i = 0; i < 8; ++i)
|
||||
std::cout << std::hex << static_cast<int>(data[i]) << " ";
|
||||
std::cout << std::dec << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
MotionControlMessage msg;
|
||||
msg.msg.cmd.control_mode = CTRL_MODE_CMD_CAN;
|
||||
msg.msg.cmd.fault_clear_flag = FAULT_CLR_NONE;
|
||||
msg.msg.cmd.linear_velocity_cmd = 10;
|
||||
msg.msg.cmd.angular_velocity_cmd = 0;
|
||||
msg.msg.cmd.reserved0 = 0;
|
||||
msg.msg.cmd.reserved1 = 0;
|
||||
msg.msg.cmd.count = 0;
|
||||
msg.msg.cmd.checksum = ScoutCANParser::Agilex_CANMsgChecksum(ScoutCANParser::CAN_MSG_MOTION_CONTROL_CMD_ID, msg.msg.raw, msg.len);
|
||||
print_msg(msg.msg.raw);
|
||||
|
||||
LightControlMessage msg2;
|
||||
msg2.msg.cmd.light_ctrl_enable = LIGHT_DISABLE_CTRL;
|
||||
msg2.msg.cmd.front_light_mode = LIGHT_MODE_CONST_ON;
|
||||
msg2.msg.cmd.front_light_custom = 0;
|
||||
msg2.msg.cmd.rear_light_mode = LIGHT_MODE_CONST_ON;
|
||||
msg2.msg.cmd.rear_light_custom = 0;
|
||||
msg2.msg.cmd.reserved0 = 0;
|
||||
msg2.msg.cmd.count = 0;
|
||||
msg2.msg.cmd.checksum = ScoutCANParser::Agilex_CANMsgChecksum(ScoutCANParser::CAN_MSG_LIGHT_CONTROL_CMD_ID, msg2.msg.raw, msg2.len);
|
||||
print_msg(msg2.msg.raw);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user