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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
f3a2750f
Commit
f3a2750f
authored
4 months ago
by
Paul-Winpenny
Browse files
Options
Downloads
Patches
Plain Diff
Added the motorcontrol into robobin
parent
c348b55d
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
ros2/src/robobin/launch/robobin_launch.py
+7
-1
7 additions, 1 deletion
ros2/src/robobin/launch/robobin_launch.py
ros2/src/robobin/robobin/motor_control_node.py
+67
-0
67 additions, 0 deletions
ros2/src/robobin/robobin/motor_control_node.py
with
74 additions
and
1 deletion
ros2/src/robobin/launch/robobin_launch.py
+
7
−
1
View file @
f3a2750f
...
...
@@ -7,10 +7,16 @@ def generate_launch_description():
return
LaunchDescription
([
Node
(
package
=
'
robobin
'
,
executable
=
'
api_node
'
,
# Name of your first node
executable
=
'
api_node
'
,
name
=
'
api_node
'
,
output
=
'
screen
'
),
Node
(
package
=
'
robobin
'
,
executable
=
'
motor_control_node
'
,
name
=
'
motor_control_node
'
,
output
=
'
screen
'
),
# Add additional nodes
# Example:
# Node(
...
...
This diff is collapsed.
Click to expand it.
ros2/src/robobin/robobin/motor_control_node.py
0 → 100644
+
67
−
0
View file @
f3a2750f
import
rclpy
from
rclpy.node
import
Node
from
geometry_msgs.msg
import
Twist
class
MotorController
(
Node
):
def
__init__
(
self
):
super
().
__init__
(
'
motor_controller
'
)
self
.
subscription
=
self
.
create_subscription
(
Twist
,
'
cmd_vel
'
,
self
.
cmd_vel_callback
,
10
)
self
.
wheel_radius
=
0.05
# meters
self
.
wheel_base
=
0.30
self
.
get_logger
().
info
(
"
hello
"
)
def
cmd_vel_callback
(
self
,
msg
):
v
=
msg
.
linear
.
x
omega
=
msg
.
angular
.
z
# self.get_logger().info(f"linearx: {v}, angluarz: {omega}")
# v_left = v - (self.wheel_base / 2.0) * omega
# v_right = v + (self.wheel_base / 2.0) * omega
# max_speed = 1.0
# # Normalize speeds to -1.0 to 1.0
# left_speed = max(min(v_left / max_speed, 1.0), -1.0)
# right_speed = max(min(v_right / max_speed, 1.0), -1.0)
# # Convert to PWM duty cycle (0 to 100)
# left_pwm = int((left_speed + 1.0) / 2.0 * 100)
# right_pwm = int((right_speed + 1.0) / 2.0 * 100)
if
omega
==
1
:
left_pwm
=
-
50
right_pwm
=
50
elif
omega
==
-
1
:
left_pwm
=
50
right_pwm
=
-
50
if
v
==
0.5
:
left_pwm
=
75
right_pwm
=
75
elif
v
==
-
0.5
:
left_pwm
=
-
75
right_pwm
=
-
75
self
.
get_logger
().
info
(
f
"
Left PWM:
{
left_pwm
}
, Right PWM:
{
right_pwm
}
"
)
# Set motor directions based on sign of speeds
# left_direction = 1 if left_speed >= 0 else 0
# right_direction = 1 if right_speed >= 0 else 0
def
main
(
args
=
None
):
rclpy
.
init
(
args
=
args
)
node
=
MotorController
()
rclpy
.
spin
(
node
)
node
.
destroy_node
()
rclpy
.
shutdown
()
if
__name__
==
'
__main__
'
:
main
()
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