• Stars
    star
    226
  • Rank 176,488 (Top 4 %)
  • Language
  • License
    BSD 3-Clause "New...
  • Created almost 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Auto formatting script for ROS C++ Style Guidelines

ROSCpp Code Format

Why waste your valuable development time formatting code manually when we are trying to build amazing robots?

The repo contains an auto formatting script for the ROS C++ Style Guidelines.

Updated June 2020 to support Ubuntu 18.04 / ROS Melodic.

Setup

  • Install clang_format:

    sudo apt-get install -y clang-format-3.9

  • Then symlink or copy in the root of your catkin workspace the file .clang-format, located in this repo. You can save this file from this link. For example, place it on your computer here:

    ~/catkin_ws/.clang-format

  • If you are interested in improving this configuration file, we recommend you checkout the git repo and symlink, e.g.:

    ln -s ~/roscpp_code_format/.clang-format ~/catkin_ws/.clang-format

  • Now any file inside your catkin workspace will be formatted with the ROS style guidelines described in this config file

Usage

You can run clang_format in several ways:

Command Line

Format single file:

clang-format-3.9 -i -style=file MY_ROS_NODE.cpp

Format entire directory recursively including subfolders:

find . -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-3.9 -i -style=file $1

Emacs Editor Configuration

In your ~/.emacs config file, add the following:

Format your source code if its in some directory such as the catkin_ws (feel free to change keywords catkin_ws):

