Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
48402017
Commit
48402017
authored
10 years ago
by
Roman Bapst
Browse files
Options
Downloads
Patches
Plain Diff
further progress on mixer node
parent
67c49303
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CMakeLists.txt
+9
-0
9 additions, 0 deletions
CMakeLists.txt
src/platforms/ros/nodes/mc_mixer.cpp
+97
-4
97 additions, 4 deletions
src/platforms/ros/nodes/mc_mixer.cpp
with
106 additions
and
4 deletions
CMakeLists.txt
+
9
−
0
View file @
48402017
...
...
@@ -182,6 +182,15 @@ target_link_libraries(att_estimator
px4
)
## Multicopter Mixer dummy
add_executable
(
mc_mixer
src/platforms/ros/nodes/mc_mixer.cpp
)
add_dependencies
(
mc_mixer px4_generate_messages_cpp
)
target_link_libraries
(
mc_mixer
${
catkin_LIBRARIES
}
px4
)
#############
## Install ##
...
...
This diff is collapsed.
Click to expand it.
src/platforms/ros/nodes/mc_mixer.cpp
+
97
−
4
View file @
48402017
e
/****************************************************************************
/****************************************************************************
*
* Copyright (c) 2014 PX4 Development Team. All rights reserved.
*
...
...
@@ -37,7 +37,19 @@ e/****************************************************************************
*
* @author Roman Bapst <romanbapst@yahoo.de>
*/
#include
"ros/ros.h"
#include
<ros/ros.h>
#include
<px4.h>
#include
<lib/mathlib/mathlib.h>
#include
<mav_msgs/MotorSpeed.h>
#define _rotor_count 4
struct
Rotor
{
float
roll_scale
;
float
pitch_scale
;
float
yaw_scale
;
};
struct
{
float
control
[
8
];
...
...
@@ -47,16 +59,96 @@ e/****************************************************************************
float
control
[
8
];
}
outputs
;
void
mix
(
void
*
input
)
{
const
Rotor
_config_x
[]
=
{
{
0.000000
,
-
1.000000
,
-
1.00
},
{
-
0.000000
,
1.000000
,
-
1.00
},
{
1.000000
,
0.000000
,
1.00
},
{
-
1.000000
,
0.000000
,
1.00
},
};
const
Rotor
*
_rotors
=
{
&
_config_x
[
0
]
};
void
mix
()
{
float
roll
=
math
::
constrain
(
inputs
.
control
[
0
],
-
1.0
f
,
1.0
f
);
float
pitch
=
math
::
constrain
(
inputs
.
control
[
1
],
-
1.0
f
,
1.0
f
);
float
yaw
=
math
::
constrain
(
inputs
.
control
[
2
],
-
1.0
f
,
1.0
f
);
float
thrust
=
math
::
constrain
(
inputs
.
control
[
3
],
0.0
f
,
1.0
f
);
float
min_out
=
0.0
f
;
float
max_out
=
0.0
f
;
/* perform initial mix pass yielding unbounded outputs, ignore yaw */
for
(
unsigned
i
=
0
;
i
<
_rotor_count
;
i
++
)
{
float
out
=
roll
*
_rotors
[
i
].
roll_scale
+
pitch
*
_rotors
[
i
].
pitch_scale
+
thrust
;
/* limit yaw if it causes outputs clipping */
if
(
out
>=
0.0
f
&&
out
<
-
yaw
*
_rotors
[
i
].
yaw_scale
)
{
yaw
=
-
out
/
_rotors
[
i
].
yaw_scale
;
}
/* calculate min and max output values */
if
(
out
<
min_out
)
{
min_out
=
out
;
}
if
(
out
>
max_out
)
{
max_out
=
out
;
}
outputs
.
control
[
i
]
=
out
;
}
/* scale down roll/pitch controls if some outputs are negative, don't add yaw, keep total thrust */
if
(
min_out
<
0.0
f
)
{
float
scale_in
=
thrust
/
(
thrust
-
min_out
);
/* mix again with adjusted controls */
for
(
unsigned
i
=
0
;
i
<
_rotor_count
;
i
++
)
{
outputs
.
control
[
i
]
=
scale_in
*
(
roll
*
_rotors
[
i
].
roll_scale
+
pitch
*
_rotors
[
i
].
pitch_scale
)
+
thrust
;
}
}
else
{
/* roll/pitch mixed without limiting, add yaw control */
for
(
unsigned
i
=
0
;
i
<
_rotor_count
;
i
++
)
{
outputs
.
control
[
i
]
+=
yaw
*
_rotors
[
i
].
yaw_scale
;
}
}
/* scale down all outputs if some outputs are too large, reduce total thrust */
float
scale_out
;
if
(
max_out
>
1.0
f
)
{
scale_out
=
1.0
f
/
max_out
;
}
else
{
scale_out
=
1.0
f
;
}
/* scale outputs to range _idle_speed..1, and do final limiting */
for
(
unsigned
i
=
0
;
i
<
_rotor_count
;
i
++
)
{
outputs
.
control
[
i
]
=
math
::
constrain
(
outputs
.
control
[
i
],
0.0
f
,
1.0
f
);
}
}
void
actuatorControlsCallback
(
const
PX4_TOPIC_T
(
actuator_controls_0
)
&
msg
)
{
// read message
memcpy
(
inputs
,
msg
,
sizeof
(
inputs
));
for
(
int
i
=
0
;
i
<
msg
.
NUM_ACTUATOR_CONTROLS
;
i
++
)
{
inputs
.
control
[
i
]
=
msg
.
control
[
i
];
}
// mix
mix
();
// publish message
mav_msgs
::
MotorSpeed
rotor_vel_msg
;
for
(
int
i
=
0
;
i
<
_rotor_count
;
i
++
)
{
rotor_vel_msg
.
motor_speed
.
push_back
(
outputs
.
control
[
i
]);
}
pub
.
publish
(
rotor_vel_msg
);
}
...
...
@@ -65,6 +157,7 @@ void mix(void *input) {
ros
::
init
(
argc
,
argv
,
"mc_mixer"
);
ros
::
NodeHandle
n
;
ros
::
Subscriber
sub
=
n
.
subscribe
(
"actuator_controls_0"
,
1000
,
actuatorControlsCallback
);
ros
::
Publisher
pub
=
n
.
advertise
<
mav_msgs
::
MotorSpeed
>
(
"mixed_motor_commands"
,
10
);
ros
::
spin
();
...
...
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