Skip to content

Commit

Permalink
Merge pull request #33 from sam-xl/LH2-211-clang-format-update
Browse files Browse the repository at this point in the history
Apply clang format standard to code base
  • Loading branch information
NithishkumarS authored Nov 30, 2023
2 parents c91a7e5 + bff5c76 commit 02ba9bc
Show file tree
Hide file tree
Showing 7 changed files with 904 additions and 708 deletions.
65 changes: 65 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# From https://github.com/PickNikRobotics/roscpp_code_format
# Using the variant from https://github.com/PickNikRobotics/roscpp_code_format/pull/16 for up-to-date syntax for clang-format 10/noetic
---
BasedOnStyle: Google
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 2
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true
BinPackParameters: true
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: false
DerivePointerBinding: false
PointerBindsToType: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 60
PenaltyBreakString: 1
PenaltyBreakFirstLessLess: 1000
PenaltyExcessCharacter: 1000
PenaltyReturnTypeOnItsOwnLine: 90
SpacesBeforeTrailingComments: 2
Cpp11BracedListStyle: false
Standard: Auto
IndentWidth: 2
TabWidth: 2
UseTab: Never
IndentFunctionDeclarationAfterType: false
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
SortIncludes: true
SpaceAfterCStyleCast: false

# Configure each individual brace in BraceWrapping
BreakBeforeBraces: Custom

# Control of individual brace wrapping cases
BraceWrapping:
AfterClass: 'true'
AfterControlStatement: 'true'
AfterEnum : 'true'
AfterFunction : 'true'
AfterNamespace : 'true'
AfterStruct : 'true'
AfterUnion : 'true'
BeforeCatch : 'true'
BeforeElse : 'true'
IndentBraces : 'false'
15 changes: 13 additions & 2 deletions .github/workflows/industrial_ci_action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ jobs:
CCACHE_DIR: /github/home/.ccache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v4.1.1
- uses: actions/cache@v3.3.2
with:
path: ${{ env.CCACHE_DIR }}
key: ccache-${{ matrix.env.ROS_DISTRO }}-${{ matrix.env.ROS_REPO }}
- uses: 'ros-industrial/industrial_ci@master'
env: ${{ matrix.env }}

clang-format-check:
strategy:
matrix:
env:
- {OS_NAME: ubuntu, OS_CODE_NAME: focal, ROS_DISTRO: noetic, DOCKER_IMAGE: "samxl/scancontrol:sdk_v1.0.0", CLANG_FORMAT_CHECK: "file", CLANG_FORMAT_VERSION: '10'}
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: 'ros-industrial/industrial_ci@master'
env: ${{ matrix.env }}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#ifndef _SCANCONTROL_DRIVER_H_
#define _SCANCONTROL_DRIVER_H_

#include <ros/ros.h>
#include <pcl/point_types.h>
#include <pcl_ros/point_cloud.h>

#include <std_srvs/SetBool.h>
#include <llt.h>
#include <mescan.h>
#include <micro_epsilon_scancontrol_msgs/GetAvailableResolutions.h>
#include <micro_epsilon_scancontrol_msgs/GetFeature.h>
#include <micro_epsilon_scancontrol_msgs/SetFeature.h>
#include <micro_epsilon_scancontrol_msgs/GetResolution.h>
#include <micro_epsilon_scancontrol_msgs/SetFeature.h>
#include <micro_epsilon_scancontrol_msgs/SetResolution.h>
#include <micro_epsilon_scancontrol_msgs/GetAvailableResolutions.h>

#include <llt.h>
#include <mescan.h>
#include <pcl/point_types.h>
#include <pcl_ros/point_cloud.h>
#include <ros/ros.h>
#include <std_srvs/SetBool.h>

#define MAX_DEVICE_INTERFACE_COUNT 6
#define MAX_RESOLUTION_COUNT 6
Expand All @@ -26,122 +24,135 @@ typedef pcl::PointCloud<pcl::PointXYZI> point_cloud_t;

