Skip to content

Instantly share code, notes, and snippets.

View TheProjectsGuy's full-sized avatar
🎯
Focusing

Avneesh Mishra TheProjectsGuy

🎯
Focusing
View GitHub Profile
@TheProjectsGuy
TheProjectsGuy / ServiceServer1.py
Last active December 11, 2018 02:39
Service server creates using Python for ROS
#!/usr/bin/env python
# Import files
import rospy
from intro_pkg1.srv import *
# Service server function
def equation(request):
# Response object
response = FloatIOResponse()
# Relation between request and response
@TheProjectsGuy
TheProjectsGuy / ServiceServer1.cpp
Created December 11, 2018 02:42
Service server created using C++ in ROS
// Include header files
#include "ros/ros.h"
// The service header file
#include "intro_pkg1/FloatIO.h"
// Definition function
bool equation(intro_pkg1::FloatIO::Request &req, intro_pkg1::FloatIO::Response &res) {
// Relation between output and input
res.output = 2 * (req.input) + 1;
ROS_INFO("Request: [%f], Response: [%f]", req.input, res.output);
@TheProjectsGuy
TheProjectsGuy / ServiceClient1.cpp
Created December 11, 2018 02:44
ROS Service client made using C++
// Header files for ROS
#include "ros/ros.h"
// For service
#include "intro_pkg1/FloatIO.h"
// For atof
#include "stdlib.h"
int main(int argc, char **argv) {
// Initialize the node
ros::init(argc, argv, "FloatIO_ServiceClient");
@TheProjectsGuy
TheProjectsGuy / ServiceClient1.py
Created December 11, 2018 02:45
ROS Service client made using Python
#!/usr/bin/env python
# Import libraries
import rospy
# Service files
from intro_pkg1.srv import *
# System files
import sys
def main():
# Initialize the node
@TheProjectsGuy
TheProjectsGuy / Sample.cfg
Last active December 11, 2018 14:32
Sample configuration file using ROS dynamic reconfiguration
#!/usr/bin/env python
PACKAGE = "intro_pkg1" # Package variable
from dynamic_reconfigure.parameter_generator_catkin import *
# Parameter Generator object
gen = ParameterGenerator()
# Add parameters
gen.add("Integer_param", int_t, 0, "An integer parameter", 0, -5, 5)
gen.add("Double_param", double_t, 0, "A double parameter", 0.0, -2, 2)
gen.add("String_param", str_t, 0, "A string parameter", "String Here")
gen.add("Bool_param", bool_t, 0, "A boolean parameter", False)
@TheProjectsGuy
TheProjectsGuy / DynamicConfig.cpp
Created December 11, 2018 14:33
C++ node for Dynamic reconfigure in ROS
// Header files
#include "ros/ros.h"
// Dynamic reconfigure server file
#include "dynamic_reconfigure/server.h"
// Configuration file
#include "intro_pkg1/SampleConfig.h"
void callback_function(intro_pkg1::SampleConfig &conf, uint32_t level) {
// Accessing parameters
ROS_INFO("Reconfiguration results: %i %f %s %s %i",
@TheProjectsGuy
TheProjectsGuy / python_config.py
Created December 11, 2018 14:35
Python node for Dynamic reconfigure in ROS
#!/usr/bin/env python
# Import rospy
import rospy
# Main dynamic reconfiguration files
from dynamic_reconfigure.server import Server
# Configuration made in the devel folder
from intro_pkg1.cfg import SampleConfig
# Callback function
def callback(config, level):
rospy.loginfo("Values: {0}, {1}, {2}, {3}, {4}".format(config.Integer_param,
@TheProjectsGuy
TheProjectsGuy / FirstLaunch.launch
Created December 12, 2018 11:32
First Launch file in ROS
<launch>
<!-- Argument parser made using C++ -->
<node name="Debugger1" pkg="intro_pkg1" type="AllLevelDebugger" launch-prefix="gnome-terminal --tab -e "/>
<node name="Debugger2" pkg="intro_pkg1" type="DebuggerAll.py" launch-prefix="gnome-terminal --tab -e"/>
</launch>
@TheProjectsGuy
TheProjectsGuy / FileName.cpp
Last active December 12, 2018 11:54
Setting the logger level using the rosconsole C++ API in ROS
// All #include files ....
#include "ros/console.h"
// Code here...
int main(int argc, char **argv) {
// Initialize ROS node using ros::init function
ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug); // Set console level to debug
// Code here...
}
@TheProjectsGuy
TheProjectsGuy / rosconsole_cpp.conf
Created December 12, 2018 12:41
Configuration files to change the debugger priority level in ROS using rosout for Python and roscpp for C++
# Override the rosconsole logger
# output level for this package ONLY
log4j.logger.ros.intro_pkg1=DEBUG