Skip to content

Commit

Permalink
change pwm_out rate to fix the cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mengchaoheng committed May 8, 2021
1 parent 821694b commit 3956ec3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
5 changes: 5 additions & 0 deletions imu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mems FIFORead -> ProcessGyro or ProcessAccel ->
PX4Geroscop's updateFIFO or PX4Accelerometer's updateFIFO ->
publish sensor_gyro_fifo and sensor_gyro

src/drivers, which used in the rc.board_sensors -> src/lib/drivers -> src/modules/sensors
37 changes: 34 additions & 3 deletions readme_pwm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,31 @@ It is used in the startup script to make sure the PWM parameters (`PWM_*`) are a
by the airframe config if specified). `pwm info` shows the current settings (the trim value is an offset
and configured with `PWM_MAIN_TRIMx` and `PWM_AUX_TRIMx`).
-------------------------------------------------------------------------------------------------------------------------------------------------
lib/mixer:












1.lib/mixer:

lib of mixer and Group of mixers, built up from single mixers and processed in order when mixing.
-------------------------------------------------------------------------------------------------------------------------------------------------
lib/mixer_module:

2.lib/mixer_module:

This handles the mixing, arming/disarming and all subscriptions required for that.

using lib/mixer
-------------------------------------------------------------------------------------------------------------------------------------------------
drivers/pwm_out:

3.drivers/pwm_out:

This module is responsible for driving the output and reading the input pins. For boards without a separate IO chip
(eg. Pixracer), it uses the main channels. On boards with an IO chip (eg. Pixhawk), it uses the AUX channels, and the
Expand All @@ -34,6 +48,23 @@ callback with ioctl calls.

using lib/mixer_module
-------------------------------------------------------------------------------------------------------------------------------------------------

















drivers/px4io:

Encapsulates PX4FMU to PX4IO communications modeled as file operations.
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/pwm_out/PWMOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ void PWMOut::update_current_rate()
}

// max interval 0.5 - 100 ms (10 - 2000Hz)
const int update_interval_in_us = math::constrain(1000000 / max_rate, 500, 100000);
// const int update_interval_in_us = math::constrain(1000000 / max_rate, 500, 100000);
const int update_interval_in_us = math::constrain(1000000 / max_rate, 4000, 10000);//4ms - 100ms (10 - 250Hz)

_current_update_rate = max_rate;
_mixing_output.setMaxTopicUpdateRate(update_interval_in_us);
Expand Down
15 changes: 10 additions & 5 deletions src/lib/mixer_module/mixer_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ bool MixingOutput::update()
// PX4_INFO("dir_alloc_sim:\n");
if (_param_use_control_alloc.get() == 1)
{
uint64_t timestamp_ca_start;
uint64_t timestamp_ca_end;
timestamp_ca_start = hrt_absolute_time();
// uint64_t timestamp_ca_start;
// uint64_t timestamp_ca_end;
// timestamp_ca_start = hrt_absolute_time();
float roll=0.0;
float pitch=0.0;
float yaw=0.0;
Expand All @@ -460,15 +460,20 @@ bool MixingOutput::update()
// double d2r=3.141592653/180;
// double r2d=180/3.141592653;
dir_alloc_sim(yd, uMin, uMax, u, &z, &iters);
for (size_t i = 0; i < 4; i++)
{
u[i] = 0.0;
}
dir_alloc_sim(yd, uMin, uMax, u, &z, &iters);

// PX4_INFO("iters: %f, z: %f, u1: %f, u2: %f, u3: %f, u4: %f. \n", iters, z, u[0]*r2d, u[1]*r2d, u[2]*r2d, u[3]*r2d);
for (size_t i = 0; i < 4; i++)
{
outputs[i+2] = (float) u[i];
}
timestamp_ca_end = hrt_absolute_time();
// timestamp_ca_end = hrt_absolute_time();
// PX4_INFO("dir_alloc_sim time: %lld \n", (timestamp_ca_end - timestamp_ca_start) ); //muttx
PX4_INFO("dir_alloc_sim time: %ld \n", (timestamp_ca_end - timestamp_ca_start) ); //sitl
// PX4_INFO("dir_alloc_sim time: %ld \n", (timestamp_ca_end - timestamp_ca_start) ); //sitl
}

/* the output limit call takes care of out of band errors, NaN and constrains */
Expand Down
2 changes: 2 additions & 0 deletions src/modules/logger/logged_topics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ void LoggedTopics::add_vision_and_avoidance_topics()
void LoggedTopics::add_raw_imu_gyro_fifo()
{
add_topic("sensor_gyro_fifo");
// add_topic_multi("sensor_gyro_fifo");
// add_topic_multi("sensor_gyro");
}

void LoggedTopics::add_raw_imu_accel_fifo()
Expand Down
2 changes: 1 addition & 1 deletion src/modules/uORB/SubscriptionInterval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace uORB
{

// Base subscription wrapper class
class SubscriptionInterval
class SubscriptionInterval
{
public:

Expand Down

0 comments on commit 3956ec3

Please sign in to comment.