Skip to content

Commit

Permalink
Merge branch 'master' into coleschon/tecs-vel-rate
Browse files Browse the repository at this point in the history
  • Loading branch information
coleschon authored Nov 2, 2023
2 parents 7e3920b + 73589a2 commit be6b7b9
Show file tree
Hide file tree
Showing 40 changed files with 478 additions and 97 deletions.
5 changes: 3 additions & 2 deletions Tools/AP_Periph/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,9 @@ void AP_Periph_FW::processTx(void)
active if it has had a successful transmit in the
last 2 seconds
*/
const auto *stats = _ins.iface->get_statistics();
if (stats == nullptr || now_us - stats->last_transmit_us < 2000000UL) {
volatile const auto *stats = _ins.iface->get_statistics();
uint64_t last_transmit_us = stats->last_transmit_us;
if (stats == nullptr || AP_HAL::micros64() - last_transmit_us < 2000000UL) {
sent = false;
}
} else {
Expand Down
10 changes: 10 additions & 0 deletions Tools/autotest/blimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,23 @@ def FlyLoiter(self):

self.disarm_vehicle()

def PREFLIGHT_Pressure(self):
'''test triggering pressure calibration with mavlink command'''
# as airspeed is not instantiated on Blimp we expect to
# instantly get back an accepted.
self.run_cmd(
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
p3=1, # p3, baro
)

def tests(self):
'''return list of all tests'''
# ret = super(AutoTestBlimp, self).tests()
ret = []
ret.extend([
self.FlyManual,
self.FlyLoiter,
self.PREFLIGHT_Pressure,
])
return ret

Expand Down
50 changes: 48 additions & 2 deletions Tools/autotest/rover.py
Original file line number Diff line number Diff line change
Expand Up @@ -5620,9 +5620,9 @@ def SendToComponents(self):
0,
0)

self.context_collect('COMMAND_LONG')

self.progress("Sending control message")
self.context_push()
self.context_collect('COMMAND_LONG')
self.mav.mav.digicam_control_send(
1, # target_system
1, # target_component
Expand All @@ -5641,6 +5641,52 @@ def SendToComponents(self):
'command': mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONTROL,
'param6': 17,
}, timeout=2, check_context=True)
self.context_pop()

# test sending via commands:
for run_cmd in self.run_cmd, self.run_cmd_int:
self.progress("Sending control command")
self.context_push()
self.context_collect('COMMAND_LONG')
run_cmd(mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONTROL,
p1=1, # start or keep it up
p2=1, # zoom_pos
p3=0, # zoom_step
p4=0, # focus_lock
p5=0, # 1 shot or start filming
p6=37, # command id (de-dupe field)
)

self.assert_received_message_field_values('COMMAND_LONG', {
'command': mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONTROL,
'param6': 37,
}, timeout=2, check_context=True)

self.context_pop()

# test sending via commands:
for run_cmd in self.run_cmd, self.run_cmd_int:
self.progress("Sending configure command")
self.context_push()
self.context_collect('COMMAND_LONG')
run_cmd(mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONFIGURE,
p1=1,
p2=1,
p3=0,
p4=0,
p5=12,
p6=37
)

self.assert_received_message_field_values('COMMAND_LONG', {
'command': mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONFIGURE,
'param5': 12,
'param6': 37,
}, timeout=2, check_context=True)

self.context_pop()

self.mav.mav.srcSystem = old_srcSystem

def SkidSteer(self):
'''Check skid-steering'''
Expand Down
1 change: 1 addition & 0 deletions Tools/scripts/build_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __init__(self,
Feature('Camera', 'Camera_Relay', 'AP_CAMERA_RELAY_ENABLED', 'Enable Camera Trigger via Relay support', 0, 'Camera,RELAY'),
Feature('Camera', 'Camera_Servo', 'AP_CAMERA_SERVO_ENABLED', 'Enable Camera Trigger via Servo support', 0, 'Camera'),
Feature('Camera', 'Camera_Solo', 'AP_CAMERA_SOLOGIMBAL_ENABLED', 'Enable Solo Gimbal support', 0, 'Camera'),
Feature('Camera', 'Camera_FOV_Status', 'AP_CAMERA_SEND_FOV_STATUS_ENABLED', 'Enable Camera FOV Status send to GCS', 0, 'Camera,MOUNT'), # noqa: E501

Feature('Camera', 'RUNCAM', 'HAL_RUNCAM_ENABLED', 'Enable RunCam Control', 0, None),

Expand Down
1 change: 1 addition & 0 deletions Tools/scripts/extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, filename, nm="arm-none-eabi-nm", strings="strings"):

