Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Robobin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
13518468
Commit
13518468
authored
7 months ago
by
Paul-Winpenny
Browse files
Options
Downloads
Patches
Plain Diff
Fixed PWM
parent
661681c0
No related branches found
No related tags found
1 merge request
!2
Manual control user interface
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ros2/src/robobin/robobin/motor_control_node.py
+29
-18
29 additions, 18 deletions
ros2/src/robobin/robobin/motor_control_node.py
with
29 additions
and
18 deletions
ros2/src/robobin/robobin/motor_control_node.py
+
29
−
18
View file @
13518468
...
@@ -6,12 +6,23 @@ class MotorController(Node):
...
@@ -6,12 +6,23 @@ class MotorController(Node):
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
(
'
motor_controller
'
)
super
().
__init__
(
'
motor_controller
'
)
self
.
get_logger
().
info
(
"
Motor Controller has been started.
"
)
self
.
get_logger
().
info
(
"
Motor Controller has been started.
"
)
self
.
subscription
=
self
.
create_subscription
(
Twist
,
'
cmd_vel
'
,
self
.
cmd_vel_callback
,
10
)
self
.
wheel_radius
=
0.05
# meters
self
.
subscription
=
self
.
create_subscription
(
Twist
,
'
cmd_vel
'
,
self
.
cmd_vel_callback
,
10
)
self
.
wheel_radius
=
0.05
self
.
wheel_base
=
0.30
self
.
wheel_base
=
0.30
self
.
get_logger
().
info
(
"
hello
"
)
self
.
left_pwm
=
0
self
.
right_pwm
=
0
self
.
get_logger
().
info
(
"
hello
"
)
def
cmd_vel_callback
(
self
,
msg
):
def
cmd_vel_callback
(
self
,
msg
):
v
=
msg
.
linear
.
x
v
=
msg
.
linear
.
x
...
@@ -33,26 +44,26 @@ class MotorController(Node):
...
@@ -33,26 +44,26 @@ class MotorController(Node):
# right_pwm = int((right_speed + 1.0) / 2.0 * 100)
# right_pwm = int((right_speed + 1.0) / 2.0 * 100)
if
omega
==
1
:
if
omega
==
1
:
left_pwm
=
-
50
self
.
left_pwm
=
-
50
right_pwm
=
50
self
.
right_pwm
=
50
elif
omega
==
-
1
:
elif
omega
==
-
1
:
left_pwm
=
50
self
.
left_pwm
=
50
right_pwm
=
-
50
self
.
right_pwm
=
-
50
# Handle linear velocity commands
if
v
==
0.5
:
if
v
==
0.5
:
left_pwm
=
75
self
.
left_pwm
=
75
right_pwm
=
75
self
.
right_pwm
=
75
elif
v
==
-
0.5
:
elif
v
==
-
0.5
:
left_pwm
=
-
75
self
.
left_pwm
=
-
75
right_pwm
=
-
75
self
.
right_pwm
=
-
75
# STOP command
if
v
==
0
and
omega
==
0
:
if
v
==
0
and
omega
==
0
:
left_pwm
=
0
self
.
left_pwm
=
0
right_pwm
=
0
self
.
right_pwm
=
0
self
.
get_logger
().
info
(
"
STOP command received. Motors stopped.
"
)
self
.
get_logger
().
info
(
"
STOP command received. Motors stopped.
"
)
self
.
get_logger
().
info
(
f
"
Left PWM:
{
left_pwm
}
, Right PWM:
{
right_pwm
}
"
)
self
.
get_logger
().
info
(
f
"
Left PWM:
{
self
.
left_pwm
}
, Right PWM:
{
self
.
right_pwm
}
"
)
# Set motor directions based on sign of speeds
# Set motor directions based on sign of speeds
# left_direction = 1 if left_speed >= 0 else 0
# left_direction = 1 if left_speed >= 0 else 0
...
...
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