Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Robomaster_pi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Emil Harlan
Robomaster_pi
Commits
c9ebdc2b
Commit
c9ebdc2b
authored
2 years ago
by
Emil Harlan
Browse files
Options
Downloads
Patches
Plain Diff
a
parent
567319b1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
robomaster_pi/robot_ros_odom.py
+15
-17
15 additions, 17 deletions
robomaster_pi/robot_ros_odom.py
robomaster_pi/robot_ros_vel.py
+12
-15
12 additions, 15 deletions
robomaster_pi/robot_ros_vel.py
with
27 additions
and
32 deletions
robomaster_pi/robot_ros_odom.py
+
15
−
17
View file @
c9ebdc2b
import
math
import
time
import
socket
import
sys
from
geometry_msgs.msg
import
TransformStamped
import
numpy
as
np
import
serial
import
rclpy
from
rclpy.node
import
Node
from
tf2_ros
import
TransformBroadcaster
...
...
@@ -11,16 +12,13 @@ from tf2_ros import TransformBroadcaster
from
rclpy.node
import
Node
ser
=
serial
.
Serial
()
ser
.
port
=
'
/dev/ttyS0
'
ser
.
baudrate
=
115200
ser
.
bytesize
=
serial
.
EIGHTBITS
ser
.
stopbits
=
serial
.
STOPBITS_ONE
ser
.
parity
=
serial
.
PARITY_NONE
ser
.
timeout
=
0.2
ser
.
open
()
ser
.
write
((
"
command;
"
).
encode
(
'
utf-8
'
))
leer
=
ser
.
readall
()
host
=
"
192.168.42.2
"
port
=
40923
address
=
(
host
,
int
(
port
))
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
(
address
)
s
.
send
((
"
command;
"
).
encode
(
'
utf-8
'
))
abfangen
=
s
.
recv
(
1024
)
def
quaternion_from_euler
(
ai
,
aj
,
ak
):
ai
/=
2.0
...
...
@@ -51,25 +49,25 @@ class Robomaster_odom(Node):
while
True
:
super
().
__init__
(
"
robomaster_odom
"
)
self
.
tf_broadcaster
=
TransformBroadcaster
(
self
)
s
er
.
write
((
"
chassis position ?;
"
).
encode
(
'
utf-8
'
))
buf
=
s
er
.
re
adall
(
)
s
.
send
((
"
chassis position ?;
"
).
encode
(
'
utf-8
'
))
buf
=
s
.
re
cv
(
1024
)
xyz
=
buf
.
decode
(
'
utf-8
'
)
self
.
get_logger
().
info
(
xyz
)
xyzlist
=
xyz
.
split
(
"
"
)
t
=
TransformStamped
()
t
.
header
.
stamp
=
self
.
get_clock
().
now
().
to_msg
()
t
.
header
.
frame_id
=
'
odom
'
t
.
child_frame_id
=
"
base_
l
in
k
"
t
.
child_frame_id
=
"
base_
footpr
in
t
"
t
.
transform
.
translation
.
x
=
float
(
xyzlist
[
0
])
t
.
transform
.
translation
.
y
=
float
(
xyzlist
[
1
])
t
.
transform
.
translation
.
y
=
-
float
(
xyzlist
[
1
])
t
.
transform
.
translation
.
z
=
0.0
q
=
quaternion_from_euler
(
0
,
0
,
float
(
xyzlist
[
2
])
*
math
.
pi
/
180
)
q
=
quaternion_from_euler
(
0
,
0
,
-
float
(
xyzlist
[
2
])
*
math
.
pi
/
180
)
t
.
transform
.
rotation
.
x
=
q
[
0
]
t
.
transform
.
rotation
.
y
=
q
[
1
]
t
.
transform
.
rotation
.
z
=
q
[
2
]
t
.
transform
.
rotation
.
w
=
q
[
3
]
self
.
tf_broadcaster
.
sendTransform
(
t
)
time
.
sleep
(
0.
1
)
time
.
sleep
(
0.
5
)
def
main
():
rclpy
.
init
()
...
...
This diff is collapsed.
Click to expand it.
robomaster_pi/robot_ros_vel.py
+
12
−
15
View file @
c9ebdc2b
import
math
import
time
import
socket
import
sys
from
geometry_msgs.msg
import
TransformStamped
import
numpy
as
np
import
serial
import
rclpy
from
rclpy.node
import
Node
from
geometry_msgs.msg
import
Twist
...
...
@@ -12,28 +13,24 @@ from tf2_ros import TransformBroadcaster
from
rclpy.node
import
Node
ser2
=
serial
.
Serial
()
ser2
.
port
=
'
/dev/ttyS0
'
ser2
.
baudrate
=
115200
ser2
.
bytesize
=
serial
.
EIGHTBITS
ser2
.
stopbits
=
serial
.
STOPBITS_ONE
ser2
.
parity
=
serial
.
PARITY_NONE
ser2
.
timeout
=
0.2
ser2
.
open
()
ser2
.
write
((
"
command;
"
).
encode
(
'
utf-8
'
))
ser2
.
read_all
()
host
=
"
192.168.42.2
"
port
=
40923
address
=
(
host
,
int
(
port
))
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
(
address
)
s
.
send
((
"
command;
"
).
encode
(
'
utf-8
'
))
class
vel_from_ros_node
(
Node
):
def
__init__
(
self
):
super
().
__init__
(
"
el_from_ros
"
)
super
().
__init__
(
"
v
el_from_ros
"
)
self
.
get_vel_from_ros_
=
self
.
create_subscription
(
Twist
,
"
/cmd_vel
_out
"
,
self
.
pose_callback
,
10
)
Twist
,
"
/cmd_vel
"
,
self
.
pose_callback
,
10
)
def
pose_callback
(
self
,
msg
:
Twist
):
command
=
"
chassis speed x
"
+
str
(
msg
.
linear
.
x
)
+
"
y
"
+
str
(
msg
.
linear
.
y
)
+
"
z
"
+
str
(
msg
.
angular
.
z
)
+
"
;
"
ser2
.
write
(
command
.
encode
(
'
utf-8
'
))
leer
=
ser2
.
readall
()
s
.
send
(
command
.
encode
(
'
utf-8
'
))
...
...
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