Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Gazebo Simulator #44

Merged
merged 14 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ logs/

# Catkin ignore files
CATKIN_IGNORE

# gazebo error msgs
core.*
1 change: 0 additions & 1 deletion src/CMakeLists.txt

This file was deleted.

69 changes: 69 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake

cmake_minimum_required(VERSION 3.0.2)

project(Project)

set(CATKIN_TOPLEVEL TRUE)

# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
RESULT_VARIABLE _res
OUTPUT_VARIABLE _out
ERROR_VARIABLE _err
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
# searching fot catkin resulted in an error
string(REPLACE ";" " " _cmd_str "${_cmd}")
message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()

# include catkin from workspace or via find_package()
if(_res EQUAL 0)
set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
# include all.cmake without add_subdirectory to let it operate in same scope
include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
add_subdirectory("${_out}")

else()
# use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
# or CMAKE_PREFIX_PATH from the environment
if(NOT DEFINED CMAKE_PREFIX_PATH)
if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
if(NOT WIN32)
string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
else()
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
endif()
endif()
endif()

# list of catkin workspaces
set(catkin_search_path "")
foreach(path ${CMAKE_PREFIX_PATH})
if(EXISTS "${path}/.catkin")
list(FIND catkin_search_path ${path} _index)
if(_index EQUAL -1)
list(APPEND catkin_search_path ${path})
endif()
endif()
endforeach()

# search for catkin in all workspaces
set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
find_package(catkin QUIET
NO_POLICY_SCOPE
PATHS ${catkin_search_path}
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
unset(CATKIN_TOPLEVEL_FIND_PACKAGE)

if(NOT catkin_FOUND)
message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
endif()
endif()

catkin_workspace()
24 changes: 24 additions & 0 deletions src/simulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Simulator nodes
This is a gazebo simulation of a racecar in a cone/wall/track environment. Control the racecar through `/racecar_cmd`.
Run with `roslaunch racecar_gazebo cones.launch`.

Get laser scans from `/scan`. Get rgb image from `/camera/rgb/image_rect_color`. Get depth from `/camera/depth/image_raw`

### gazebo
Contains the models for each scene, most importantly cones.world.
Launching a world will also load all other required features:
- racecar_description
- gazebo
- joint controllers
- image publishers

Execute the cones.launch file to launch the simulator as a whole.

### racecar_description
`xacro` files and meshes for the racecar

### control
Sets up the joint controllers, and state publishers for each joint.

### basement
Some unrelated files I found during cleanup that may be useful later
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/simulator/basement/maps/basement_hallways_10cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
image: basement_hallways_10cm.png
resolution: 0.100000
origin: [-30.000000, -30.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/simulator/basement/maps/basement_hallways_5cm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
image: basement_hallways_5cm.png
resolution: 0.050000
origin: [-30.000000, -30.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

Binary file added src/simulator/basement/maps/short-course-33.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/simulator/basement/maps/short-course-33.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
image: short-course-33.png
resolution: 0.025000
origin: [-11.50000, -5.000000, -0.090000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

26 changes: 26 additions & 0 deletions src/simulator/basement/readimage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/python

import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import cv2

class worker:

def __init__(self):

self.bridge = CvBridge()
rospy.Subscriber('/camera/zed/rgb/image_rect_color',Image,self.callback_SaveImage)
rospy.spin()

def callback_SaveImage(self,data):
print('save calisti')
cv2_img = self.bridge.imgmsg_to_cv2(data, "bgr8")
cv2.imwrite('camera_image.jpeg', cv2_img)


if __name__ == '__main__':
try:
rospy.init_node('racecar_readimage',anonymous=True)
w = worker()
except rospy.ROSInterruptException: pass
59 changes: 59 additions & 0 deletions src/simulator/basement/readlidar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/python

import rospy
from std_msgs.msg import Float32
from sensor_msgs.msg import LaserScan
from dtmessage.msg import simple_dist

from numpy import inf

class worker:

def __init__(self):
rospy.Subscriber('/scan',LaserScan,self.callback_scan)

# -- "Different topics with float32" --
#self.pubLeftDist = rospy.Publisher('/readlidar/left_dist', Float32,queue_size=10)
#self.pubCenterDist = rospy.Publisher('/readlidar/center_dist', Float32,queue_size=10)
#self.pubRightDist = rospy.Publisher('/readlidar/right_dist', Float32,queue_size=10)
# -- "Different topics with float32" --

# -- "Different topics with custom msg" --
self.pub = rospy.Publisher('/readlidar',simple_dist,queue_size=10)
# -- "Different topics with custom msg" --

print("racecar_readlidar is running")
rospy.spin()

def callback_scan(self,data):
left = min(data.ranges[90:150])
center = min(data.ranges[150:230])
right = min(data.ranges[230:270])

if(left == inf):
left = 18;
if(center == inf):
center = 18;
if(right == inf):
right = 18;

# -- "Different topics with float32" --
#self.pubLeftDist.publish(left)
#self.pubCenterDist.publish(center)
#self.pubRightDist.publish(right)
# -- "Different topics with float32" --

# -- "Different topics with custom msg" --
data = simple_dist()
data.left = left
data.center = center
data.right = right
self.pub.publish(data)
# -- "Different topics with custom msg" --


if __name__ == '__main__':
try:
rospy.init_node('racecar_readlidar',anonymous=True)
w = worker()
except rospy.ROSInterruptException: pass
181 changes: 181 additions & 0 deletions src/simulator/control/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
cmake_minimum_required(VERSION 2.8.3)
project(control)

## 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 run_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 run_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 run_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 you 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 control
# 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)

## Declare a C++ library
# add_library(control
# src/${PROJECT_NAME}/control.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(control ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
# add_executable(control_node src/control_node.cpp)

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(control_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
# target_link_libraries(control_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 and/or libraries for installation
# install(TARGETS control control_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_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_control.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)
Loading