Skip to content

Instantly share code, notes, and snippets.

@jdumont0201
jdumont0201 / constructor_new_bad.cpp
Last active May 5, 2018 07:53
Bad object contruction using new
class A{
int d_val;
public:
A(int val){
d_val=val;
}
};
int main(){
A * a=new A(5);
@jdumont0201
jdumont0201 / convolutions.py
Last active July 2, 2020 20:09
Image processing with convolutions in Python
import cv2
import numpy as np
img = cv2.imread('images/input.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
rows,cols = img.shape[:2]
cv2.imshow('Original',img)
@jdumont0201
jdumont0201 / package.xml
Created May 4, 2018 11:36
ROS Custom Message package.xml
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
@jdumont0201
jdumont0201 / CMakeLists.txt
Created May 4, 2018 11:36
ROS Custom Message CMake
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
message_generation # Add message_generation here, after the other packages
)
#Add to message files
add_message_files(
FILES
@jdumont0201
jdumont0201 / CMakeLists.txt
Created May 4, 2018 11:34
Ros loading a file into a service: CMake
find_package(catkin REQUIRED COMPONENTS roscpp roslib)
@jdumont0201
jdumont0201 / loading_file.cpp
Created May 4, 2018 11:33
ROS loading file into a service
#include <ros/package.h>
trajectory.request.file = ros::package::getPath("packagename") + "/path_to/file.txt";
@jdumont0201
jdumont0201 / MyCustomMessage.srv
Created May 4, 2018 11:31
ROS Custom Message definition
float64 radius
int32 repetitions
---
bool success
@jdumont0201
jdumont0201 / CMakeLists.txt
Created May 4, 2018 11:30
Service server CMake edits
add_service_files(
FILES
ServiceName.srv
)
...
find_package(catkin REQUIRED COMPONENTS
roscpp
message_generation
)
@jdumont0201
jdumont0201 / CMakeLists.txt
Last active May 4, 2018 11:29
Custom service message CMake edits
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs message_generation )
...
add_service_files(
FILES
MyCustomServiceMessage.srv
)
...
@jdumont0201
jdumont0201 / minimal_service_server.cpp
Created May 4, 2018 11:27
Minimal ROS Service server
#include "ros/ros.h" #include "std_srvs/Empty.h" // Import the service message header file generated from the Empty.srv message
bool my_callback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res){
//process some action
ROS_INFO("My_callback has been called");
return true;
}
int main(int argc, char **argv){
ros::init(argc, argv, "service_server");