Open Kleczyk opened 1 month ago
@Kleczyk czy po wykonaniu taska dawać tutaj jakiś ss że działa?
@FWalkowicz tak tutaj. screen wystarczy
@Kleczyk dodaje całe rozwiązanie wraz z przykładowym kodem gdyby ktoś miał jakieś pytania albo mu nie działało.
rover_control
package
Jeżeli tutaj nie dodaliśmy w --dependencies
std_msg musimy to zrobić w pliku package.xml
żeby poprawnie nam działało.<depend>rclpy</depend>
<depend>std_msgs</depend>
mkdir ROS2
cd ROS2
mkdir src
ros2 pkg create my_robot_controller --build-type ament_python --dependencies rclpy
cd ROS2/src/my_robot_controller/my_robot_controller
touch my_first_node.py
touch my_second_node.py
publisher_node
)import rclpy
import random
from std_msgs.msg import String
from rclpy.node import Node
class SpeedPublisher(Node):
def __init__(self):
super().__init__('speed_publisher')
self.speed_publisher = self.create_publisher(String, '/rover/speed', 10)
time_period = 1
self.timer = self.create_timer(time_period, self.timer_callback)
self.i = 1
def timer_callback(self):
msg = String()
msg.data = f'msg: {self.i} - rover speed is : {round(random.random(), 2)}'
self.speed_publisher.publish(msg)
self.get_logger().info(f'Publishing {msg.data}')
self.i += 1
def main(args=None):
rclpy.init(args=args)
node = SpeedPublisher()
rclpy.spin(node)
rclpy.shutdown()
if __name__ == '__main__':
main()
subscriber_node
)
import rclpy
from std_msgs.msg import String
from rclpy.node import Node
class SpeedSubscriber(Node):
def init(self):
super().init('speed_subscriber')
self.create_subscription(
String,
'rover/speed',
self.listener_callback,
10
)
self.subscriptions
def listener_callback(self, msg):
self.get_logger().info(f'Subscribed {msg.data}')
def main(args=None):
rclpy.init(args=args)
node = SpeedSubscriber()
rclpy.spin(node)
rclpy.shutdown()
if name == 'main':
main()
- [x] Add correct entries to the `setup.py` file
```python
'console_scripts': [
"publisher_node = my_robot_controller.my_first_node:main",
"subscriber_node = my_robot_controller.my_second_node:main",
],
colcon
colcon build
ros2 run my_robot_controller publisher_node
ros2 run my_robot_controller subscriber_node
rqt_graph
rqt_graph
@FWalkowicz , @kosiarn @Sygnator @kubabartecki @bafaurazan @jKryczka jak tam idzie ?
@kosiarn @Sygnator @kubabartecki @bafaurazan @jKryczka jak tam idzie ?
@Kleczyk sorki, inżynierka nieco wstrzymała... właśnie instaluję Ubuntu na wirtualce
@kosiarn nic się nie dzieje super powodzianka z VM
@Kleczyk na linux mint działa wszystko
rover_control
package
żeby na linux mint działało sprawdzanie zależności dla ros, trzeba było dać tą komendęsudo apt upgrade
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers" --os=ubuntu:jammy
mkdir ros2_ws
cd ros2_ws
mkdir src
cd src
ros2 pkg create --build-type ament_python --license Apache-2.0 rover_control
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rover_control</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="rafal@todo.todo">rafal</maintainer>
<license>Apache-2.0</license>
<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>
<export>
<build_type>ament_python</build_type>
</export>
</package>
publisher_node
)pobranie przykładowego publisher-a i dostosowanie go
cd src/rover_control/rover_control/
wget https://raw.githubusercontent.com/ros2/examples/humble/rclpy/topics/minimal_publisher/examples_rclpy_minimal_publisher/publisher_member_function.py
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class SpeedPublisher(Node):
def __init__(self):
super().__init__('speed_publisher')
self.publisher_ = self.create_publisher(String, 'rover/speed', 10)
timer_period = 1.0
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0.0
def timer_callback(self):
msg = String()
msg.data = '%.1f' % self.i
self.publisher_.publish(msg)
self.get_logger().info('"%s"' % msg.data)
self.i += 0.1
def main(args=None):
rclpy.init(args=args)
my_speed_publisher = SpeedPublisher()
rclpy.spin(my_speed_publisher)
my_speed_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
subscriber_node
)pobranie przykładowego subscriber-a i dostosowanie go
cd src/rover_control/rover_control/
wget https://raw.githubusercontent.com/ros2/examples/humble/rclpy/topics/minimal_subscriber/examples_rclpy_minimal_subscriber/subscriber_member_function.py
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class SpeedSubscriber(Node):
def __init__(self):
super().__init__('speed_subscriber')
self.subscription = self.create_subscription(
String,
'rover/speed',
self.listener_callback,
10)
self.subscription
def listener_callback(self, msg):
self.get_logger().info('"%s"' % msg.data)
def main(args=None):
rclpy.init(args=args)
my_speed_subscriber = SpeedSubscriber()
rclpy.spin(my_speed_subscriber)
my_speed_subscriber.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
setup.py
fileentry_points={
'console_scripts': [
'publisher_node = rover_control.publisher_member_function:main',
'subscriber_node = rover_control.subscriber_member_function:main',
],
},
colcon
colcon build
ros2 run rover_control publisher_node
ros2 run rover_control subscriber_node
rqt_graph
rqt_graph
coś działa aczkolwiek jeśli ktoś wie dlaczego przy każdej nowej instancji terminala muszę robić source setup.zsh
paczki żeby ros ją widział przy ros2 run
to byłbym wdzięczny za podzielenie się wiedzą :))))
Info
For the sake of learning and before getting started in ROS, everyone needs to do the task. i encourage you to expand the network of node connections to get a better feel for the topic. We need this before brainstorming. Solutions past in comment .
Description
The goal is to create two ROS 2 nodes, one that publishes data and another that subscribes to it via a topic. The nodes must be correctly built and configured in a package, and their connections should be visualized using
rqt_graph
.Tasks
rover_control
packagepublisher_node
)subscriber_node
)setup.py
filecolcon
rqt_graph
Possible Solution
Two nodes:
Float32
every second to therover/speed
topic.rover/speed
topic and prints received data in the terminal.Images look this:
Dependencies
Blocked by