Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 오블완
- 티스토리챌린지
- turtlebot3
- 아두이노
- QT
- Visual SLAM
- 인공지능
- ROS2
- Jetson
- Puck LITE
- ubuntu
- 자율탐사
- ROS
- Simulation
- GPS
- SLAM
- 젯슨
- ZED2
- WSL2
- C++
- WSL
- RTK
- 터틀심
- 강화학습
- GUI
- 로봇
- 자율주행
- U-blox
- turtlesim
- Gazebo
Archives
- Today
- Total
직관적인느낌
Simulation_turtlebot3 - Autorace(melodic) - 제어 본문
728x90
반응형
Simulation_turtlebot3 - Autorace(melodic) - 제어
코드 출처
https://github.com/ROBOTIS-GIT/turtlebot3_autorace_2020
실행
roslaunch turtlebot3_gazebo turtlebot3_autorace.launch
roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
roslaunch turtlebot3_autorace_detect detect_lane.launch
roslaunch turtlebot3_autorace_driving turtlebot3_autorace_control_lane.launch
rosrun rqt_reconfigure rqt_reconfigure
주행 제어 파트
roslaunch turtlebot3_autorace_driving turtlebot3_autorace_control_lane.launch
turtlebot3_autorace_control_lane
<launch>
<!-- launch turtlebot3_autorace_detect_lane.launch before launch this file -->
<!-- lane control -->
<node pkg="turtlebot3_autorace_driving" type="control_lane" name="control_lane" output="screen">
<remap from="/control/lane" to="/detect/lane" />
<remap from="/control/cmd_vel" to="/cmd_vel" />
</node>
</launch>
control_lane
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright 2018 ROBOTIS CO., LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
# Author: Leon Jung, Gilbert, Ashe Kim
import rospy
import numpy as np
from std_msgs.msg import Float64
from geometry_msgs.msg import Twist
class ControlLane():
def __init__(self):
self.sub_lane = rospy.Subscriber('/control/lane', Float64, self.cbFollowLane, queue_size = 1)
self.sub_max_vel = rospy.Subscriber('/control/max_vel', Float64, self.cbGetMaxVel, queue_size = 1)
self.pub_cmd_vel = rospy.Publisher('/control/cmd_vel', Twist, queue_size = 1)
self.lastError = 0
self.MAX_VEL = 0.1
rospy.on_shutdown(self.fnShutDown)
def cbGetMaxVel(self, max_vel_msg):
self.MAX_VEL = max_vel_msg.data
def cbFollowLane(self, desired_center):
center = desired_center.data
error = center - 500
Kp = 0.0025
Kd = 0.007
angular_z = Kp * error + Kd * (error - self.lastError)
self.lastError = error
twist = Twist()
# twist.linear.x = 0.05
twist.linear.x = min(self.MAX_VEL * ((1 - abs(error) / 500) ** 2.2), 0.05)
twist.linear.y = 0
twist.linear.z = 0
twist.angular.x = 0
twist.angular.y = 0
twist.angular.z = -max(angular_z, -2.0) if angular_z < 0 else -min(angular_z, 2.0)
self.pub_cmd_vel.publish(twist)
def fnShutDown(self):
rospy.loginfo("Shutting down. cmd_vel will be 0")
twist = Twist()
twist.linear.x = 0
twist.linear.y = 0
twist.linear.z = 0
twist.angular.x = 0
twist.angular.y = 0
twist.angular.z = 0
self.pub_cmd_vel.publish(twist)
def main(self):
rospy.spin()
if __name__ == '__main__':
rospy.init_node('control_lane')
node = ControlLane()
node.main()
💡 angular_z = Kp * error + Kd * (error - self.lastError)
- PD 제어로 주행하고 있는것을 확인 가능
728x90
반응형
'공학 > ROS' 카테고리의 다른 글
ROS기반 Q필터가 적용된 비선형외란관측기(DOB)를 모바일 로봇 (0) | 2023.03.03 |
---|---|
ROS기반 sliding mode control 파이썬 코드 (0) | 2023.03.02 |
Simulation_turtlebot3 - Autorace(melodic, 18.04) (0) | 2023.03.02 |
SSH로 접속해 Real_turtlebot3 with WSL2(melodic-18.04) (0) | 2023.02.27 |
WSL2 + ROS2 [Simulation_turtlebot3 - Navigation] (터틀봇3 네비게이션) (0) | 2023.02.23 |