Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
catkin_ws_berlindynamics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bashas99
catkin_ws_berlindynamics
Commits
f25c5911
Commit
f25c5911
authored
3 years ago
by
Frederik Safner
Browse files
Options
Downloads
Patches
Plain Diff
assignment_9 exercise1
parent
4768c32c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/assignment_9/src/exercise1_subscriber.py
+52
-0
52 additions, 0 deletions
src/assignment_9/src/exercise1_subscriber.py
with
52 additions
and
0 deletions
src/assignment_9/src/exercise1_subscriber.py
0 → 100755
+
52
−
0
View file @
f25c5911
#!/usr/bin/env python3
from
cmath
import
pi
from
math
import
sqrt
import
numpy
as
np
import
rospy
import
std_msgs.msg
from
autominy_msgs.msg
import
NormalizedSteeringCommand
,
SpeedCommand
from
nav_msgs.msg
import
Odometry
from
tf.transformations
import
quaternion_from_euler
,
quaternion_multiply
class
Subscriber
:
def
__init__
(
self
):
rospy
.
init_node
(
"
movementPublisher
"
)
self
.
vector
=
None
self
.
time
=
0.
self
.
subscriber
=
rospy
.
Subscriber
(
'
/simulation/odom_ground_truth
'
,
Odometry
,
self
.
callback_pose
)
self
.
steering_publisher
=
rospy
.
Publisher
(
"
/actuators/steering_normalized
"
,
NormalizedSteeringCommand
,
queue_size
=
10
)
self
.
speed_publisher
=
rospy
.
Publisher
(
"
/actuators/speed
"
,
SpeedCommand
,
queue_size
=
10
)
self
.
move
(
steering
=
0
)
def
move
(
self
,
steering
):
# Move approximately two meters
header
=
std_msgs
.
msg
.
Header
()
rospy
.
loginfo
(
"
Start moving with steering angle %d
"
,
steering
)
self
.
steering_publisher
.
publish
(
header
,
steering
)
self
.
speed_publisher
.
publish
(
header
,
0.3
)
rospy
.
sleep
(
3
)
rospy
.
loginfo
(
"
Stop moving
"
)
header
=
std_msgs
.
msg
.
Header
()
self
.
steering_publisher
.
publish
(
header
,
0
)
self
.
speed_publisher
.
publish
(
header
,
0
)
def
callback_pose
(
self
,
message
):
position
=
message
.
pose
.
pose
.
position
orientation
=
message
.
pose
.
pose
.
orientation
orientation
=
[
orientation
.
x
,
orientation
.
y
,
orientation
.
z
,
orientation
.
w
]
rospy
.
loginfo
(
self
.
__rotate_quaternion
(
orientation
))
@staticmethod
def
__rotate_quaternion
(
quat
):
# Rotate quat by 90 degree around x-axis.
q_rot
=
quaternion_from_euler
(
pi
/
2
,
0
,
0
)
return
quaternion_multiply
(
q_rot
,
quat
)
subscriber
=
Subscriber
()
rospy
.
spin
()
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