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
134dc9b9
Commit
134dc9b9
authored
1 year ago
by
Emil Harlan
Browse files
Options
Downloads
Patches
Plain Diff
a
parent
5555a85e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
robomaster_pi/conn_vel.py
+23
-35
23 additions, 35 deletions
robomaster_pi/conn_vel.py
with
23 additions
and
35 deletions
robomaster_pi/conn_vel.py
+
23
−
35
View file @
134dc9b9
...
...
@@ -11,63 +11,51 @@ from geometry_msgs.msg import TransformStamped
from
geometry_msgs.msg
import
Twist
from
tf2_ros
import
TransformBroadcaster
import
os
from
rclpy.node
import
Node
from
rclpy.node
import
Node
x
,
y
,
z
=
0
,
0
,
0
import
socket
def
quaternion_from_euler
(
ai
,
aj
,
ak
):
ai
/=
2.0
aj
/=
2.0
ak
/=
2.0
ci
=
math
.
cos
(
ai
)
si
=
math
.
sin
(
ai
)
cj
=
math
.
cos
(
aj
)
sj
=
math
.
sin
(
aj
)
ck
=
math
.
cos
(
ak
)
sk
=
math
.
sin
(
ak
)
cc
=
ci
*
ck
cs
=
ci
*
sk
sc
=
si
*
ck
ss
=
si
*
sk
q
=
np
.
empty
((
4
,
))
q
[
0
]
=
cj
*
sc
-
sj
*
cs
q
[
1
]
=
cj
*
ss
+
sj
*
cc
q
[
2
]
=
cj
*
cs
-
sj
*
sc
q
[
3
]
=
cj
*
cc
+
sj
*
ss
return
q
class
vel_from_ros_node
(
Node
):
def
__init__
(
self
,
my_ep_chassis
):
super
().
__init__
(
"
vel_from_ros
"
)
self
.
hostname
=
"
192.168.1.77
"
self
.
response
=
1
self
.
response
=
False
Timer
(
1
,
self
.
check_connection
)
self
.
my_ep_chassis
=
my_ep_chassis
self
.
get_vel_from_ros_
=
self
.
create_subscription
(
Twist
,
"
/cmd_vel
"
,
self
.
pose_callback
,
10
)
def
check_connection
():
self
.
response
=
self
.
isConnected
()
if
(
self
.
response
=
!
True
):
self
.
my_ep_chassis
.
drive_speed
(
x
=
0
,
y
=
0
,
z
=
0.5
)
def
isConnected
():
try
:
# connect to the host -- tells us if the host is actually
# reachable
sock
=
socket
.
create_connection
((
"
www.google.com
"
,
80
))
if
sock
is
not
None
:
print
(
'
Clossing socket
'
)
sock
.
close
return
True
except
OSError
:
pass
return
False
def
check_connection
():
self
.
response
=
os
.
system
(
"
ping -c 1
"
+
self
.
hostname
)
def
pose_callback
(
self
,
msg
:
Twist
):
if
((
msg
.
angular
.
z
==
0.0
and
msg
.
linear
.
x
==
0.0
and
msg
.
linear
.
y
==
0.0
)
or
self
.
response
=
=
0
):
if
((
msg
.
angular
.
z
==
0.0
and
msg
.
linear
.
x
==
0.0
and
msg
.
linear
.
y
==
0.0
)
or
response
!
=
True
):
self
.
my_ep_chassis
.
drive_speed
(
x
=
0
,
y
=
0
,
z
=
0.5
)
else
:
self
.
my_ep_chassis
.
drive_speed
(
x
=
msg
.
linear
.
x
,
y
=
-
msg
.
linear
.
y
,
z
=
-
msg
.
angular
.
z
*
(
180
/
math
.
pi
))
...
...
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