namespace scancontrol_driver
{
class ScanControlDriver
{
public:
// Constructor and destructor
ScanControlDriver(ros::NodeHandle nh, ros::NodeHandle private_nh);
~ScanControlDriver() {}

// Profile functions
int SetPartialProfile(int &resolution);
int StartProfileTransfer();
int StopProfileTransfer();
int ProcessAndPublishProfile(const void * data, size_t data_size);

// Device setting functions
int GetFeature(unsigned int setting_id, unsigned int *value);
int SetFeature(unsigned int setting_id, unsigned int value);

// Get configuration parameters
std::string serial() const {return config_.serial;};
int resolution() const {return config_.resolution;};

// Service Callback
bool ServiceSetFeature(micro_epsilon_scancontrol_msgs::SetFeature::Request &request, micro_epsilon_scancontrol_msgs::SetFeature::Response &response);
bool ServiceGetFeature(micro_epsilon_scancontrol_msgs::GetFeature::Request &request, micro_epsilon_scancontrol_msgs::GetFeature::Response &response);
bool ServiceSetResolution(micro_epsilon_scancontrol_msgs::SetResolution::Request &request, micro_epsilon_scancontrol_msgs::SetResolution::Response &response);
bool ServiceGetResolution(micro_epsilon_scancontrol_msgs::GetResolution::Request &request, micro_epsilon_scancontrol_msgs::GetResolution::Response &response);
bool ServiceGetAvailableResolutions(micro_epsilon_scancontrol_msgs::GetAvailableResolutions::Request &request, micro_epsilon_scancontrol_msgs::GetAvailableResolutions::Response &response);
bool ServiceInvertZ(std_srvs::SetBool::Request &request, std_srvs::SetBool::Response &response);
bool ServiceInvertX(std_srvs::SetBool::Request &request, std_srvs::SetBool::Response &response);

private:
// Profile functions
int Profile2PointCloud();
// Configuration storage
struct
{
std::string frame_id;
std::string model;
std::string serial;
std::string interface;
std::string topic_name;
int resolution;
int pp_start_point;
int pp_start_point_data;
int pp_point_count;
int pp_point_data_width;
} config_;

bool initialized_ = false;
bool transfer_active_ = false;

// ROS handles
ros::NodeHandle nh_;
ros::NodeHandle private_nh_;
ros::Publisher publisher;
ros::ServiceServer get_feature_srv;
ros::ServiceServer set_feature_srv;
ros::ServiceServer get_resolution_srv;
ros::ServiceServer set_resolution_srv;
ros::ServiceServer get_available_resolutions_srv;
ros::ServiceServer invert_z_srv;
ros::ServiceServer invert_x_srv;


// Driver objects
std::unique_ptr<CInterfaceLLT> device_interface_ptr;
TScannerType device_type;
TPartialProfile t_partial_profile_;
std::vector<guint8> profile_buffer;
std::vector<double> value_x, value_z;
int lost_values;
unsigned int lost_profiles;

point_cloud_t::Ptr point_cloud_msg;

std::map<std::string, unsigned int> feature2id = {
{"FEATURE_FUNCTION_SERIAL", FEATURE_FUNCTION_SERIAL},
{"FEATURE_FUNCTION_PEAKFILTER_WIDTH", FEATURE_FUNCTION_PEAKFILTER_WIDTH},
{"FEATURE_FUNCTION_PEAKFILTER_HEIGHT", FEATURE_FUNCTION_PEAKFILTER_HEIGHT},
{"FEATURE_FUNCTION_FREE_MEASURINGFIELD_Z", FEATURE_FUNCTION_FREE_MEASURINGFIELD_Z},
{"FEATURE_FUNCTION_FREE_MEASURINGFIELD_X", FEATURE_FUNCTION_FREE_MEASURINGFIELD_X},
{"FEATURE_FUNCTION_DYNAMIC_TRACK_DIVISOR", FEATURE_FUNCTION_DYNAMIC_TRACK_DIVISOR},
{"FEATURE_FUNCTION_DYNAMIC_TRACK_FACTOR", FEATURE_FUNCTION_DYNAMIC_TRACK_FACTOR},
{"FEATURE_FUNCTION_CALIBRATION_0", FEATURE_FUNCTION_CALIBRATION_0},
{"FEATURE_FUNCTION_CALIBRATION_1", FEATURE_FUNCTION_CALIBRATION_1},
{"FEATURE_FUNCTION_CALIBRATION_2", FEATURE_FUNCTION_CALIBRATION_2},
{"FEATURE_FUNCTION_CALIBRATION_3", FEATURE_FUNCTION_CALIBRATION_3},
{"FEATURE_FUNCTION_CALIBRATION_4", FEATURE_FUNCTION_CALIBRATION_4},
{"FEATURE_FUNCTION_CALIBRATION_5", FEATURE_FUNCTION_CALIBRATION_5},
{"FEATURE_FUNCTION_CALIBRATION_6", FEATURE_FUNCTION_CALIBRATION_6},
{"FEATURE_FUNCTION_CALIBRATION_7", FEATURE_FUNCTION_CALIBRATION_7},
{"FEATURE_FUNCTION_LASERPOWER", FEATURE_FUNCTION_LASERPOWER},
{"FEATURE_FUNCTION_MEASURINGFIELD", FEATURE_FUNCTION_MEASURINGFIELD},
{"FEATURE_FUNCTION_TRIGGER", FEATURE_FUNCTION_TRIGGER},
{"FEATURE_FUNCTION_SHUTTERTIME", FEATURE_FUNCTION_SHUTTERTIME},
{"FEATURE_FUNCTION_IDLETIME", FEATURE_FUNCTION_IDLETIME},
{"FEATURE_FUNCTION_PROCESSING_PROFILEDATA", FEATURE_FUNCTION_PROCESSING_PROFILEDATA},
{"FEATURE_FUNCTION_THRESHOLD", FEATURE_FUNCTION_THRESHOLD},
{"FEATURE_FUNCTION_MAINTENANCEFUNCTIONS", FEATURE_FUNCTION_MAINTENANCEFUNCTIONS},
{"FEATURE_FUNCTION_REARRANGEMENT_PROFILE", FEATURE_FUNCTION_REARRANGEMENT_PROFILE},
{"FEATURE_FUNCTION_PROFILE_FILTER", FEATURE_FUNCTION_PROFILE_FILTER},
{"FEATURE_FUNCTION_RS422_INTERFACE_FUNCTION", FEATURE_FUNCTION_RS422_INTERFACE_FUNCTION},
{"FEATURE_FUNCTION_PACKET_DELAY", FEATURE_FUNCTION_PACKET_DELAY},
{"FEATURE_FUNCTION_SHARPNESS", FEATURE_FUNCTION_SHARPNESS},
{"FEATURE_FUNCTION_TEMPERATURE", FEATURE_FUNCTION_TEMPERATURE},
{"FEATURE_FUNCTION_SATURATION", FEATURE_FUNCTION_SATURATION},
{"FEATURE_FUNCTION_CAPTURE_QUALITY", FEATURE_FUNCTION_CAPTURE_QUALITY}
};

//
std::list<unsigned int> features_with_corruption_risk = {FEATURE_FUNCTION_LASERPOWER, FEATURE_FUNCTION_MEASURINGFIELD, FEATURE_FUNCTION_TRIGGER};
};

void NewProfileCallback(const void * data, size_t data_size, gpointer user_data);
void ControlLostCallback(ArvGvDevice *mydevice, gpointer user_data);

} // namespace scancontrol_driver

