Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rospy2_pkg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thk_libs
ROS_2
rospy2_pkg
Commits
13a7ace0
Commit
13a7ace0
authored
11 months ago
by
Vladislav Vlasuk
Browse files
Options
Downloads
Patches
Plain Diff
comments
parent
c716feee
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
__pycache__/__init__.cpython-38.pyc
+0
-0
0 additions, 0 deletions
__pycache__/__init__.cpython-38.pyc
src/__pycache__/m_ros2py.cpython-38.pyc
+0
-0
0 additions, 0 deletions
src/__pycache__/m_ros2py.cpython-38.pyc
src/m_ros2py.py
+24
-2
24 additions, 2 deletions
src/m_ros2py.py
with
24 additions
and
2 deletions
__pycache__/__init__.cpython-38.pyc
+
0
−
0
View file @
13a7ace0
No preview for this file type
This diff is collapsed.
Click to expand it.
src/__pycache__/m_ros2py.cpython-38.pyc
+
0
−
0
View file @
13a7ace0
No preview for this file type
This diff is collapsed.
Click to expand it.
src/m_ros2py.py
+
24
−
2
View file @
13a7ace0
#______________________________________________________________________________________________________________________________________________
#Author: VV
#Description: Class to simplify the creation of ros2 nodes
#Date: 01.08.24
#______________________________________________________________________________________________________________________________________________
#imports
from
rclpy.node
import
Node
from
rclpy.node
import
Node
from
std_msgs.msg
import
*
from
std_msgs.msg
import
*
#______________________________________________________________________________________________________________________________________________
#wrapper for creating ros2 node as publisher, subscriber, clients, service
class
ros2node
(
Node
):
class
ros2node
(
Node
):
def
__init__
(
self
,
nodeName
):
def
__init__
(
self
,
nodeName
):
super
().
__init__
(
nodeName
)
super
().
__init__
(
nodeName
)
...
@@ -11,20 +19,30 @@ class ros2node(Node):
...
@@ -11,20 +19,30 @@ class ros2node(Node):
self
.
_clients
=
{}
self
.
_clients
=
{}
self
.
as_ClientService
=
False
self
.
as_ClientService
=
False
#______________________________________________________________________________________________________________________________________________
#ros2 publisher
def
create_publisher_with_timer
(
self
,
topicName
,
msgType
,
func
,
rate
):
def
create_publisher_with_timer
(
self
,
topicName
,
msgType
,
func
,
rate
):
self
.
_publishers
[
topicName
]
=
self
.
create_publisher
(
msgType
,
topicName
,
10
)
self
.
_publishers
[
topicName
]
=
self
.
create_publisher
(
msgType
,
topicName
,
10
)
self
.
_timers
[
topicName
]
=
self
.
create_timer
(
rate
,
lambda
:
self
.
timer_callback
(
topicName
,
func
))
self
.
_timers
[
topicName
]
=
self
.
create_timer
(
rate
,
lambda
:
self
.
timer_callback
(
topicName
,
func
))
#______________________________________________________________________________________________________________________________________________
#ros2 subscriber
def
create_subscriber
(
self
,
topicName
,
msgType
,
func
):
def
create_subscriber
(
self
,
topicName
,
msgType
,
func
):
self
.
_subscribers
[
topicName
]
=
self
.
create_subscription
(
msgType
,
topicName
,
func
,
10
)
self
.
_subscribers
[
topicName
]
=
self
.
create_subscription
(
msgType
,
topicName
,
func
,
10
)
#______________________________________________________________________________________________________________________________________________
#ros2 service
def
create_new_service
(
self
,
topicName
,
msgType
,
func
):
def
create_new_service
(
self
,
topicName
,
msgType
,
func
):
self
.
_services
[
topicName
]
=
self
.
create_service
(
msgType
,
topicName
,
func
)
self
.
_services
[
topicName
]
=
self
.
create_service
(
msgType
,
topicName
,
func
)
self
.
as_ClientService
=
True
self
.
as_ClientService
=
True
#______________________________________________________________________________________________________________________________________________
#ros2 client
def
create_new_client
(
self
,
topicName
,
msgType
):
def
create_new_client
(
self
,
topicName
,
msgType
):
self
.
_clients
[
topicName
]
=
self
.
create_client
(
msgType
,
topicName
)
self
.
_clients
[
topicName
]
=
self
.
create_client
(
msgType
,
topicName
)
self
.
as_ClientService
=
True
self
.
as_ClientService
=
True
#______________________________________________________________________________________________________________________________________________
#external executable callback function
def
timer_callback
(
self
,
topicName
,
func
):
def
timer_callback
(
self
,
topicName
,
func
):
if
not
self
.
as_ClientService
:
if
not
self
.
as_ClientService
:
...
@@ -35,6 +53,10 @@ class ros2node(Node):
...
@@ -35,6 +53,10 @@ class ros2node(Node):
# self.get_logger().info(f'Publishing: "{msg.data}" on topic: "{topicName}"')
# self.get_logger().info(f'Publishing: "{msg.data}" on topic: "{topicName}"')
else
:
else
:
self
.
get_logger
().
info
(
f
'
No publisher found for topic:
"
{
topicName
}
"'
)
self
.
get_logger
().
info
(
f
'
No publisher found for topic:
"
{
topicName
}
"'
)
#______________________________________________________________________________________________________________________________________________
#getter
def
get_client
(
self
,
topicName
):
def
get_client
(
self
,
topicName
):
return
self
.
_clients
.
get
(
topicName
)
return
self
.
_clients
.
get
(
topicName
)
#______________________________________________________________________________________________________________________________________________
#setter
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment