Skip to content

Commit

Permalink
Fix : lint fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsooyoung committed Jun 9, 2021
1 parent ee55279 commit 88672fd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 202 deletions.
17 changes: 6 additions & 11 deletions gcamp_gazebo/launch/diffbot_description.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@

from ament_index_python.packages import get_package_share_directory

import launch
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription, DeclareLaunchArgument, ExecuteProcess
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, Command
from launch.substitutions import LaunchConfiguration

from launch_ros.actions import Node

import xacro


def generate_launch_description():
use_sim_time = LaunchConfiguration('use_sim_time', default='false')

package_name = "gcamp_gazebo"
robot_file = "diffbot.urdf"
rviz_file = "description.rviz"
package_name = 'gcamp_gazebo'
robot_file = 'diffbot.urdf'
rviz_file = 'description.rviz'

urdf = os.path.join(get_package_share_directory(package_name), "urdf", robot_file)
rviz = os.path.join(get_package_share_directory(package_name), "rviz", rviz_file)
urdf = os.path.join(get_package_share_directory(package_name), 'urdf', robot_file)
rviz = os.path.join(get_package_share_directory(package_name), 'rviz', rviz_file)

robot_desc = open(urdf, 'r').read()

Expand Down
48 changes: 19 additions & 29 deletions py_action_pkg/py_action_pkg/robot_controller.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#!/usr/bin/env/ python3
# !/usr/bin/env/ python3

import sys
import time
import math
import rclpy
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
import numpy as np

import rclpy
from rclpy.node import Node

from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry


# https://gist.github.com/salmagro/2e698ad4fbf9dae40244769c5ab74434
def euler_from_quaternion(quaternion):
"""
Converts quaternion (w in last place) to euler roll, pitch, yaw
Return Converted euler roll, pitch, yaw from quaternion (w in last place).
quaternion = [x, y, z, w]
Bellow should be replaced when porting for ROS 2 Python tf_conversions is done.
"""
Expand All @@ -40,19 +36,15 @@ def euler_from_quaternion(quaternion):


class RobotController(Node):
"""
Create an RobotController class, which is a subclass of the Node class.
"""
"""Create an RobotController class, which is a subclass of the Node class."""

def __init__(self):
"""
Class constructor to set up the node
"""
"""Class constructor to set up the node."""
# Initiate the Node class's constructor and give it a name
super().__init__("robot_controller")
super().__init__('robot_controller')

"""
Clockwise Heading Used
Clockwise Heading Used.
0 : Upper
1 : Right
2 : Down
Expand All @@ -71,48 +63,46 @@ def __init__(self):
# Create the subscriber. This subscriber will receive an LaserScan
# Data from the /diffbot/scan topic. The queue size is 10 messages.
self.laser_sub = self.create_subscription(
LaserScan, "/diffbot/scan", self.laser_sub_cb, self.sub_period
LaserScan, '/diffbot/scan', self.laser_sub_cb, self.sub_period
)

# Receive an Odometry from the /diffbot/odom topic.
self.odom_sub = self.create_subscription(
Odometry,
"/diffbot/odom",
'/diffbot/odom',
self.odom_sub_cb,
self.sub_period,
)

# Create the publisher. This publisher will control robot by
# /diffbot/cmd_vel topic. The queue size is 10 messages.
self.cmd_vel_pub = self.create_publisher(
Twist, "/diffbot/cmd_vel", self.pub_period
Twist, '/diffbot/cmd_vel', self.pub_period
)

# prevent unused variable warning
self.cmd_vel_pub
self.laser_sub
self.odom_sub
self.get_logger().info("==== Robot Control Node Started ====\n")
self.get_logger().info('====Robot Control Node Started ====\n')

def is_ok(self):
return self.ok

def odom_sub_cb(self, data):
orientation = data.pose.pose.orientation
_, _, self.yaw = euler_from_quaternion(orientation)
# print(f"yaw : {self.yaw}")

def laser_sub_cb(self, data):
self.forward_distance = data.ranges[360]
# print(f"Distance : {self.forward_distance}")

def move_robot(self, linear_vel=0.0):
self.twist_msg.linear.x = linear_vel
self.twist_msg.angular.z = 0.0
self.cmd_vel_pub.publish(self.twist_msg)

def stop_robot(self):
print("==== Stop Robot ====")
self.get_logger().info('====Stop Robot ====')
self.twist_msg.linear.x = 0.0
self.twist_msg.angular.z = 0.0
self.cmd_vel_pub.publish(self.twist_msg)
Expand All @@ -124,7 +114,7 @@ def turn_robot(self, angular_vel=0.0):


def turn_robot(rclpy, controller, euler_angle):
print("Robot Turns to Object Angle")
print('Robot Turns to Object Angle')

controller.stop_robot()

Expand All @@ -143,7 +133,7 @@ def turn_robot(rclpy, controller, euler_angle):


def parking_robot(rclpy, controller):
print("Going Forward Until 0.8m Obstacle Detection")
print('Going Forward Until 0.8m Obstacle Detection')

controller.stop_robot()

Expand All @@ -165,7 +155,7 @@ def main(args=None):

while True:
robot_controller.move_robot(1.0)
print(f"{robot_controller.forward_distance}")
robot_controller.get_logger().info(robot_controller.forward_distance)

# parking_robot(rclpy, robot_controller)
# turn_robot(rclpy, robot_controller, math.pi)
Expand All @@ -179,5 +169,5 @@ def main(args=None):
rclpy.shutdown()


if __name__ == "__main__":
if __name__ == '__main__':
main()
162 changes: 0 additions & 162 deletions py_action_pkg/py_action_pkg/test_maze_action_server.py

This file was deleted.

0 comments on commit 88672fd

Please sign in to comment.