Skip to content
Open
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
62 changes: 62 additions & 0 deletions ROS/ROS
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# RUNNING ROS using virtual machine.
i am using the virtual machine for ubuntu.
# EXCERCISE 1
- In this we first create the required folder using ---> mkdir ~/git
- I downloaded the sub_common zip.
- Then i used :
manan@manan-virtual-machine:~$ cd ~/git
manan@manan-virtual-machine:~/git$ unzip smb_common.zip
- then i made i directory ~/Workspaces/smb_ws/src
manan@manan-virtual-machine:~/git$ mkdir -p ~/Workspaces/smb_ws/src
- Using roslaunch to start the simulation and inspect the created nodes and their topics.
- Source the ROS setup script
- source /opt/ros/noetic/setup.bash
- Launch the simulation
roslaunch smb_gazebo smb_gazebo.launch
- In a new terminal, source the ROS setup script again
-source /opt/ros/noetic/setup.bash
- List all active nodes
rosnode list
- List all active topics
rostopic list
- Echo messages from a specific topic (e.g., /cmd_vel)
-rostopic echo /cmd_vel
- Check the publishing rate of a specific topic (e.g., /cmd_vel)
rostopic hz /cmd_vel
- Visualize the ROS computation graph
-rqt_graph
- Publish a velocity command to the /cmd_vel topic
rostopic pub /cmd_vel geometry_msgs/Twist "linear:
x: 0.5
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.5" -r 10
Navigate to the git folder and clone the repository
cd ~/git
git clone https://github.com/ros-teleop/teleop_twist_keyboard.git
Create a symlink in the catkin workspace
cd ~/Workspaces/smb_ws/src
ln -s ~/git/teleop_twist_keyboard .
-Compile the package
cd ~/Workspaces/smb_ws
Catkin_make
Run teleop_twist_keyboard
-Source devel/setup.bash
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
!-- File: smb_custom_world.launch --
- launch
!-- Include the default smb_gazebo.launch file --
include file="$(find smb_gazebo)/launch/smb_gazebo.launch"
!-- Override the world_file argument to use a different world --
arg name="world_file" value="/usr/share/gazebo-11/worlds/robocup14_spl_field.world"/
/include
/launch
- Check if teleop_twist_keyboard is compiled
roscd teleop_twist_keyboard
- Source the ROS setup script
- source /opt/ros/noetic/setup.bash
- Start the custom launch file
roslaunch smb_gazebo smb_custom_world.launch
89 changes: 89 additions & 0 deletions ROS/ROS assignment 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# excercise 2
- I first downloaded the smb_highlevel_controller zip file from the course website.
- After that I inspected :
cd ~/Downloads
unzip smb_highlevel_controller.zip
cd smb_highlevel_controller
cat CMakeLists.txt
cat package.xml
- Created a subscriber to the /scan topic :
nano smb_highlevel_controller_node.cpp
- then i coded the following :
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
ROS_INFO("Received a LaserScan message with %lu ranges", msg->ranges.size());
}

int main(int argc, char **argv)
{
ros::init(argc, argv, "smb_highlevel_controller_node");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("scan", 1000, scanCallback);
ros::spin();
return 0;
}
- Added a parameter file with topic name and queue size for the subscriber of the topic
/scan:
nano smb_highlevel_controller_node.cpp
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>

void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
ROS_INFO("Received a LaserScan message with %lu ranges", msg->ranges.size());
}

int main(int argc, char **argv)
{
ros::init(argc, argv, "smb_highlevel_controller_node");
ros::NodeHandle nh;

ros::Subscriber sub = nh.subscribe("scan", 1000, scanCallback);

ros::spin();

return 0;
}
- Created a callback method for that subscriber which outputs the smallest distance
measurement from the vector ranges in the message of the laser scanner to the
terminal :
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
#include <limits> // For std::numeric_limits

void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
// Initialize minimum range to the maximum possible float value
float min_range = std::numeric_limits<float>::infinity();

// Iterate through the range readings to find the minimum value
for (const auto& range : msg->ranges) {
if (range < min_range && range >= msg->range_min && range <= msg->range_max) {
min_range = range;
}
}

// Output the smallest distance measurement to the terminal
ROS_INFO("Smallest distance measurement: %f", min_range);
}

int main(int argc, char **argv)
{
ros::init(argc, argv, "smb_highlevel_controller_node");
ros::NodeHandle nh;

std::string scan_topic;
int queue_size;

nh.getParam("scan_topic", scan_topic);
nh.getParam("queue_size", queue_size);

ros::Subscriber sub = nh.subscribe(scan_topic, queue_size, scanCallback);

ros::spin();

return 0;
}
- Then i was not able to add the launch file for ex1 , figuring that out...
Binary file added ROS/Screenshot 2024-06-18 212725.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.