(defun run-ros-clang-format ()
  "Runs clang-format on cpp,h files in catkin_ws/ and reverts buffer."
  (interactive)
  (and
   (string-match "/catkin_ws/.*\\.\\(h\\|cpp\\)$" buffer-file-name)
   (save-some-buffers 'no-confirm)
   (shell-command (concat "clang-format-3.9 -style=file -i " buffer-file-name))
   (message (concat "Saved and ran clang-format on " buffer-file-name))
   (revert-buffer t t t)
))

Set a keyboard shortcut to run, such as F12

(global-set-key [f12] 'run-ros-clang-format)

Atom Editor Configuration

Install the clang-format package via the Atom package manager or apm install clang-format.

In the package settings set clang-format-3.9 as your executable and point 'Style' to your .clang_format file.

Usage with Qt

To set up Qt Creator to use this clang formatting follow the instructions here.

On the Clang Format Panel change the Clang Format command to 'clang-format-4.0'. After this, choose Use predefined style: File, and then create a soft link on the root of your files workspace (where all your code is) pointing to this file and with the same name (.clang-format).

It is recomended to deactivate the Enable auto format on file save option and create a keyboard shortcut

Usage with Sublime

Installation Package Control in Sublime:

https://packagecontrol.io/installation

Configuration Clang format in Sublime:

https://github.com/rosshemsley/SublimeClangFormat/blob/master/README.md

Usage with Visual Studio Code

Install the C/C++ extension.

Put the .clang-format file in your workspace.

Select Format Document in the right-click context menu, or use the shortcut Ctrl+Shift+I.

This explanation and more here.

Exceptions to clang-format

Occationally the auto formatting used by clang-format might not make sense e.g. for lists of items that are easier to read on separate lines. It can be overwritten with the commands:

// clang-format off
... some untouched code
// clang-format on

Use this sparingly though.

More Repositories

1

rviz_visual_tools

C++ API wrapper for displaying shapes and meshes in Rviz
C++
747
star
2

ros_control_boilerplate

Provides a simple simulation interface and template for setting up a hardware interface for ros_control
C++
244
star
3

generate_parameter_library

Declarative ROS 2 Parameters
Python
228
star
4

data_tamer

C++ library for Fearless Timeseries Logging
C++
196
star
5

deep_grasp_demo

Deep learning for grasp detection within MoveIt.
C++
104
star
6

abb_ros2

C++
86
star
7

pick_ik

Inverse Kinematics solver for MoveIt
C++
68
star
8

topic_based_ros2_control

ros2_control hardware interface that uses topics to command the robot and publish its state
C++
58
star
9

tf_visual_tools

Manually manipulate TFs in ROS using this Rviz plugin.
C++
51
star
10

ros2_robotiq_gripper

C++
48
star
11

RSL

ROS Support Library
C++
46
star
12

rosparam_shortcuts

Quickly load variables from rosparam with good command line error checking.
C++
38
star
13

descartes_capability

Drop-in capability for MoveIt's move_group that uses Descartes
C++
37
star
14

ros_testing_templates

C++
28
star
15

tf_keyboard_cal

Allows manual control of a TF through the keyboard or interactive markers
C++
27
star
16

quick-ros-install

Instant install script for ROS
Shell
25
star
17

ros2_package_template

A ROS2 package cookiecutter template
C++
22
star
18

moveit_studio_ur_ws

Workspace containing example MoveIt Studio configuration packages.
C++
21
star
19

UR10e_welding_demo

C++
21
star
20

crac_build_system

The unified Catin / ROSBuild / Ament / Colcon build system
Shell
21
star
21

snowbot_operating_system

The weather outside is frightful
C++
18
star
22

moveit_sim_controller

A simulation interface for a hardware interface for ros_control, and loads default joint values from SRDF
C++
14
star
23

ik_benchmarking

Utilities for IK solver benchmarking with MoveIt 2
C++
13
star
24

moveit_shelf_picking

Benchmarking suite for dual arm manipulation
C++
12
star
25

ros2_epick_gripper

ROS2 driver for the Robotiq EPick gripper.
C++
11
star
26

ROStoROS2

A living documentation of automate-able and manual steps for porting ROS packages to ROS2
10
star
27

moveit_studio_sdk

MoveIt Studio SDK
Python
9
star
28

trackjoint

C++
9
star
29

ros_reflexxes

Reflexxes Type II provides acceleration-limited trajectory smoothing
C++
9
star
30

ruckig_traj_smoothing

A jerk-limited trajectory smoothing plugin
8
star
31

graph_msgs

ROS messages for publishing graphs of different data types
CMake
8
star
32

launch_param_builder

Python library for loading parameters in launch files
Python
8
star
33

moveit_boilerplate

Basic functionality for easily building applications on MoveIt! in C++
C++
6
star
34

stretch_moveit_plugins

Package for the inverse kinematics solver for stretch from Hello Robot Inc.
C++
5
star
35

tool_changing

MoveGroup capability to dynamically change end-effectors
C++
4
star
36

test_examples

Examples of different test techniques (integration, unit, gtest, dependency injection...)
Python
4
star
37

moveit_studio_example_behaviors

C++
4
star
38

CMakeGuidelines

Collection of useful cmake tips
4
star
39

moveit_differential_ik_plugin

A plugin to provide differential kinematics. Used in admittance control.
C++
4
star
40

pronto

C++
4
star
41

light_painting_demo

C++
3
star
42

cpp_polyfills

Vendored Pollyfills for C++
C++
3
star
43

ocs2_robotic_assets

CMake
2
star
44

rqt2_setup

2
star
45

Moveit2_Tutorials

test deployment of moveit 2 tutorials
HTML
2
star
46

cartesian_msgs-release

1
star
47

moveit_sim_controller-release

1
star
48

ros_control_boilerplate-release

1
star
49

cirs_girona_cala_viuda

ROS2 version of girona cala viuda dataset
Python
1
star
50

picknik_controllers

PickNik's ros2_controllers
C++
1
star
51

rviz_visual_tools-release

1
star
52

rosparam_shortcuts-release

1
star
53

tf_keyboard_cal-release

1
star
54

rqt2_demo_nodes

Python
1
star
55

picknik_accessories

Various accessories used for studio configuration packages
CMake
1
star
56

moveit_studio_kortex_ws

C++
1
star
57

moveit_camera_survey

Code for survey of RGB-D cameras for manipulation
Dockerfile
1
star
58

picknik_ur5_moveit_config

CMake
1
star
59

beta_moveit_website

Demo site for major changes to moveit.ros.org. Found at http://moveit_beta.picknik.ai/
JavaScript
1
star
60

robot_on_rails

MoveIt Studio package for a UR robot on a linear rail
C++
1
star
61

c3pzero

Python
1
star
62

picknik_ament_copyright

Python
1
star
63

boost_sml

State Machine Library ROS Package
C++
1
star
64

cartesian_msgs

Experimental messages for sending Cartesian commands to a robot.
CMake
1
star