Skip to content

Commit

Permalink
Merge pull request #7 from ami-iit/feature/style
Browse files Browse the repository at this point in the history
Enforce C++ and Python code style
  • Loading branch information
diegoferigo authored Oct 5, 2021
2 parents 8cbd4d8 + 72b5c81 commit c669d1a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 25 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Code Style

on:
push:
branches: ["**"]
tags-ignore: ["**"]
pull_request:
workflow_dispatch:

jobs:

clang-format:

name: clang-format
runs-on: ubuntu-latest

steps:

- name: "🔀 Checkout repository"
uses: actions/checkout@v2

- name: "⬇️️ Install dependencies"
run: sudo apt-get install -y --no-install-recommends colordiff

- name: "📝 Format C++"
uses: diegoferigo/gh-action-clang-format@main
id: format
with:
style: file
pattern: |
*.h
*.cpp
- name: "🔍️ Inspect style diff"
if: failure()
run: printf "${{ steps.format.outputs.diff }}" | colordiff

black:

name: black
runs-on: ubuntu-latest

steps:

- name: "🔀 Checkout repository"
uses: actions/checkout@v2

- name: '🐍 Initialize Python'
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: "📝 Black Code Formatter"
uses: psf/black@stable
with:
options: --check --diff --color

isort:

name: isort
runs-on: ubuntu-latest

steps:

- name: "🔀 Checkout repository"
uses: actions/checkout@v2

- name: '🐍 Initialize Python'
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: "📝 isort"
uses: isort/isort-action@master
with:
configuration: --check --diff --color
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ requires = [

[tool.setuptools_scm]
local_scheme = "dirty-tag"

[tool.black]
line-length = 88

[tool.isort]
profile = "black"
multi_line_output = 3
4 changes: 2 additions & 2 deletions python/gazebo_scenario_plugins/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import abc
from typing import Tuple
from dataclasses import dataclass, field
from typing import Tuple

# Default SDF version used in the serialized XML context
SDF_VERSION=1.7
SDF_VERSION = 1.7

# Read the following for more information about dataclasses internals:
# https://florimond.dev/blog/articles/2018/10/reconciling-dataclasses-and-properties-in-python/
Expand Down
3 changes: 2 additions & 1 deletion python/gazebo_scenario_plugins/plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import enum
from dataclasses import dataclass, field
from gazebo_scenario_plugins import plugin

from . import plugin


@dataclass
Expand Down
45 changes: 23 additions & 22 deletions tests/test_actuation_delay.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
import gym
import pytest
import numpy as np
from queue import Queue

import gym
import gym_ignition_models
from gym_ignition import utils
from scenario import core as scenario_core
import numpy as np
import pytest
from gazebo_scenario_plugins import plugins
from gym_ignition import utils
from gym_ignition.utils.scenario import init_gazebo_sim
from scenario import core as scenario_core

# Set the verbosity
utils.logger.set_level(gym.logger.DEBUG)

# Panda PID gains
# https://github.com/mkrizmancic/franka_gazebo/blob/master/config/default.yaml
panda_pid_gains_1000Hz = {
'panda_joint1': scenario_core.PID(50, 0, 20),
'panda_joint2': scenario_core.PID(10000, 0, 500),
'panda_joint3': scenario_core.PID(100, 0, 10),
'panda_joint4': scenario_core.PID(1000, 0, 50),
'panda_joint5': scenario_core.PID(100, 0, 10),
'panda_joint6': scenario_core.PID(100, 0, 10),
'panda_joint7': scenario_core.PID(10, 0.5, 0.1),
'panda_finger_joint1': scenario_core.PID(100, 0, 50),
'panda_finger_joint2': scenario_core.PID(100, 0, 50),
"panda_joint1": scenario_core.PID(50, 0, 20),
"panda_joint2": scenario_core.PID(10000, 0, 500),
"panda_joint3": scenario_core.PID(100, 0, 10),
"panda_joint4": scenario_core.PID(1000, 0, 50),
"panda_joint5": scenario_core.PID(100, 0, 10),
"panda_joint6": scenario_core.PID(100, 0, 10),
"panda_joint7": scenario_core.PID(10, 0.5, 0.1),
"panda_finger_joint1": scenario_core.PID(100, 0, 50),
"panda_finger_joint2": scenario_core.PID(100, 0, 50),
}


def test_actuation_delay():

# Get the simulator and the world
gazebo, world = init_gazebo_sim(step_size=0.001,
real_time_factor=1.0,
steps_per_run=1)
gazebo, world = init_gazebo_sim(
step_size=0.001, real_time_factor=1.0, steps_per_run=1
)

# Get the panda urdf
panda_urdf = gym_ignition_models.get_model_file("panda")

# Insert the panda arm
model_name = "panda"
assert world.insert_model(panda_urdf,
scenario_core.Pose_identity(),
model_name)
assert world.insert_model(panda_urdf, scenario_core.Pose_identity(), model_name)

# Get the model
panda = world.get_model(model_name)
Expand Down Expand Up @@ -77,8 +76,10 @@ def test_actuation_delay():

# Build a new reference for a single joint
q0_j1 = joint1.position()
q_j1 = (0.9 * joint1_range / 2 * np.sin(2 * np.pi * 0.33 * t)
for t in np.arange(start=0, stop=10.0, step=gazebo.step_size()))
q_j1 = (
0.9 * joint1_range / 2 * np.sin(2 * np.pi * 0.33 * t)
for t in np.arange(start=0, stop=10.0, step=gazebo.step_size())
)

# Create a queue
queue = Queue(maxsize=actuation_delay.delay)
Expand Down

0 comments on commit c669d1a

Please sign in to comment.