Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dynamixel_motor_cont
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
labrobotica
drivers
dynamixel_motor_cont
Commits
fdecbe26
Commit
fdecbe26
authored
5 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Implemented the velcoity control mode.
parent
dec7c6aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dynamixel_motor.cpp
+75
-19
75 additions, 19 deletions
src/dynamixel_motor.cpp
with
75 additions
and
19 deletions
src/dynamixel_motor.cpp
+
75
−
19
View file @
fdecbe26
...
@@ -88,7 +88,10 @@ unsigned int CDynamixelMotor::from_speeds(double speed)
...
@@ -88,7 +88,10 @@ unsigned int CDynamixelMotor::from_speeds(double speed)
if
(
speed
>
this
->
info
.
max_speed
)
if
(
speed
>
this
->
info
.
max_speed
)
speed
=
this
->
info
.
max_speed
;
speed
=
this
->
info
.
max_speed
;
counts
=
fabs
(
speed
)
/
0.666
;
if
(
this
->
info
.
ext_memory_map
)
counts
=
speed
/
0.229
;
else
counts
=
fabs
(
speed
)
/
0.666
;
return
counts
;
return
counts
;
}
}
...
@@ -106,7 +109,10 @@ double CDynamixelMotor::to_speeds(unsigned int counts)
...
@@ -106,7 +109,10 @@ double CDynamixelMotor::to_speeds(unsigned int counts)
{
{
double
speed
;
double
speed
;
speed
=
counts
*
0.666
;
// Taken from the datasheets (sfoix)
if
(
this
->
info
.
ext_memory_map
)
speed
=
counts
*
0.229
;
else
speed
=
counts
*
0.666
;
// Taken from the datasheets (sfoix)
return
speed
;
return
speed
;
}
}
...
@@ -787,12 +793,21 @@ void CDynamixelMotor::set_current_limit(double current)
...
@@ -787,12 +793,21 @@ void CDynamixelMotor::set_current_limit(double current)
double
CDynamixelMotor
::
get_speed_limit
(
void
)
double
CDynamixelMotor
::
get_speed_limit
(
void
)
{
{
unsigned
int
data
;
double
speed
;
this
->
read_register
(
this
->
registers
[
velocity_limit
],
data
);
speed
=
this
->
to_speeds
(
data
);
return
speed
;
}
}
void
CDynamixelMotor
::
set_speed_limit
(
double
speed
)
void
CDynamixelMotor
::
set_speed_limit
(
double
speed
)
{
{
unsigned
int
data
;
data
=
this
->
from_speeds
(
speed
);
this
->
write_register
(
this
->
registers
[
velocity_limit
],
data
);
}
}
...
@@ -995,27 +1010,60 @@ void CDynamixelMotor::move_absolute_angle(double angle,double speed,double curre
...
@@ -995,27 +1010,60 @@ void CDynamixelMotor::move_absolute_angle(double angle,double speed,double curre
void
CDynamixelMotor
::
move_relative_angle
(
double
angle
,
double
speed
,
double
current
)
void
CDynamixelMotor
::
move_relative_angle
(
double
angle
,
double
speed
,
double
current
)
{
{
unsigned
int
cmd
[
2
]
,
pos
;
unsigned
int
data
,
pos
;
double
abs_angle
;
double
abs_angle
;
this
->
set_control_mode
(
position_ctrl
);
if
(
current
==
std
::
numeric_limits
<
double
>::
infinity
())
this
->
read_register
(
this
->
registers
[
current_pos
],
pos
);
{
abs_angle
=
angle
+
this
->
to_angles
(
pos
);
this
->
set_control_mode
(
position_ctrl
);
if
(
abs_angle
>
this
->
info
.
center_angle
)
this
->
read_register
(
this
->
registers
[
current_pos
],
pos
);
abs_angle
=
this
->
info
.
center_angle
;
abs_angle
=
angle
+
this
->
to_angles
(
pos
);
else
if
(
abs_angle
<-
this
->
info
.
center_angle
)
if
(
abs_angle
>
this
->
info
.
center_angle
)
abs_angle
=-
this
->
info
.
center_angle
;
abs_angle
=
this
->
info
.
center_angle
;
cmd
[
0
]
=
this
->
from_angles
(
abs_angle
);
else
if
(
abs_angle
<-
this
->
info
.
center_angle
)
this
->
write_register
(
this
->
registers
[
goal_pos
],
cmd
[
0
]);
abs_angle
=-
this
->
info
.
center_angle
;
if
(
speed
>
this
->
info
.
max_speed
)
data
=
this
->
from_angles
(
abs_angle
);
speed
=
this
->
info
.
max_speed
;
this
->
write_register
(
this
->
registers
[
goal_pos
],
data
);
cmd
[
1
]
=
this
->
from_speeds
(
speed
);
if
(
speed
>
this
->
info
.
max_speed
)
this
->
write_register
(
this
->
registers
[
goal_speed
],
cmd
[
1
]);
speed
=
this
->
info
.
max_speed
;
data
=
this
->
from_speeds
(
speed
);
this
->
write_register
(
this
->
registers
[
goal_speed
],
data
);
}
else
{
this
->
set_control_mode
(
current_pos_ctrl
);
if
(
current
>
this
->
info
.
max_current
)
current
=
this
->
info
.
max_current
;
else
if
(
current
<-
this
->
info
.
max_current
)
current
=-
this
->
info
.
max_current
;
data
=
(
signed
short
int
)(
current
*
1000.0
/
2.69
);
this
->
write_register
(
this
->
registers
[
goal_current
],
data
);
this
->
read_register
(
this
->
registers
[
current_pos
],
pos
);
abs_angle
=
angle
+
this
->
to_angles
(
pos
);
if
(
abs_angle
>
this
->
info
.
center_angle
)
abs_angle
=
this
->
info
.
center_angle
;
else
if
(
abs_angle
<-
this
->
info
.
center_angle
)
abs_angle
=-
this
->
info
.
center_angle
;
data
=
this
->
from_angles
(
abs_angle
);
this
->
write_register
(
this
->
registers
[
goal_pos
],
data
);
if
(
speed
>
this
->
info
.
max_speed
)
speed
=
this
->
info
.
max_speed
;
data
=
this
->
from_speeds
(
speed
);
this
->
write_register
(
this
->
registers
[
goal_speed
],
data
);
}
}
}
void
CDynamixelMotor
::
move_speed
(
double
speed
)
void
CDynamixelMotor
::
move_speed
(
double
speed
)
{
{
unsigned
int
data
;
this
->
set_control_mode
(
velocity_ctrl
);
if
(
speed
>
this
->
info
.
max_speed
)
speed
=
this
->
info
.
max_speed
;
else
if
(
speed
<-
this
->
info
.
max_speed
)
speed
=-
this
->
info
.
max_speed
;
data
=
this
->
from_speeds
(
speed
);
this
->
write_register
(
this
->
registers
[
goal_speed
],
data
);
}
}
void
CDynamixelMotor
::
move_pwm
(
double
pwm_ratio
)
void
CDynamixelMotor
::
move_pwm
(
double
pwm_ratio
)
...
@@ -1046,6 +1094,10 @@ void CDynamixelMotor::move_current(double current)
...
@@ -1046,6 +1094,10 @@ void CDynamixelMotor::move_current(double current)
unsigned
int
data
;
unsigned
int
data
;
this
->
set_control_mode
(
current_ctrl
);
this
->
set_control_mode
(
current_ctrl
);
if
(
current
>
this
->
info
.
max_current
)
current
=
this
->
info
.
max_current
;
else
if
(
current
<-
this
->
info
.
max_current
)
current
=-
this
->
info
.
max_current
;
data
=
(
signed
short
int
)(
current
*
1000.0
/
2.69
);
data
=
(
signed
short
int
)(
current
*
1000.0
/
2.69
);
this
->
write_register
(
this
->
registers
[
goal_current
],
data
);
this
->
write_register
(
this
->
registers
[
goal_current
],
data
);
}
}
...
@@ -1054,7 +1106,7 @@ void CDynamixelMotor::stop(void)
...
@@ -1054,7 +1106,7 @@ void CDynamixelMotor::stop(void)
{
{
unsigned
int
current_position
;
unsigned
int
current_position
;
if
(
this
->
mode
==
position_ctrl
)
if
(
this
->
mode
==
position_ctrl
||
this
->
mode
==
ext_position_ctrl
||
this
->
mode
==
current_pos_ctrl
)
{
{
this
->
read_register
(
this
->
registers
[
current_pos
],
current_position
);
this
->
read_register
(
this
->
registers
[
current_pos
],
current_position
);
if
(
this
->
to_angles
(
current_position
)
>
this
->
config
.
max_angle
)
if
(
this
->
to_angles
(
current_position
)
>
this
->
config
.
max_angle
)
...
@@ -1063,8 +1115,12 @@ void CDynamixelMotor::stop(void)
...
@@ -1063,8 +1115,12 @@ void CDynamixelMotor::stop(void)
current_position
=
from_angles
(
this
->
config
.
min_angle
);
current_position
=
from_angles
(
this
->
config
.
min_angle
);
this
->
write_register
(
this
->
registers
[
goal_pos
],
current_position
);
this
->
write_register
(
this
->
registers
[
goal_pos
],
current_position
);
}
}
else
else
if
(
this
->
mode
==
current_ctrl
)
this
->
write_register
(
this
->
registers
[
goal_speed
],
0
);
this
->
move_current
(
0.0
);
else
if
(
this
->
mode
==
velocity_ctrl
)
this
->
move_speed
(
0.0
);
else
if
(
this
->
mode
==
pwm_ctrl
)
this
->
move_pwm
(
0.0
);
}
}
double
CDynamixelMotor
::
get_current_angle
(
void
)
double
CDynamixelMotor
::
get_current_angle
(
void
)
...
...
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