Forstinger Miriam
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # ROS (Robot Operating System) ## Cheat Sheet http://github.com/ros/cheatsheet/releases/download/0.0.1/ROScheatsheet_catkin.pdf ## ROS Workspace Environment ### Overview Defines context for the current workspace ### Load default workspace ``` source /opt/ros/indigo/setup.bash ``` ### Overlay your *catkin* workspace ``` cd ~/catkin_ws source devel/setup.bash ``` ### Check workspace ``` echo $ROS_PACKAGE_PATH ``` ## ROS Master ### Overview * Manages the communication between nodes * Every node registers at startup with the master ### Start Master ``` roscore ``` ## ROS Nodes ### Overview * Single purpose, executable program * Individually compiled, executed and managed * Organized in packages ### Run a node ``` rosrun package_name node_name ``` ### See active nodes ``` rosnode list ``` ### Retrieve information about a node ``` rosnode info node_name ``` ## ROS Topics ### Overview * Nodes communicate over topics * Nodes can publish or subscribe to a topic * Topic is a name for a stream of messages ### List active topics ``` rostopic list ``` ### Subscribe and print contents of a topic ``` rostopic echo /topic ``` ### Show information about a topic ``` rostopic info /topic ``` ### Analayze the frequency ``` rostopic hz /topic ``` ## ROS Messages ### Overview * Data structure defining the *type* of a topic * Compromised of a nested structure of integers, floats, booleans, strings etc. and arrays of objects * Defined in *.msg files ### See type of a topic ``` rostopic type /topic ``` ### Publish a message to a topic ``` rostopic pub /topic type args ``` ## catkin Build System ``` catkin_make ``` ### Navigate to catkin workspace ``` cd ~/catkin_ws ``` ### Build package ``` catkin build package_name ``` ### !! If you build a new package -> update your environment !! ``` source devel/setup.bash ``` ### Clean entire build and devel space ``` catkin clean ``` ### Check catkin workspace setup ``` catkin config ``` ## ROS Launch ### Overview * *launch* is a tool for launching multiple nodes * are written in SML as *.launch files * launch starts automatically a roscore, if it is not running yet ### Start a launch file ``` roslaunch file_name.launch ``` ### Start launch file from a package ``` roslaunch package_name file_name.launch ``` ### See content of the launch file ``` rosed file_name.launch ``` ### File Structur Example ``` <launch> <node name="node_name" pkg="package_name" type="listener/talker" output="screen"/> <node name="node_name" pkg="package_name" type="listener/talker" output="screen"/> </launch> ``` Explanation * launch root element of the launch file * node each < node > tag specifies a node to be launched * name name of the node * pkg package containing the node * type type of the node, there must be a corresponding executable with the same name * output specifies where to output log messages(screen: console, log: log file) ### Arguments ``` <arg name="arg_name" default="default_value"/> ``` Example ``` <arg name="use_sim_time" default="true"/> ``` #### Use arguments in launch a file ``` $(arg arg_name) ``` Example ``` if="$(arg use_sim_time)" ``` #### Launching arguments can be set with ``` roslaunch launch_file.launch arg_name:=value ``` ### Including Other Launch Files #### Include other launch files ``` <include file="package_name"/> ``` #### Find the system path to other packages ``` $(find package_name) ``` #### Pass arguments to the included file ``` <arg name="arg_name" value="value"/> ``` ## ROS Packages * ROS software is organized into packages, which can contain source code, launch files, configuartion files, message definitions, data and documentation * A packge that builds up on/requires other packages, declares these as dependencies ``` catkin_create_pkg package_name {dependencies} ``` ### CMakeLists.xml ``` cmake_minimum_required(VERSION 2.8.3) project(ros_package_template) ## Use C++11 add_definitions(--std=c++11) ## Find catkin macros and libraries find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs ) catkin_package( INCLUDE_DIRS include #LIBRARIES CATKIN_DEPENDS roscpp sensor_msgs #DEPENDS ) include_directories(include ${catkin_INCLUDE_DIRS}) add_executable(${PROJECT_NAME} src/${PROJECT_NAME}_node.cpp src/name.cpp) target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES}) ``` * ```project(ros_package_template)``` Use the same name as in the package.xml * ```add_definitions(--std=c ++ 11)``` use C ++ 11 by default * ```find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs)``` List the packages that your package requires to build (have to be listed in package.xml) * ```catkin_package( INCLUDE_DIRS include CATKIN_DEPENDS roscpp sensor_msgs)``` Specify build export information INCLUDE_DIRS -> Directories with header files LIBRARIES -> Libraries created in this project CATKIN_DEPENDS -> Packages depent projects alsoneed DEPENDS -> System dependencies dependent projects also need (have to be listed in package.xml) * ```include_directories(include ${catkin_INCLUDE_DIRS})``` Specify locations of header files * ```add_executable(${PROJECT_NAME} src/${PROJECT_NAME}_node.cpp src/name.cpp)``` Declare a C++ executable * ```target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})``` Specify libraries to link the execuble against ## Easy ROS C++ Example (Hello World) ``` #include <ros/ros.h> ``` ROS main header file include ``` int main(int argc, char** argv) { ros::init(argc, argv, "hello_world"); ``` ros::init(...) hasto be calle before calling other ROS functions ``` ros::NodeHandle nodeHandle; ``` The node handle is the access point for communications with the ROS system(topics services parameters) ``` ros::Rate loopRate(10); ``` ros::Rate is a helper class to run loops at a desired frequency ``` unsigned int count = 0; while(ros::ok()){ ``` ros::ok() check if a node should continue running *Returns false if SIGINT is received(Ctrl + C) or ros::shutdown() has been called* ``` ROS_INFO_STREAM("Hello World" << count); ``` ROS_INFO() logs messages to the filesystem ``` ros::spinOnce(); ``` ros::spinOnce() processes incoming messages via callbacks ``` loopRate.sleep(); count++; } return 0; } ``` ## Node Handles (Recoommended) * Default (public) node handle: nh_ = ros::NodeHandle(); /namespace/topic * Private node handle: nh_private_ = ros::NodeHandle("~"); /namespace/node/topic * Namespaced node hanle: nh_eth_ = ros::NodeHandle("eth"); /namespace/eth/topic ## Logging ``` /rosout topic ``` In the program: ``` ROS_INFO("Result: %d", result); ROS_INFO_STREAM("Result: "<< result); ``` To see it in the console, set the output configuration to *screen* in the launch file ``` <launch> <node name="node_name" output="screen"/> </launch> ``` ## Subscriber ``` #include "ros/ros.h" #include "std_msgs/String.h" void chatterCallback(const std_msgs::Sring::ConstPtr& msg) { ROS_INFO("message: [%s]", msg->data.c_str()); } int main(int argc, char **argv) { ros::init(argc, argv, "listener"); ros::NodeHandle node; ros::Subscriber subscriber = node.subscribe("chatter",10, chatterCallback); ros::spin(); return 0; } ``` * ```ros::Subscriber subscriber = node.subscribe("chatter",10, chatterCallback);``` Start listeninig to a topic by calling the method subscribe() of the node handle ros:: Subscriber subscriber = nodeHandle.subscribe(topic, queue_size, callback_function); * ```void chatterCallback(const std_msgs::Sring::ConstPtr& msg){ROS_INFO("message: [%s]", msg->data.c_str()); }``` When a message is received -> callback function is called with the contents of the message as argument * ```ros::spin();``` ros::spin() processes callbacks and will not return until the node has been shutdown ## Publisher ``` #include <ros/ros.h> #include <std_msgs/String.h> int main(int argc, char **argv){ ros::init(argc, argv, "name"); ros::NodeHandle nh; ros::Publisher chatterPublisher = nh.advertise<std_msgs::String>("chatter",1); ros::Rate loopRate(10); unsigned int count = 0; while(ros::ok()){ std_msgs::String message; message.data = "hello world" + std::to_string(count); ROS_INFO_STREAM(message.data); chatterPublisher.publish(message); ros::spinOnce(); loopRate.sleep(); count++; } return 0; } ``` * Create a publisher with help of the node handle ``` ros::Publisher publisher = nh.advertise<message_type>(topic, queue_size); ``` * ``` message.data = "hello world" + std::to_string(count);``` Create the message contents ## ROS Parameter Service ### Overview * Nodes use the *parameter server* to store and retrieve parameters at runtime * Best used for static data such as configuration parameters * Parameters can be defined in launch files or separate YAML files * Parameters can be defined in lauch files or separate YAML files ``` <launch> <node name="name" pkg="package" type="node_type"> <rosparam command="load" file="$(find package)/config/config.yaml"/> </node> </launch> ``` ### List all parameters ``` rosparam list ``` ### Get value of a parameter ``` rosparam get parameter_name ``` ### Set value of a parameter ``` rosparam set parameter_name value ``` ## C++ API * Get a parameter in C++ ``` nodeHandle.getParam(parameter_name, variable) ``` This method returns *true* if parameter was found, *false* otherwise * Global and relative parameter access * Global parameter name with preceding / ``` nodeHandle.getParam("/package/camera/left/exposure", variable) ``` * Relative parameter name (relative to the node handle) ``` nodeHandle.getParam("camera/left/exposure", variable) ``` * For parameters, typically use the private node handle ``` ros::NodeHandle("~") ``` ``` ros::NodeHandle nodeHandle("~"); std::string topic; if(!nodeHandle.getParam("topic_name", topic0)){ ROS_ERROR("Could not find topic parameter!") } ``` ## ERRORS * ### RLException: [file_name.launch] is neither a launch file in package [package_name] nor is [package_name] a launch file name The traceback for the exception was written to the log file **Solution:** source ~/.bashrc * ###[gazebo-2] process has died [pid < pidnr >, exit code 255, cmd /opt/ros/melodic/lib/gazebo_ros/gzserver -e ode /home/name/mybot_ws/src/mybot_gazebo/worlds/mybot.world __name:=gazebo __log:=/home/name/.ros/log/3aa819c6-a2f5-11e9-a3ef-080027af97c9/gazebo-2.log]. log file: /home/name/.ros/log/3aa819c6-a2f5-11e9-a3ef-080027af97c9/gazebo-2*.log **Solution** killall gzserver kilall gzclient (and with ctrl+C in the terminal) * ### Add the installation prefix of "tf2_sensor_msgs" to CMAKE_PREFIX_PATH or set "tf2_sensor_msgs_DIR" to a directory containing one of the above files. **Solution** sudo apt-get install ros-melodic-tf2-sensor-msgs * ### RLException: roscore cannot run as another roscore/master is already running. Please kill other roscore/master processes before relaunching. The ROS_MASTER_URI is http://miriam-HP-ProBook-470-G4:11311/ The traceback for the exception was written to the log file **Solution** killall -9 roscore killall -9 rosmaster * ### Could not find a package configuration file provided by "joy" with any of the following names: joyConfig.cmake joy-config.cmake **Solution** $ sudo apt-get install ros-melodic-joy*

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully