Skip to content
Snippets Groups Projects
Commit 6a88a255 authored by goldar's avatar goldar
Browse files
parents d8ad0174 a407ede0
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 2.8.3)
project(assignment10)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs # Or other packages containing msgs
# )
################################################
## Declare ROS dynamic reconfigure parameters ##
################################################
## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed
## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES assignment10
# CATKIN_DEPENDS other_catkin_pkg
# DEPENDS system_lib
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
# ${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/assignment10.cpp
# )
## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/assignment10_node.cpp)
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
# ${catkin_LIBRARIES}
# )
#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_assignment10.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
<?xml version="1.0"?>
<package format="2">
<name>assignment10</name>
<version>0.0.0</version>
<description>The assignment10 package</description>
<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="joern@todo.todo">joern</maintainer>
<!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>TODO</license>
<!-- Url tags are optional, but multiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<!-- <url type="website">http://wiki.ros.org/assignment10</url> -->
<!-- Author tags are optional, multiple are allowed, one per tag -->
<!-- Authors do not have to be maintainers, but could be -->
<!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
<!-- The *depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
<!-- <depend>roscpp</depend> -->
<!-- Note that this is equivalent to the following: -->
<!-- <build_depend>roscpp</build_depend> -->
<!-- <exec_depend>roscpp</exec_depend> -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<!-- Use build_export_depend for packages you need in order to build against this package: -->
<!-- <build_export_depend>message_generation</build_export_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use exec_depend for packages you need at runtime: -->
<!-- <exec_depend>message_runtime</exec_depend> -->
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<!-- Use doc_depend for packages you need only for building documentation: -->
<!-- <doc_depend>doxygen</doc_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
</export>
</package>
#!/usr/bin/env python
# coding=utf-8
import rospy
from geometry_msgs.msg import PoseWithCovariance,Pose,Point,Quaternion
from autominy_msgs.msg import NormalizedSteeringCommand,SteeringCommand
from std_msgs.msg import Header
from nav_msgs.msg import Odometry
from tf.transformations import euler_from_quaternion
import numpy as np
import math
class PID():
#yaw=0 := Richtung Pokale, yaw=pi := Richtung Tür-Seite
def __init__(self,yaw_angle,car_id=8):
print('init')
self.angles=[]#enthält die Fehler
self.wanted_yaw=yaw_angle
self.steer_pub=rospy.Publisher('/actuators/steering_normalized', NormalizedSteeringCommand,queue_size=10)
rospy.init_node("pid")
rospy.Subscriber("/communication/gps/"+str(car_id),Odometry,self.onPosition)
self.steering_sub = rospy.Subscriber("/control/steering", SteeringCommand, self.onSteering, queue_size=1)
print('init finish')
rospy.spin()
def onPosition(self,odometry):
quaternion_msg=odometry.pose.pose.orientation
quaternion=(quaternion_msg.x,quaternion_msg.y,quaternion_msg.z,quaternion_msg.w)
_,_,yaw=euler_from_quaternion(quaternion)
error=self.wanted_yaw-yaw
if error >np.pi:
error+=np.pi*2
elif error<-np.pi:
error-=np.pi*2
#abl ist die Änderung des Fehlers, also die Ableitung
try:
abl=(error)-self.angles[-1]
except:
abl=0
self.angles.append(error)
print('yaw:',yaw)
p,d,i=2,0.2,0#rospy.get_param("/pid/p"),rospy.get_param("/pid/d"),rospy.get_param("/pid/i")
#u= p*Fehler + d*Ableitung + i*Integral über alle bisherigen Fehler
u=p*(error)+d*(abl)+i*np.trapz(np.asarray(self.angles))
print('u:',u)
#u als SteeringCommand publishen
h=Header()
h.stamp=rospy.Time.now()
steer_com=NormalizedSteeringCommand(h,u)
self.steer_pub.publish(steer_com)
def onSteering(self, msg):
self.wanted_yaw = msg.value
if __name__=='__main__':
PID(0)
File added
File added
#!/usr/bin/env python
# coding=utf-8
import rospy
import math
import numpy as np
from splines import Map
from nav_msgs.msg import Odometry
from autominy_msgs.msg import SteeringCommand
from std_msgs.msg import UInt8
class Control():
def __init__(self):
self.lane1=Map(np.load('lane1.npy'),1)
self.lane2=Map(np.load('lane2.npy'),2)
self.target_lane=self.lane1
rospy.init_node("control")
rospy.Subscriber("/sensors/localization/filtered_map", Odometry, self.on_localization, queue_size=1)
rospy.Subscriber("/control/lane", UInt8, self.on_lane, queue_size=1)
self.steering_pub = rospy.Publisher("/control/steering", SteeringCommand, queue_size=10)
def on_lane(self,msg):
if msg.data==1:
self.target_lane=self.lane1
elif msg.data==2:
self.target_lane=self.lane2
def on_localization(self,msg):
start=msg.pose.pose.position
target=self.target_lane.closestPoint(start,lookahead=0.75)
self.target_lane.showMarker(target)
dx=target.x-start.x
dy=target.y-start.y
yaw=np.arctan2(dy,dx)
com=SteeringCommand()
com.value=yaw
print (math.degrees(yaw))
self.steering_pub.publish(com)
if __name__=='__main__':
Control()
rospy.spin()
#!/usr/bin/env python
# coding=utf-8
import rospy
import scipy.interpolate
import numpy as np
from visualization_msgs.msg import Marker
from geometry_msgs.msg import Point,Pose,Quaternion,PointStamped
from std_msgs.msg import Header
from std_msgs.msg import ColorRGBA
import threading
class Map():
def __init__(self,samples,id,num_points=20):
self.id=id
size=len(samples)
step=size//num_points
indices=[i*step for i in range(num_points)]
indices.append((len(samples)-1))
self.samples=samples
print(indices)
self.x_spline=scipy.interpolate.CubicSpline(samples[indices,0],samples[indices,1])
self.y_spline=scipy.interpolate.CubicSpline(samples[indices,0],samples[indices,2])
self.publisher=rospy.Publisher('/visualization/map', Marker,queue_size=10)
#rospy.init_node("splineMap",anonymous=True)
def closestPoint(self,p,lookahead=0.0,initial_step=0.1,cutoff_change=0.001):
target=np.array([p.x,p.y])
max_u=self.samples[-1,0]
u=0
distance=np.linalg.norm([self.x_spline(u),self.y_spline(u)]-target)
u=initial_step
pos_distance=np.linalg.norm([self.x_spline(u),self.y_spline(u)]-target)
u=max_u-initial_step
neg_distance=np.linalg.norm([self.x_spline(u),self.y_spline(u)]-target)
if neg_distance<distance:
step=-initial_step
change=distance-neg_distance
prev_distance=neg_distance
else:
step=initial_step
u=initial_step
change=distance-pos_distance
prev_distance=pos_distance
u+=step
while abs(change)>cutoff_change:
distance=np.linalg.norm([self.x_spline(u),self.y_spline(u)]-target)
change=prev_distance-distance
prev_distance=distance
if change<0:
step=-step/2
u+=step
u+=lookahead
if u>max_u:
u-=max_u
return Point(self.x_spline(u),self.y_spline(u),0)
def show_closest_point(self,msg,lookahead=0.0):
p=msg.point
closest=self.closestPoint(p,lookahead=lookahead)
print('closest Point',closest.x,closest.y)
self.showMarker(closest)
def showMarker(self,point):
h=Header()
h.stamp=rospy.Time.now()
h.frame_id='map'
marker=Marker()
marker.header=h
marker.ns='closestPoint'
marker.id=self.id
marker.type=Marker.SPHERE
marker.action=Marker.ADD
p=Pose(point,Quaternion(0.0,0.0,0.0,1.0))
marker.pose=p
marker.scale.x = 0.5
marker.scale.y = 0.5
marker.scale.z = 0.5
marker.color.r = 0.0
marker.color.g = 1.0
marker.color.b = 0.0
marker.color.a = 1.0
marker.lifetime = rospy.Duration()
self.publisher.publish(marker)
\documentclass {article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{hyperref}
\usepackage{float}
\fancyhf{}
\lhead{Robotik\\Übung 9}
\rhead{bearbeitet von Darius Golagha und Jörn Andreesen}
\begin{document}
\section*{Aufgabe 1-2}
Der verwendete Code findet sich hier:
\url{https://git.imp.fu-berlin.de/joea95/catkin_ws_team_otter/tree/master/src/assignment10/src}
\end{document}
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment