diff --git a/ROS/ROS b/ROS/ROS new file mode 100644 index 0000000..b123757 --- /dev/null +++ b/ROS/ROS @@ -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 diff --git a/ROS/ROS assignment 2 b/ROS/ROS assignment 2 new file mode 100644 index 0000000..fd21ada --- /dev/null +++ b/ROS/ROS assignment 2 @@ -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 +#include +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 +#include + +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 +#include +#include // 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::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... diff --git a/ROS/Screenshot 2024-06-18 212725.jpg b/ROS/Screenshot 2024-06-18 212725.jpg new file mode 100644 index 0000000..ef783de Binary files /dev/null and b/ROS/Screenshot 2024-06-18 212725.jpg differ