#endif // _SCANCONTROL_DRIVER_H_
class ScanControlDriver
{
public:
// Constructor and destructor
ScanControlDriver(ros::NodeHandle nh, ros::NodeHandle private_nh);
~ScanControlDriver()
{
}

// Profile functions
int SetPartialProfile(int& resolution);
int StartProfileTransfer();
int StopProfileTransfer();
int ProcessAndPublishProfile(const void* data, size_t data_size);

// Device setting functions
int GetFeature(unsigned int setting_id, unsigned int* value);
int SetFeature(unsigned int setting_id, unsigned int value);

// Get configuration parameters
std::string serial() const
{
return config_.serial;
};
int resolution() const
{
return config_.resolution;
};

// Service Callback
bool ServiceSetFeature(micro_epsilon_scancontrol_msgs::SetFeature::Request& request,
micro_epsilon_scancontrol_msgs::SetFeature::Response& response);
bool ServiceGetFeature(micro_epsilon_scancontrol_msgs::GetFeature::Request& request,
micro_epsilon_scancontrol_msgs::GetFeature::Response& response);
bool ServiceSetResolution(micro_epsilon_scancontrol_msgs::SetResolution::Request& request,
micro_epsilon_scancontrol_msgs::SetResolution::Response& response);
bool ServiceGetResolution(micro_epsilon_scancontrol_msgs::GetResolution::Request& request,
micro_epsilon_scancontrol_msgs::GetResolution::Response& response);
bool ServiceGetAvailableResolutions(micro_epsilon_scancontrol_msgs::GetAvailableResolutions::Request& request,
micro_epsilon_scancontrol_msgs::GetAvailableResolutions::Response& response);
bool ServiceInvertZ(std_srvs::SetBool::Request& request, std_srvs::SetBool::Response& response);
bool ServiceInvertX(std_srvs::SetBool::Request& request, std_srvs::SetBool::Response& response);

private:
// Profile functions
int Profile2PointCloud();
// Configuration storage
struct
{
std::string frame_id;
std::string model;
std::string serial;
std::string interface;
std::string topic_name;
int resolution;
int pp_start_point;
int pp_start_point_data;
int pp_point_count;
int pp_point_data_width;
} config_;

bool initialized_ = false;
bool transfer_active_ = false;

// ROS handles
ros::NodeHandle nh_;
ros::NodeHandle private_nh_;
ros::Publisher publisher;
ros::ServiceServer get_feature_srv;
ros::ServiceServer set_feature_srv;
ros::ServiceServer get_resolution_srv;
ros::ServiceServer set_resolution_srv;
ros::ServiceServer get_available_resolutions_srv;
ros::ServiceServer invert_z_srv;
ros::ServiceServer invert_x_srv;

// Driver objects
std::unique_ptr<CInterfaceLLT> device_interface_ptr;
TScannerType device_type;
TPartialProfile t_partial_profile_;
std::vector<guint8> profile_buffer;
std::vector<double> value_x, value_z;
int lost_values;
unsigned int lost_profiles;

point_cloud_t::Ptr point_cloud_msg;

std::map<std::string, unsigned int> feature2id = {
{ "FEATURE_FUNCTION_SERIAL", FEATURE_FUNCTION_SERIAL },
{ "FEATURE_FUNCTION_PEAKFILTER_WIDTH", FEATURE_FUNCTION_PEAKFILTER_WIDTH },
{ "FEATURE_FUNCTION_PEAKFILTER_HEIGHT", FEATURE_FUNCTION_PEAKFILTER_HEIGHT },
{ "FEATURE_FUNCTION_FREE_MEASURINGFIELD_Z", FEATURE_FUNCTION_FREE_MEASURINGFIELD_Z },
{ "FEATURE_FUNCTION_FREE_MEASURINGFIELD_X", FEATURE_FUNCTION_FREE_MEASURINGFIELD_X },
{ "FEATURE_FUNCTION_DYNAMIC_TRACK_DIVISOR", FEATURE_FUNCTION_DYNAMIC_TRACK_DIVISOR },
{ "FEATURE_FUNCTION_DYNAMIC_TRACK_FACTOR", FEATURE_FUNCTION_DYNAMIC_TRACK_FACTOR },
{ "FEATURE_FUNCTION_CALIBRATION_0", FEATURE_FUNCTION_CALIBRATION_0 },
{ "FEATURE_FUNCTION_CALIBRATION_1", FEATURE_FUNCTION_CALIBRATION_1 },
{ "FEATURE_FUNCTION_CALIBRATION_2", FEATURE_FUNCTION_CALIBRATION_2 },
{ "FEATURE_FUNCTION_CALIBRATION_3", FEATURE_FUNCTION_CALIBRATION_3 },
{ "FEATURE_FUNCTION_CALIBRATION_4", FEATURE_FUNCTION_CALIBRATION_4 },
{ "FEATURE_FUNCTION_CALIBRATION_5", FEATURE_FUNCTION_CALIBRATION_5 },
{ "FEATURE_FUNCTION_CALIBRATION_6", FEATURE_FUNCTION_CALIBRATION_6 },
{ "FEATURE_FUNCTION_CALIBRATION_7", FEATURE_FUNCTION_CALIBRATION_7 },
{ "FEATURE_FUNCTION_LASERPOWER", FEATURE_FUNCTION_LASERPOWER },
{ "FEATURE_FUNCTION_MEASURINGFIELD", FEATURE_FUNCTION_MEASURINGFIELD },
{ "FEATURE_FUNCTION_TRIGGER", FEATURE_FUNCTION_TRIGGER },
{ "FEATURE_FUNCTION_SHUTTERTIME", FEATURE_FUNCTION_SHUTTERTIME },
{ "FEATURE_FUNCTION_IDLETIME", FEATURE_FUNCTION_IDLETIME },
{ "FEATURE_FUNCTION_PROCESSING_PROFILEDATA", FEATURE_FUNCTION_PROCESSING_PROFILEDATA },
{ "FEATURE_FUNCTION_THRESHOLD", FEATURE_FUNCTION_THRESHOLD },
{ "FEATURE_FUNCTION_MAINTENANCEFUNCTIONS", FEATURE_FUNCTION_MAINTENANCEFUNCTIONS },
{ "FEATURE_FUNCTION_REARRANGEMENT_PROFILE", FEATURE_FUNCTION_REARRANGEMENT_PROFILE },
{ "FEATURE_FUNCTION_PROFILE_FILTER", FEATURE_FUNCTION_PROFILE_FILTER },
{ "FEATURE_FUNCTION_RS422_INTERFACE_FUNCTION", FEATURE_FUNCTION_RS422_INTERFACE_FUNCTION },
{ "FEATURE_FUNCTION_PACKET_DELAY", FEATURE_FUNCTION_PACKET_DELAY },
{ "FEATURE_FUNCTION_SHARPNESS", FEATURE_FUNCTION_SHARPNESS },
{ "FEATURE_FUNCTION_TEMPERATURE", FEATURE_FUNCTION_TEMPERATURE },
{ "FEATURE_FUNCTION_SATURATION", FEATURE_FUNCTION_SATURATION },
{ "FEATURE_FUNCTION_CAPTURE_QUALITY", FEATURE_FUNCTION_CAPTURE_QUALITY }
};

//
std::list<unsigned int> features_with_corruption_risk = { FEATURE_FUNCTION_LASERPOWER,
FEATURE_FUNCTION_MEASURINGFIELD, FEATURE_FUNCTION_TRIGGER };
};

void NewProfileCallback(const void* data, size_t data_size, gpointer user_data);
void ControlLostCallback(ArvGvDevice* mydevice, gpointer user_data);

} // namespace scancontrol_driver

#endif // _SCANCONTROL_DRIVER_H_
Loading

0 comments on commit 02ba9bc

Please sign in to comment.