![Page 1: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/1.jpg)
+ Docente:Domenico Daniele Bloisi
Nov
embr
e20
17
Corso di RoboticaParte di Laboratorio
Laurea magistrale in ingegneria e scienze informatiche
![Page 2: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/2.jpg)
ROS + git
Esempio pratico
1. creare un nodo ROS2. creare un repository git3. condividere il nodo ROS
tramite il repository git4. modificare il nodo ROS
usando git
![Page 3: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/3.jpg)
Creare un repository git
![Page 4: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/4.jpg)
Repository name
realsense_r200_viewer
![Page 5: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/5.jpg)
Repository creato
![Page 6: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/6.jpg)
clone
![Page 7: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/7.jpg)
Creazione del repository localeRepository su GitHubhttps://github.com/labrobotica-bloisi/realsense_r200_viewer
Repository localecreato in~/catkin_ws/src
![Page 8: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/8.jpg)
Creating a ROS package by hand
http://wiki.ros.org/ROS/Tutorials/Creating%20a%20Package%20by%20Hand
The very first thing we'll do is add our manifest file.The package.xml file allows tools like rospack to determine information about what your package depends upon.
![Page 9: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/9.jpg)
Package.xml<?xml version="1.0"?><package><name>realsense_r200_viewer</name><version>0.0.1</version><description>realsense_r200_viewer package</description><maintainer email="[email protected]">Domenico Bloisi</maintainer><license>LGPLv3</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>cv_bridge</build_depend><build_depend>image_transport</build_depend><build_depend>roscpp</build_depend><build_depend>rospy</build_depend><build_depend>sensor_msgs</build_depend><build_depend>std_msgs</build_depend>
<run_depend>cv_bridge</run_depend><run_depend>image_transport</run_depend><run_depend>roscpp</run_depend><run_depend>rospy</run_depend><run_depend>sensor_msgs</run_depend><run_depend>std_msgs</run_depend>
</package>
![Page 10: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/10.jpg)
Adding package.xml
git add
git commit
![Page 11: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/11.jpg)
Finding a ROS package
http://wiki.ros.org/ROS/Tutorials/Creating%20a%20Package%20by%20Hand
Now that your package has a manifest, ROS can find it. Try executing the command:
rospack find realsense_r200_viewer
if ROS is set up correctly you should see the physical location where your package is stored
![Page 12: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/12.jpg)
CMakeList
http://wiki.ros.org/ROS/Tutorials/Creating%20a%20Package%20by%20Hand
We need the CMakeLists.txt file so that catkin_make, which uses CMake for its more powerful flexibility when building across multiple platforms, builds the package
![Page 13: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/13.jpg)
CmakeList.txtcmake_minimum_required(VERSION 2.8.3)project(realsense_r200_viewer)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(catkin REQUIRED COMPONENTScv_bridgeimage_transportroscpprospysensor_msgsstd_msgs
)
catkin_package()
include_directories(src/${catkin_INCLUDE_DIRS}
)
set(SRCS src/r200_viewer.cpp)add_executable(realsense_r200_viewer ${SRCS})target_link_libraries(realsense_r200_viewer${catkin_LIBRARIES}
)
il codice andrà insrc/r200_viewer.cpp
![Page 14: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/14.jpg)
Creazione di src/r200_viewer.cpp
![Page 15: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/15.jpg)
r200_viewer.cpp #include <ros/ros.h>#include <sensor_msgs/Image.h>#include <cv_bridge/cv_bridge.h>
#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/imgproc.hpp>#include <opencv2/imgcodecs.hpp>
using namespace std;
void rgb_callback(const sensor_msgs::ImageConstPtr& msg){cv_bridge::CvImagePtr cv_ptr;
try{cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
} catch (cv_bridge::Exception& e){ROS_ERROR("cv_bridge exception: %s", e.what());return;
}
cv::imshow("RGB", cv_ptr->image);cv::waitKey(30);
}
![Page 16: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/16.jpg)
r200_viewer.cpp void depth_callback(const sensor_msgs::ImageConstPtr& msg){
cv_bridge::CvImagePtr cv_ptr;
try {cv_ptr = cv_bridge::toCvCopy(msg, msg->encoding);
} catch (cv_bridge::Exception& e) {ROS_ERROR("cv_bridge exception: %s", e.what());return;
}
cv::Mat depthMat = cv_ptr->image.clone();
double dmin, dmax;cv::minMaxIdx(depthMat, &dmin, &dmax);cv::Mat adjMat;cv::convertScaleAbs(depthMat, adjMat, 255 / dmax);
cv::Mat colorMat;cv::applyColorMap(adjMat, colorMat, cv::COLORMAP_HOT);cv::imshow("Depth", colorMat);
cv::waitKey(30);}
![Page 17: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/17.jpg)
r200_viewer.cpp int main(int argc, char **argv){
ros::init(argc, argv, "realsense_r200_viewer");
ros::NodeHandle nh;
string topic_rgb = "camera/rgb/image_rect_color";string topic_depth = "camera/depth_registered/sw_registered/image_rect_raw";
cout << "Subscriptions:" << endl;cout << " - RGB topic: " << topic_rgb << endl;cout << " - Depth topic: " << topic_depth << endl;
ros::Subscriber rgb_sub = nh.subscribe(topic_rgb, 1, &rgb_callback);ros::Subscriber depth_sub = nh.subscribe(topic_depth, 1, &depth_callback);
ros::spin();
return 0;}
![Page 18: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/18.jpg)
catkin_make
catkin_make --pkg realsense_r200_viewer
![Page 19: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/19.jpg)
roscore + rosrunApriamo un terminale e lanciamo roscore
Cosa accade?
Apriamo un secondo terminale e lanciamorosrun realsense_r200_viewer realsense_r200_viewer
![Page 20: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/20.jpg)
Intel RealSense Camera R200
https://software.intel.com/en-us/articles/realsense-r200-camera
• The R200 actually has 3 cameras providing RGB (color) and stereoscopic IR to produce depth
• The inside range is approximately 0.5-3.5 meters and an outside range up to 10 meters
• With the help of a laser projector, the camera does 3D scanning for scene perception and enhanced photography
![Page 21: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/21.jpg)
realsense_camera node
roslaunch realsense_camera r200_nodelet_rgbd.launch
![Page 22: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/22.jpg)
rosrun (riproviamo)
![Page 23: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/23.jpg)
Aggiungiamo il codice sorgentegit add
git commit
![Page 24: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/24.jpg)
Aggiungiamo CmakeLists.txtgit add
git commit
![Page 25: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/25.jpg)
Aggiorniamo il repogit push
![Page 26: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/26.jpg)
Aggiungere collaboratori
![Page 27: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/27.jpg)
Ricerca del collaboratore
![Page 28: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/28.jpg)
Invito recapitato al collaboratore
![Page 29: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/29.jpg)
Vista del collaboratore
![Page 30: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/30.jpg)
branching
https://git-scm.com/book/it/v2/Git-Branching-Basic-Branching-and-Merging
git checkout -b colormap
![Page 31: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/31.jpg)
branching
git checkout -b colormap
colormap
https://git-scm.com/book/it/v2/Git-Branching-Basic-Branching-and-Merging
![Page 32: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/32.jpg)
Modifica a r200_viewer.cppvoid depth_callback(const sensor_msgs::ImageConstPtr& msg){
cv_bridge::CvImagePtr cv_ptr;
try {cv_ptr = cv_bridge::toCvCopy(msg, msg->encoding);
} catch (cv_bridge::Exception& e) {ROS_ERROR("cv_bridge exception: %s", e.what());return;
}
cv::Mat depthMat = cv_ptr->image.clone();
double dmin, dmax;cv::minMaxIdx(depthMat, &dmin, &dmax);cv::Mat adjMat;cv::convertScaleAbs(depthMat, adjMat, 255 / dmax);
cv::Mat colorMat;cv::applyColorMap(adjMat, colorMat, cv::COLORMAP_JET);cv::imshow("Depth", colorMat);
cv::waitKey(30);}
![Page 33: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/33.jpg)
branching
git commit -am 'cambio color map'
colormap
https://git-scm.com/book/it/v2/Git-Branching-Basic-Branching-and-Merging
![Page 34: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/34.jpg)
Merging
git checkout master
git merge colormap
colormap
https://git-scm.com/book/it/v2/Git-Branching-Basic-Branching-and-Merging
![Page 35: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/35.jpg)
Color map JET
![Page 36: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/36.jpg)
Esercizio
Scrivere un nodo ROS in grado di1. leggere lo stream video proveniente dalla webcam
integrata nel pc (o da una webcam esterna) 2. mostrare a video le immagini usando OpenCV
Pubblicare il codice usando un repository Git
![Page 37: µ v } ] } Ç P ]profs.scienze.univr.it/~bloisi/corsi/lezioni/ros-and-git.pdf · Microsoft PowerPoint - ros-and-git.pptx Author: bloisi Created Date: 11/30/2017 12:15:18 AM](https://reader034.vdocuments.pub/reader034/viewer/2022051322/602f62e292fa8a4c7666fe1d/html5/thumbnails/37.jpg)
+ Docente:Domenico Daniele Bloisi
Nov
embr
e20
17
Corso di RoboticaParte di Laboratorio
Laurea magistrale in ingegneria e scienze informatiche