mvrk33 / AgroBot

7 stars 1 forks source link

ROS Intro #21

Open mvrk33 opened 9 months ago

mvrk33 commented 9 months ago

[Uploading Lab-1-ROS-Intro.pdf…]()

krishnavamsi333 commented 8 months ago

ROS 2 humble

REQUIREMENTS

steps for uploading ubuntu in pi4

mobaXterm

-open mobaXterm->sessions->SSH-> -Remote host=proxy8.remoteiot.com -specify username(agrobot1 or agrobot2 or agrobot3) -port( )

Install service

-Java JVM -Java and the JVM (Java's virtual machine) are required for the RemoteIoT service. -If your system doesn't have JVM or you find any ssl exception, please install the recommended OpenJDK 8 which is open-source and the default Java version of the ubuntu and centos Linux system. -In ubuntu please use the command as below:

sudo apt-get -y remove java*
sudo apt-get -y install openjdk-8-jre-headless

-setup

ROS2 humble

locale  # check for UTF-8
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
locale  # verify settings

-Setup resources

sudo apt install software-properties-common
sudo add-apt-repository universe

-Environment setup -Set up your environment by sourcing the following file.

# Replace ".bash" with your shell if you're not using bash
# Possible values are: setup.bash, setup.sh, setup.zsh
source /opt/ros/humble/setup.bash

-If you installed ros-humble-desktop above you can try some examples.

-In one terminal, source the setup file and then run a C++ talker:

source /opt/ros/humble/setup.bash
ros2 run demo_nodes_cpp talker

-In another terminal source the setup file and then run a Python listener:

source /opt/ros/humble/setup.bash
ros2 run demo_nodes_py listener

Mandatory code

-You will need to run this command on every new shell you open to have access to the ROS 2 commands

source /opt/ros/humble/setup.bash

starting up turtlesim.

ros2 run turtlesim turtlesim_node

Open another terminal and run:

ros2 run turtlesim turtle_teleop_key

Recording and playing back data

create the new bag files

mkdir bag_files
cd bag_files

Choose a topic

ros2 bag can only record data from published messages in topics. To see the list of your system’s topics, open a new terminal and run the command:

ros2 topic list

this will return

/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose

In the topics tutorial, you learned that the /turtle_teleop node publishes commands on the /turtle1/cmd_vel topic to make the turtle move in turtlesim.

To see the data that /turtle1/cmd_vel is publishing, run the command:

ros2 topic echo /turtle1/cmd_vel

To record the data published to a topic use the command syntax: ros2 bag record

ros2 bag record /turtle1/cmd_vel

You can also record multiple topics, as well as change the name of the file ros2 bag saves to.Run the following command:

ros2 bag record -o subset /turtle1/cmd_vel /turtle1/pose

command used to know the storage of bag file

image

ros2 bag info rosbag2_2024_03_23-17_11_07

image

If you're referring to setting up a master-slave communication model between two terminals

In Terminal 1 (Master):

nc -l -p 1234

In Terminal 2 (Slave):

nc localhost 1234 | bash

example

-Create a New C++ Source File: nano hello.cpp

#include <iostream>

int main() {
    std::cout << "Hello" << std::endl;
    return 0;
}

In terminal 1(master)

./hello image

In terminal 2(slave)

-- you get output here image

vishaldirectr commented 7 months ago

ROS2 HUMBLE FULL BASH SCRIPT

Instructions:

1.Install git on your system: sudo apt-get install git 2.Clone this repository to your home folder! git clone https://github.com/adamjvr/ros2-bash.git cd ros2-bash/ ls cd src 3.Make script executable by navigating to the source folder of the repository directory and using the following command: chmod +x install_ros2.sh 4.Run the script: ./install_ros2.sh

vishaldirectr commented 7 months ago

ROS2 HUMBLE FULL BASH SCRIPT

Instructions:

Install git on your system: sudo apt-get install git Clone this repository to your home folder! git clone https://github.com/adamjvr/ros2-bash.git cd ros2-bash/ ls cd src Make script executable by navigating to the source folder of the repository directory and using the following command: chmod +x install_ros2.sh Run the script: ./install_ros2.sh

_ FOLLOW THIS FOR EASY INSTALLATION_**

1026Jaswanth commented 6 months ago

Creating a new python custom script

Creating Workspace (click to expand) ``` mkdir -p bumperbot_ws/src cd bumperbot_ws/ ```

colcon build the new workspace

colcon build
Creating Python & C packages (click to expand) ``` cd src ros2 pkg create --build-type ament_python bumperbot_py_examples ros2 pkg create --build-type ament_cmake bumperbot_cpp_examples ```

again build the package

colcon build

in a new terminal check the setup.bash file to run agrobot1@Trex:~/bumperbot_ws$

cd install

and run the setup.bash

. setup.bash

and check the updated packages list of ros2

ros2 pkg list

find the newly formed packages in the pkg list. Create your custom python file in the agrobot1@Trex:~/bumperbot_ws/src/bumperbot_py_examples/bumperbot_py_examples$ here i created simple_publisher.py and simple _subscriber.py after this edit the setup.py and package.xml update the setupt.py script in the console scripts , add the method of the codes here i utilised subscriber & publisher

    entry_points={
        'console_scripts': [
            'simple_publisher = bumperbot_py_examples.simple_publisher:main'
            'simple_subscriber = bumperbot_py_examples.simple_subscriber:main'
        ],

update the package.xml with the packages rclpy and stdmsgs

  <license>TODO: License declaration</license>

  <exec_depend>rclpy</exec_depend>
  <exec_depend>std_msgs</exec_depend>

  <test_depend>ament_copyright</test_depend>

build the worksapce again in new terminal and then initialize the setup.bash

. install/setup.bash

then

ros2 run bumperbot_py_examples

ros2 run bumperbot_py_examples simple_publisher

in another tab

ros2 run bumperbot_py_examples simple_subscriber
vishaldirectr commented 2 months ago

STEP 1:

Create the workspace folder and empty package

Open a new terminal window. First, we need to source the base ROS2 environment. That is, we need to create an underlay:

source/opt/ros/humble/setup.bash

Its for editing and manipulating python files

 sudo apt update
 sudo apt upgrade
 sudo apt-get install gedit

Create a workspace

mkdir -p ~/ws_pub_sub/src

This command will create the workspace called WS_pub__sub and inside of that folder, it will create a sub folder called SRC

The next step is to create a package for that we need to navigate to the SRC folder

cd ~/ws_pub_sub/src

To create a package to need to type :

ros2 pkg create --build-type ament_python publisher_subscriber

The package name is publisher_subscriber

STEP 2;

Create publisher_subscriber python node files

palce the python files in the publisher_subscriber

cd ~/ws_pub_sub/src/publisher_subscriber/publisher_subscriber/

In this folder we will create a pub and sub nodes

create a pub node. Name the file as publisher.py

we can create the publisher file by gedit or spyder

gedit publisher.py

as the gedit is not good foe the complex code we go for the syper or conda #i will create a file for that

open new terminal

Before that install conda

conda activate
anaconda-navigator

launch the spyder

write the code of publisher and save it as publisher.py in the ws_pub_sub/src/publisher_subscriber/publisher_subscriber/

the code willl be available in the internet as wll as in the ros2 fourms

write the subscriber code just like the above

sav it in the same location as publisher.py

close the terminal now

Step 3 got to the work space ws_pub_sub/src/publisher_subscriber/

gedit package.xml

add the dependencies

rclpy std_msgs save the file create the entry point for the package ``` cd ws_pub_sub/src/publisher_subscriber/ gedit setup.py ``` in the entry points edit it as entry_points={ 'console_scripts':['publisher=publisher_subscriber.publisher:main', 'subscriber=publisher_subscriber.subscriber:main' ], } `gedit setup.cfg` check if its in empty if empty then someting is wrong ``` cd ~/ws_pub_sub/ rosdep install -i --from-path src --rosdistro humble -y ``` it will retrun all are up to date ``` cd ~/ws_pub_sub/ colcon build ``` **Step 4** `cd ~/ws_pub_sub/` in the same dicrectory ope new terminal bash the follwing `source ~/ws_pub_sub/install/setup.bash` run the node as `ros2 run publisher_subscriber publisher` to run the subscriber node open new terminal `cd ~/ws_pub_sub/` bash the follwing `source ~/ws_pub_sub/install/setup.bash` run the node as `ros2 run publisher_subscriber subscriber`
vishaldirectr commented 2 months ago

STEP 1: #Create the workspace folder and empty package #Open a new terminal window. First, we need to source the base ROS2 environment. That is, we need to create an underlay:

source/opt/ros/humble/setup.bash

Its for editing and manipulating python files

 sudo apt update
 sudo apt upgrade
 sudo apt-get install gedit

Create a workspace

mkdir -p ~/ws_pub_sub/src

This command will create the workspace called WS_pub__sub and inside of that folder, it will create a sub folder called SRC

The next step is to create a package for that we need to navigate to the SRC folder

cd ~/ws_pub_sub/src

To create a package to need to type :

ros2 pkg create --build-type ament_python publisher_subscriber

The package name is publisher_subscriber

STEP 2; #Create publisher_subscriber python node files #palce the python files in the publisher_subscriber

cd ~/ws_pub_sub/src/publisher_subscriber/publisher_subscriber/

In this folder we will create a pub and sub nodes #create a pub node. Name the file as publisher.py #we can create the publisher file by gedit or spyder

gedit publisher.py

as the gedit is not good foe the complex code we go for the syper or conda #i will create a file for that

open new terminal

Before that install conda

conda activate
anaconda-navigator

launch the spyder #write the code of publisher and save it as publisher.py in the ws_pub_sub/src/publisher_subscriber/publisher_subscriber/ #the code willl be available in the internet as wll as in the ros2 fourms

write the subscriber code just like the above #sav it in the same location as publisher.py close the terminal now

Step 3 got to the work space ws_pub_sub/src/publisher_subscriber/

gedit package.xml

add the dependencies rclpy std_msgs

save the file

create the entry point for the package

cd ws_pub_sub/src/publisher_subscriber/
gedit setup.py

in the entry points edit it as entry_points={ 'console_scripts':['publisher=publisher_subscriber.publisher:main', 'subscriber=publisher_subscriber.subscriber:main' ], }

gedit setup.cfg check if its in empty if empty then someting is wrong

cd ~/ws_pub_sub/
rosdep install -i --from-path src --rosdistro humble -y

it will retrun all are up to date

cd ~/ws_pub_sub/
colcon build

Step 4

cd ~/ws_pub_sub/ in the same dicrectory open new terminal bash the follwing source ~/ws_pub_sub/install/setup.bash

run the node as ros2 run publisher_subscriber publisher

to run the subscriber node open new terminal cd ~/ws_pub_sub/

bash the follw0ing source ~/ws_pub_sub/install/setup.bash run the node as ros2 run publisher_subscriber subscriber

Follow this for Easy Creation of pub_sub node