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
b705bf6b
Commit
b705bf6b
authored
6 years ago
by
mcsauder
Committed by
Beat Küng
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Cut case MAVLINK_MSG_ID_HIL_SENSOR content and paste into handle_message_hil_sensor() method.
parent
37cda4e2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/modules/simulator/simulator.h
+1
-0
1 addition, 0 deletions
src/modules/simulator/simulator.h
src/modules/simulator/simulator_mavlink.cpp
+66
-62
66 additions, 62 deletions
src/modules/simulator/simulator_mavlink.cpp
with
67 additions
and
62 deletions
src/modules/simulator/simulator.h
+
1
−
0
View file @
b705bf6b
...
...
@@ -332,6 +332,7 @@ private:
void
handle_message
(
mavlink_message_t
*
msg
);
void
handle_message_distance_sensor
(
const
mavlink_message_t
*
msg
);
void
handle_message_hil_sensor
(
const
mavlink_message_t
*
msg
);
void
handle_message_hil_state_quaternion
(
const
mavlink_message_t
*
msg
);
void
handle_message_landing_target
(
const
mavlink_message_t
*
msg
);
void
handle_message_optical_flow
(
const
mavlink_message_t
*
msg
);
...
...
This diff is collapsed.
Click to expand it.
src/modules/simulator/simulator_mavlink.cpp
+
66
−
62
View file @
b705bf6b
...
...
@@ -292,68 +292,8 @@ void Simulator::update_gps(mavlink_hil_gps_t *gps_sim)
void
Simulator
::
handle_message
(
mavlink_message_t
*
msg
)
{
switch
(
msg
->
msgid
)
{
case
MAVLINK_MSG_ID_HIL_SENSOR
:
{
mavlink_hil_sensor_t
imu
;
mavlink_msg_hil_sensor_decode
(
msg
,
&
imu
);
// set temperature to a decent value
imu
.
temperature
=
32.0
f
;
struct
timespec
ts
;
abstime_to_ts
(
&
ts
,
imu
.
time_usec
);
px4_clock_settime
(
CLOCK_MONOTONIC
,
&
ts
);
hrt_abstime
now_us
=
hrt_absolute_time
();
#if 0
// This is just for to debug missing HIL_SENSOR messages.
static hrt_abstime last_time = 0;
hrt_abstime diff = now_us - last_time;
float step = diff / 4000.0f;
if (step > 1.1f || step < 0.9f) {
PX4_INFO("HIL_SENSOR: imu time_usec: %lu, time_usec: %lu, diff: %lu, step: %.2f", imu.time_usec, now_us, diff, step);
}
last_time = now_us;
#endif
if
(
_publish
)
{
publish_sensor_topics
(
&
imu
);
}
update_sensors
(
&
imu
);
// battery simulation (limit update to 100Hz)
if
(
hrt_elapsed_time
(
&
_battery_status
.
timestamp
)
>=
10
_ms
)
{
const
float
discharge_interval_us
=
_battery_drain_interval_s
.
get
()
*
1000
*
1000
;
bool
armed
=
(
_vehicle_status
.
arming_state
==
vehicle_status_s
::
ARMING_STATE_ARMED
);
if
(
!
armed
||
batt_sim_start
==
0
||
batt_sim_start
>
now_us
)
{
batt_sim_start
=
now_us
;
}
float
ibatt
=
-
1.0
f
;
// no current sensor in simulation
const
float
minimum_percentage
=
0.499
f
;
// change this value if you want to simulate low battery reaction
/* Simulate the voltage of a linearly draining battery but stop at the minimum percentage */
float
battery_percentage
=
1.0
f
-
(
now_us
-
batt_sim_start
)
/
discharge_interval_us
;
battery_percentage
=
math
::
max
(
battery_percentage
,
minimum_percentage
);
float
vbatt
=
math
::
gradual
(
battery_percentage
,
0.
f
,
1.
f
,
_battery
.
empty_cell_voltage
(),
_battery
.
full_cell_voltage
());
vbatt
*=
_battery
.
cell_count
();
const
float
throttle
=
0.0
f
;
// simulate no throttle compensation to make the estimate predictable
_battery
.
updateBatteryStatus
(
now_us
,
vbatt
,
ibatt
,
true
,
true
,
0
,
throttle
,
armed
,
&
_battery_status
);
// publish the battery voltage
int
batt_multi
;
orb_publish_auto
(
ORB_ID
(
battery_status
),
&
_battery_pub
,
&
_battery_status
,
&
batt_multi
,
ORB_PRIO_HIGH
);
}
}
case
MAVLINK_MSG_ID_HIL_SENSOR
:
handle_message_hil_sensor
(
msg
);
break
;
case
MAVLINK_MSG_ID_HIL_OPTICAL_FLOW
:
...
...
@@ -411,6 +351,70 @@ void Simulator::handle_message_distance_sensor(const mavlink_message_t *msg)
publish_distance_topic
(
&
dist
);
}
void
Simulator
::
handle_message_hil_sensor
(
const
mavlink_message_t
*
msg
)
{
mavlink_hil_sensor_t
imu
;
mavlink_msg_hil_sensor_decode
(
msg
,
&
imu
);
// set temperature to a decent value
imu
.
temperature
=
32.0
f
;
struct
timespec
ts
;
abstime_to_ts
(
&
ts
,
imu
.
time_usec
);
px4_clock_settime
(
CLOCK_MONOTONIC
,
&
ts
);
hrt_abstime
now_us
=
hrt_absolute_time
();
#if 0
// This is just for to debug missing HIL_SENSOR messages.
static hrt_abstime last_time = 0;
hrt_abstime diff = now_us - last_time;
float step = diff / 4000.0f;
if (step > 1.1f || step < 0.9f) {
PX4_INFO("HIL_SENSOR: imu time_usec: %lu, time_usec: %lu, diff: %lu, step: %.2f", imu.time_usec, now_us, diff, step);
}
last_time = now_us;
#endif
if
(
_publish
)
{
publish_sensor_topics
(
&
imu
);
}
update_sensors
(
&
imu
);
// battery simulation (limit update to 100Hz)
if
(
hrt_elapsed_time
(
&
_battery_status
.
timestamp
)
>=
10
_ms
)
{
const
float
discharge_interval_us
=
_battery_drain_interval_s
.
get
()
*
1000
*
1000
;
bool
armed
=
(
_vehicle_status
.
arming_state
==
vehicle_status_s
::
ARMING_STATE_ARMED
);
if
(
!
armed
||
batt_sim_start
==
0
||
batt_sim_start
>
now_us
)
{
batt_sim_start
=
now_us
;
}
float
ibatt
=
-
1.0
f
;
// no current sensor in simulation
const
float
minimum_percentage
=
0.499
f
;
// change this value if you want to simulate low battery reaction
/* Simulate the voltage of a linearly draining battery but stop at the minimum percentage */
float
battery_percentage
=
1.0
f
-
(
now_us
-
batt_sim_start
)
/
discharge_interval_us
;
battery_percentage
=
math
::
max
(
battery_percentage
,
minimum_percentage
);
float
vbatt
=
math
::
gradual
(
battery_percentage
,
0.
f
,
1.
f
,
_battery
.
empty_cell_voltage
(),
_battery
.
full_cell_voltage
());
vbatt
*=
_battery
.
cell_count
();
const
float
throttle
=
0.0
f
;
// simulate no throttle compensation to make the estimate predictable
_battery
.
updateBatteryStatus
(
now_us
,
vbatt
,
ibatt
,
true
,
true
,
0
,
throttle
,
armed
,
&
_battery_status
);
// publish the battery voltage
int
batt_multi
;
orb_publish_auto
(
ORB_ID
(
battery_status
),
&
_battery_pub
,
&
_battery_status
,
&
batt_multi
,
ORB_PRIO_HIGH
);
}
}
void
Simulator
::
handle_message_hil_state_quaternion
(
const
mavlink_message_t
*
msg
)
{
mavlink_hil_state_quaternion_t
hil_state
;
...
...
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