('AP_CAMERA_ENABLED', 'AP_Camera::var_info',),
('AP_CAMERA_{type}_ENABLED', 'AP_Camera_(?P<type>.*)::trigger_pic',),
('AP_CAMERA_SEND_FOV_STATUS_ENABLED', 'AP_Camera::send_camera_fov_status'),
('HAL_RUNCAM_ENABLED', 'AP_RunCam::AP_RunCam',),

('HAL_PROXIMITY_ENABLED', 'AP_Proximity::AP_Proximity',),
Expand Down
29 changes: 22 additions & 7 deletions libraries/AP_Camera/AP_Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ void AP_Camera::handle_message(mavlink_channel_t chan, const mavlink_message_t &
}

// handle command_long mavlink messages
MAV_RESULT AP_Camera::handle_command_long(const mavlink_command_long_t &packet)
MAV_RESULT AP_Camera::handle_command(const mavlink_command_int_t &packet)
{
switch (packet.command) {
case MAV_CMD_DO_DIGICAM_CONFIGURE:
configure(packet.param1, packet.param2, packet.param3, packet.param4, packet.param5, packet.param6, packet.param7);
configure(packet.param1, packet.param2, packet.param3, packet.param4, packet.x, packet.y, packet.z);
return MAV_RESULT_ACCEPTED;
case MAV_CMD_DO_DIGICAM_CONTROL:
control(packet.param1, packet.param2, packet.param3, packet.param4, packet.param5, packet.param6);
control(packet.param1, packet.param2, packet.param3, packet.param4, packet.x, packet.y);
return MAV_RESULT_ACCEPTED;
case MAV_CMD_DO_SET_CAM_TRIGG_DIST:
set_trigger_distance(packet.param1);
Expand Down Expand Up @@ -438,7 +438,7 @@ void AP_Camera::cam_mode_toggle(uint8_t instance)
}

// configure camera
void AP_Camera::configure(float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time)
void AP_Camera::configure(float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time)
{
WITH_SEMAPHORE(_rsem);

Expand All @@ -448,7 +448,7 @@ void AP_Camera::configure(float shooting_mode, float shutter_speed, float apertu
primary->configure(shooting_mode, shutter_speed, aperture, ISO, exposure_type, cmd_id, engine_cutoff_time);
}

void AP_Camera::configure(uint8_t instance, float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time)
void AP_Camera::configure(uint8_t instance, float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time)
{
WITH_SEMAPHORE(_rsem);

Expand All @@ -462,7 +462,7 @@ void AP_Camera::configure(uint8_t instance, float shooting_mode, float shutter_s
}

// handle camera control
void AP_Camera::control(float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id)
void AP_Camera::control(float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id)
{
WITH_SEMAPHORE(_rsem);

Expand All @@ -472,7 +472,7 @@ void AP_Camera::control(float session, float zoom_pos, float zoom_step, float fo
primary->control(session, zoom_pos, zoom_step, focus_lock, shooting_cmd, cmd_id);
}

void AP_Camera::control(uint8_t instance, float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id)
void AP_Camera::control(uint8_t instance, float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id)
{
WITH_SEMAPHORE(_rsem);

Expand Down Expand Up @@ -526,6 +526,21 @@ void AP_Camera::send_camera_settings(mavlink_channel_t chan)
}
}

#if AP_CAMERA_SEND_FOV_STATUS_ENABLED
// send camera field of view status
void AP_Camera::send_camera_fov_status(mavlink_channel_t chan)
{
WITH_SEMAPHORE(_rsem);

// call each instance
for (uint8_t instance = 0; instance < AP_CAMERA_MAX_INSTANCES; instance++) {
if (_backends[instance] != nullptr) {
_backends[instance]->send_camera_fov_status(chan);
}
}
}
#endif

/*
update; triggers by distance moved and camera trigger
*/
Expand Down
15 changes: 10 additions & 5 deletions libraries/AP_Camera/AP_Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AP_Camera {
void handle_message(mavlink_channel_t chan, const mavlink_message_t &msg);

// handle MAVLink command from GCS to control the camera
MAV_RESULT handle_command_long(const mavlink_command_long_t &packet);
MAV_RESULT handle_command(const mavlink_command_int_t &packet);

// send camera feedback message to GCS
void send_feedback(mavlink_channel_t chan);
Expand All @@ -95,13 +95,18 @@ class AP_Camera {
// send camera settings message to GCS
void send_camera_settings(mavlink_channel_t chan);

#if AP_CAMERA_SEND_FOV_STATUS_ENABLED
// send camera field of view status
void send_camera_fov_status(mavlink_channel_t chan);
#endif

// configure camera
void configure(float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time);
void configure(uint8_t instance, float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time);
void configure(float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time);
void configure(uint8_t instance, float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time);

// handle camera control
void control(float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id);
void control(uint8_t instance, float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id);
void control(float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id);
void control(uint8_t instance, float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id);

// set camera trigger distance in a mission
void set_trigger_distance(float distance_m);
Expand Down
43 changes: 41 additions & 2 deletions libraries/AP_Camera/AP_Camera_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ void AP_Camera_Backend::stop_capture()
}

// handle camera control
void AP_Camera_Backend::control(float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id)
void AP_Camera_Backend::control(float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id)
{
// take picture
if (is_equal(shooting_cmd, 1.0f)) {
if (shooting_cmd == 1) {
take_picture();
}
}
Expand Down Expand Up @@ -247,6 +247,45 @@ void AP_Camera_Backend::send_camera_settings(mavlink_channel_t chan) const
NaN); // focusLevel float, percentage from 0 to 100, NaN if unknown
}

#if AP_CAMERA_SEND_FOV_STATUS_ENABLED
// send camera field of view status
void AP_Camera_Backend::send_camera_fov_status(mavlink_channel_t chan) const
{
// getting corresponding mount instance for camera
const AP_Mount* mount = AP::mount();
if (mount == nullptr) {
return;
}
Quaternion quat;
Location loc;
Location poi_loc;
if (!mount->get_poi(get_mount_instance(), quat, loc, poi_loc)) {
return;
}
// send camera fov status message only if the last calculated values aren't stale
const float NaN = nanf("0x4152");
const float quat_array[4] = {
quat.q1,
quat.q2,
quat.q3,
quat.q4
};
mavlink_msg_camera_fov_status_send(
chan,
AP_HAL::millis(),
loc.lat,
loc.lng,
loc.alt,
poi_loc.lat,
poi_loc.lng,
poi_loc.alt,
quat_array,
horizontal_fov() > 0 ? horizontal_fov() : NaN,
vertical_fov() > 0 ? vertical_fov() : NaN
);
}
#endif

// setup a callback for a feedback pin. When on PX4 with the right FMU
// mode we can use the microsecond timer.
void AP_Camera_Backend::setup_feedback_callback()
Expand Down
13 changes: 11 additions & 2 deletions libraries/AP_Camera/AP_Camera_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ class AP_Camera_Backend
// set camera lens as a value from 0 to 5
virtual bool set_lens(uint8_t lens) { return false; }

// get camera image horizontal or vertical field of view in degrees. returns 0 if unknown
float horizontal_fov() const { return MAX(0, _params.hfov); }
float vertical_fov() const { return MAX(0, _params.vfov); }

// handle MAVLink messages from the camera
virtual void handle_message(mavlink_channel_t chan, const mavlink_message_t &msg) {}

// configure camera
virtual void configure(float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time) {}
virtual void configure(float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time) {}

// handle camera control
virtual void control(float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id);
virtual void control(float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id);

// set camera trigger distance in meters
void set_trigger_distance(float distance_m) { _params.trigg_dist.set(distance_m); }
Expand All @@ -106,6 +110,11 @@ class AP_Camera_Backend
// send camera settings message to GCS
virtual void send_camera_settings(mavlink_channel_t chan) const;

#if AP_CAMERA_SEND_FOV_STATUS_ENABLED
// send camera field of view status
void send_camera_fov_status(mavlink_channel_t chan) const;
#endif

#if AP_CAMERA_SCRIPTING_ENABLED
// accessor to allow scripting backend to retrieve state
// returns true on success and cam_state is filled in
Expand Down
14 changes: 7 additions & 7 deletions libraries/AP_Camera/AP_Camera_MAVLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool AP_Camera_MAVLink::trigger_pic()
}

// configure camera
void AP_Camera_MAVLink::configure(float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time)
void AP_Camera_MAVLink::configure(float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time)
{
// convert to mavlink message and send to all components
mavlink_command_long_t mav_cmd_long = {};
Expand All @@ -30,19 +30,19 @@ void AP_Camera_MAVLink::configure(float shooting_mode, float shutter_speed, floa
mav_cmd_long.param2 = shutter_speed;
mav_cmd_long.param3 = aperture;
mav_cmd_long.param4 = ISO;
mav_cmd_long.param5 = exposure_type;
mav_cmd_long.param6 = cmd_id;
mav_cmd_long.param5 = float(exposure_type);
mav_cmd_long.param6 = float(cmd_id);
mav_cmd_long.param7 = engine_cutoff_time;

// send to all components
GCS_MAVLINK::send_to_components(MAVLINK_MSG_ID_COMMAND_LONG, (char*)&mav_cmd_long, sizeof(mav_cmd_long));
}

// handle camera control message
void AP_Camera_MAVLink::control(float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id)
void AP_Camera_MAVLink::control(float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id)
{
// take picture and ignore other arguments
if (is_equal(shooting_cmd, 1.0f)) {
if (shooting_cmd == 1) {
take_picture();
return;
}
Expand All @@ -54,8 +54,8 @@ void AP_Camera_MAVLink::control(float session, float zoom_pos, float zoom_step,
mav_cmd_long.param2 = zoom_pos;
mav_cmd_long.param3 = zoom_step;
mav_cmd_long.param4 = focus_lock;
mav_cmd_long.param5 = shooting_cmd;
mav_cmd_long.param6 = cmd_id;
mav_cmd_long.param5 = float(shooting_cmd);
mav_cmd_long.param6 = float(cmd_id);

// send to all components
GCS_MAVLINK::send_to_components(MAVLINK_MSG_ID_COMMAND_LONG, (char*)&mav_cmd_long, sizeof(mav_cmd_long));
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_Camera/AP_Camera_MAVLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class AP_Camera_MAVLink : public AP_Camera_Backend
bool trigger_pic() override;

// configure camera
void configure(float shooting_mode, float shutter_speed, float aperture, float ISO, float exposure_type, float cmd_id, float engine_cutoff_time) override;
void configure(float shooting_mode, float shutter_speed, float aperture, float ISO, int32_t exposure_type, int32_t cmd_id, float engine_cutoff_time) override;

// handle camera control message
void control(float session, float zoom_pos, float zoom_step, float focus_lock, float shooting_cmd, float cmd_id) override;
void control(float session, float zoom_pos, float zoom_step, float focus_lock, int32_t shooting_cmd, int32_t cmd_id) override;
};

#endif // AP_CAMERA_MAVLINK_ENABLED
16 changes: 16 additions & 0 deletions libraries/AP_Camera/AP_Camera_Params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ const AP_Param::GroupInfo AP_Camera_Params::var_info[] = {
// @User: Standard
AP_GROUPINFO("_MNT_INST", 11, AP_Camera_Params, mount_instance, 0),

// @Param: _HFOV
// @DisplayName: Camera horizontal field of view
// @Description: Camera horizontal field of view. 0 if unknown
// @Units: deg
// @Range: 0 360
// @User: Standard
AP_GROUPINFO("_HFOV", 12, AP_Camera_Params, hfov, 0),

// @Param: _VFOV
// @DisplayName: Camera vertical field of view
// @Description: Camera vertical field of view. 0 if unknown
// @Units: deg
// @Range: 0 180
// @User: Standard
AP_GROUPINFO("_VFOV", 13, AP_Camera_Params, vfov, 0),

AP_GROUPEND

};
Expand Down
Loading

0 comments on commit be6b7b9

Please sign in to comment.