Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walksnail Serial gimbal and headtracker support #10109

Merged
merged 72 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
48d05dc
Initial draft for gimbal support.
mmosca Jun 2, 2024
1834a67
Make it optional
mmosca Jun 2, 2024
4faed24
Business logic ok, still needs plumbing
mmosca Jun 2, 2024
0e8486e
rename some fields, add some plumbing for gimbal_common
mmosca Jun 3, 2024
307e35a
Current status.
mmosca Jun 3, 2024
42a94cb
Few extra changes to cut down noise
mmosca Jun 4, 2024
4da6622
Plumbing in place
mmosca Jun 5, 2024
ae07fd7
Some files that were missed
mmosca Jun 5, 2024
5037401
Fix typo in settings and update docs
mmosca Jun 5, 2024
51cedc7
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 6, 2024
201172b
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 6, 2024
14370ce
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 6, 2024
93d19f7
Let f722 have some fun
mmosca Jun 6, 2024
1f9c285
More .gitignore
mmosca Jun 6, 2024
c6da0b7
Add unit tests
mmosca Jun 6, 2024
719a96e
Tested working. May need to clamp inputs to 1000-2000 range
mmosca Jun 6, 2024
4ba9a1b
Clean up
mmosca Jun 6, 2024
50754d0
ninja folder for tests
mmosca Jun 6, 2024
db0856b
Fix typos
mmosca Jun 6, 2024
5f6e734
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 7, 2024
53cb6bd
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 7, 2024
a136afe
Add modes to active modes.
mmosca Jun 8, 2024
1474e02
Add active modes
mmosca Jun 8, 2024
bcc9fd2
fix permanentBoxId
mmosca Jun 8, 2024
3e66d63
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 8, 2024
bf651ac
Update flight modes
mmosca Jun 8, 2024
0253e86
Only activate TILT lock and ROLL lock if CENTER is not active
mmosca Jun 8, 2024
ca494d1
Cleanup
mmosca Jun 8, 2024
0f2eeda
Use constrain instead of duplicating this code
mmosca Jun 8, 2024
504dd5b
First steps to allow reading headtracker info from a side channel
mmosca Jun 8, 2024
1be5b74
Fix warning about unused variable
mmosca Jun 8, 2024
9ad3f24
Parse incomming headtracking info from sidechannel
mmosca Jun 8, 2024
03f1a8b
Plumbing for head tracking in place.
mmosca Jun 8, 2024
99a3518
Fix unit test build
mmosca Jun 8, 2024
e30ab94
Add uart sharing.
mmosca Jun 9, 2024
327d173
fix headtracker center position
mmosca Jun 9, 2024
21ccfa5
Switch based changing from head tracker to center and sliders verifie…
mmosca Jun 9, 2024
5afef31
Small fixes
mmosca Jun 9, 2024
3b42180
Placeholders for head tracker as servo input
mmosca Jun 10, 2024
498ad3b
Basic plumbing on servos.
mmosca Jun 10, 2024
8f3f146
Make serial headtracker input available on the mixer tab
mmosca Jun 10, 2024
5865ab9
Build fixed for no gimbal or no headtracker
mmosca Jun 10, 2024
5efba06
Missing file
mmosca Jun 10, 2024
03698d6
New files
mmosca Jun 10, 2024
f09eef1
sitl fix
mmosca Jun 10, 2024
03829b7
fix detection
mmosca Jun 10, 2024
4257ff3
Add MSP headtracker
mmosca Jun 11, 2024
ab7f14c
Add init() call for msp head tracker
mmosca Jun 11, 2024
5b16cde
Add config reset functions
mmosca Jun 11, 2024
2d2eab8
Use reset template
mmosca Jun 11, 2024
6893844
group reset template
mmosca Jun 11, 2024
2366b0e
Add headtracker to SITL
mmosca Jun 11, 2024
cf14ed8
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 12, 2024
7486a38
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 12, 2024
b6ebb96
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 13, 2024
29a2d69
Add version header, in case we want to expand it in the future
mmosca Jun 14, 2024
0849408
Add headtracker axis ratios
mmosca Jun 17, 2024
2f268e9
build fixes
mmosca Jun 17, 2024
528e7b4
Fix sitl warnings
mmosca Jun 17, 2024
74c309f
fix reset function
mmosca Jun 17, 2024
337d609
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 17, 2024
d082abf
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 18, 2024
59bfddc
Merge remote-tracking branch 'origin/master' into mmosca-gimbal-test
mmosca Jun 18, 2024
0843ff7
Fix copy and paste error on settings.yaml
mmosca Jun 19, 2024
ac3834f
Cleanup
mmosca Jun 19, 2024
4e99f80
Increase max for heatracker ratio
mmosca Jun 19, 2024
0550aac
Change default headtracker type to NONE
mmosca Jun 20, 2024
005a818
Cleanup and simplification.
mmosca Jun 20, 2024
69123b1
Clean up
mmosca Jun 20, 2024
9a4a741
More cleanup. Most of the functionality is on headtracker_common.
mmosca Jun 20, 2024
188cc00
Build fixes for when different parts of heatracker / gimbal are disabled
mmosca Jun 20, 2024
677734d
Move scaling to headtracker_common
mmosca Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
*.o
.DS_Store
*~
*.swp
*.uvopt
*.dep
*.bak
*.uvgui.*
*.ubx
.project
.settings
.cproject
Expand All @@ -16,6 +18,8 @@ startup_stm32f10x_md_gcc.s
cov-int*
/build/
/build_SITL/
/[hs]itl/
/ninja/
/obj/
/patches/
/tools/
Expand Down
90 changes: 90 additions & 0 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,56 @@ Yaw Iterm is frozen when bank angle is above this threshold [degrees]. This solv

---

### gimbal_pan_channel

Gimbal pan rc channel index. 0 is no channel.

| Default | Min | Max |
| --- | --- | --- |
| 0 | 0 | 32 |

---

### gimbal_roll_channel

Gimbal roll rc channel index. 0 is no channel.

| Default | Min | Max |
| --- | --- | --- |
| 0 | 0 | 32 |

---

### gimbal_sensitivity

Gimbal sensitivity is similar to gain and will affect how quickly the gimbal will react.

| Default | Min | Max |
| --- | --- | --- |
| 0 | -16 | 15 |

---

### gimbal_serial_single_uart

Gimbal serial and headtracker device share same UART. FC RX goes to headtracker device, FC TX goes to gimbal.

| Default | Min | Max |
| --- | --- | --- |
| OFF | OFF | ON |

---

### gimbal_tilt_channel

Gimbal tilt rc channel index. 0 is no channel.

| Default | Min | Max |
| --- | --- | --- |
| 0 | 0 | 32 |

---

### gps_auto_baud

Automatic configuration of GPS baudrate(The specified baudrate in configured in ports will be used) when used with UBLOX GPS
Expand Down Expand Up @@ -1772,6 +1822,46 @@ This setting limits yaw rotation rate that HEADING_HOLD controller can request f

---

### headtracker_pan_ratio

Head pan movement vs camera movement ratio

| Default | Min | Max |
| --- | --- | --- |
| 1 | 0 | 5 |

---

### headtracker_roll_ratio

Head roll movement vs camera movement ratio

| Default | Min | Max |
| --- | --- | --- |
| 1 | 0 | 5 |

---

### headtracker_tilt_ratio

Head tilt movement vs camera movement ratio

| Default | Min | Max |
| --- | --- | --- |
| 1 | 0 | 5 |

---

### headtracker_type

Type of headtrackr dervice

| Default | Min | Max |
| --- | --- | --- |
| NONE | | |

---

### hott_alarm_sound_interval

Battery alarm delay in seconds for Hott telemetry
Expand Down
8 changes: 8 additions & 0 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ main_sources(COMMON_SRC
drivers/flash_m25p16.h
drivers/flash_w25n01g.c
drivers/flash_w25n01g.h
drivers/gimbal_common.h
drivers/gimbal_common.c
drivers/headtracker_common.h
drivers/headtracker_common.c
drivers/io.c
drivers/io.h
drivers/io_pcf8574.c
Expand Down Expand Up @@ -356,6 +360,10 @@ main_sources(COMMON_SRC
io/servo_sbus.h
io/frsky_osd.c
io/frsky_osd.h
io/gimbal_serial.c
io/gimbal_serial.h
io/headtracker_msp.c
io/headtracker_msp.h
io/osd_dji_hd.c
io/osd_dji_hd.h
io/lights.c
Expand Down
9 changes: 9 additions & 0 deletions src/main/build/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <stdint.h>
#include <stdbool.h>

#include "platform.h"

#define DEBUG32_VALUE_COUNT 8
extern int32_t debug[DEBUG32_VALUE_COUNT];
extern uint8_t debugMode;
Expand Down Expand Up @@ -73,5 +75,12 @@ typedef enum {
DEBUG_LANDING,
DEBUG_POS_EST,
DEBUG_ADAPTIVE_FILTER,
DEBUG_HEADTRACKING,
DEBUG_COUNT
} debugType_e;

#ifdef SITL_BUILD
#define SD(X) (X)
#else
#define SD(X)
#endif
5 changes: 4 additions & 1 deletion src/main/config/parameter_group_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@
#define PG_FW_AUTOLAND_CONFIG 1036
#define PG_FW_AUTOLAND_APPROACH_CONFIG 1037
#define PG_OSD_CUSTOM_ELEMENTS_CONFIG 1038
#define PG_INAV_END PG_OSD_CUSTOM_ELEMENTS_CONFIG
#define PG_GIMBAL_CONFIG 1039
#define PG_GIMBAL_SERIAL_CONFIG 1040
#define PG_HEADTRACKER_CONFIG 1041
#define PG_INAV_END PG_HEADTRACKER_CONFIG

// OSD configuration (subject to change)
//#define PG_OSD_FONT_CONFIG 2047
Expand Down
117 changes: 117 additions & 0 deletions src/main/drivers/gimbal_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* This file is part of INAV.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with INAV. If not, see <http://www.gnu.org/licenses/>.
*/

#include "platform.h"

#ifdef USE_SERIAL_GIMBAL

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#include <build/debug.h>
#include <config/parameter_group_ids.h>

#include "common/time.h"

#include "fc/cli.h"

#include "drivers/gimbal_common.h"


PG_REGISTER(gimbalConfig_t, gimbalConfig, PG_GIMBAL_CONFIG, 0);


static gimbalDevice_t *commonGimbalDevice = NULL;

void gimbalCommonInit(void)
{
}

void gimbalCommonSetDevice(gimbalDevice_t *gimbalDevice)
{
SD(fprintf(stderr, "[GIMBAL]: device added %p\n", gimbalDevice));
commonGimbalDevice = gimbalDevice;
}

gimbalDevice_t *gimbalCommonDevice(void)
{
return commonGimbalDevice;
}

void gimbalCommonProcess(gimbalDevice_t *gimbalDevice, timeUs_t currentTimeUs)
{
if (gimbalDevice && gimbalDevice->vTable->process && gimbalCommonIsReady(gimbalDevice)) {
gimbalDevice->vTable->process(gimbalDevice, currentTimeUs);
}
}

gimbalDevType_e gimbalCommonGetDeviceType(gimbalDevice_t *gimbalDevice)
{
if (!gimbalDevice || !gimbalDevice->vTable->getDeviceType) {
return GIMBAL_DEV_UNKNOWN;
}

return gimbalDevice->vTable->getDeviceType(gimbalDevice);
}

bool gimbalCommonIsReady(gimbalDevice_t *gimbalDevice)
{
if (gimbalDevice && gimbalDevice->vTable->isReady) {
return gimbalDevice->vTable->isReady(gimbalDevice);
}
return false;
}

#ifdef GIMBAL_UNIT_TEST
void taskUpdateGimbal(timeUs_t currentTimeUs)
{
}
#else
void taskUpdateGimbal(timeUs_t currentTimeUs)
{
if (cliMode) {
return;
}

gimbalDevice_t *gimbalDevice = gimbalCommonDevice();

if(gimbalDevice) {
gimbalCommonProcess(gimbalDevice, currentTimeUs);
}
}
#endif

// TODO: check if any gimbal types are enabled
bool gimbalCommonIsEnabled(void)
{
return true;
}


bool gimbalCommonHtrkIsEnabled(void)
{
const gimbalDevice_t *dev = gimbalCommonDevice();
if(dev && dev->vTable->hasHeadTracker) {
bool ret = dev->vTable->hasHeadTracker(dev);
return ret;
}

return false;
}

#endif
97 changes: 97 additions & 0 deletions src/main/drivers/gimbal_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* This file is part of INAV.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with INAV. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "platform.h"

#ifdef USE_SERIAL_GIMBAL

#include <stdint.h>

#include "config/feature.h"
#include "common/time.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
GIMBAL_DEV_UNSUPPORTED = 0,
GIMBAL_DEV_SERIAL,
GIMBAL_DEV_UNKNOWN=0xFF
} gimbalDevType_e;


struct gimbalVTable_s;

typedef struct gimbalDevice_s {
const struct gimbalVTable_s *vTable;
} gimbalDevice_t;

// {set,get}BandAndChannel: band and channel are 1 origin
// {set,get}PowerByIndex: 0 = Power OFF, 1 = device dependent
// {set,get}PitMode: 0 = OFF, 1 = ON

typedef struct gimbalVTable_s {
void (*process)(gimbalDevice_t *gimbalDevice, timeUs_t currentTimeUs);
gimbalDevType_e (*getDeviceType)(const gimbalDevice_t *gimbalDevice);
bool (*isReady)(const gimbalDevice_t *gimbalDevice);
bool (*hasHeadTracker)(const gimbalDevice_t *gimbalDevice);
} gimbalVTable_t;


typedef struct gimbalConfig_s {
uint8_t panChannel;
uint8_t tiltChannel;
uint8_t rollChannel;
uint8_t sensitivity;
} gimbalConfig_t;

PG_DECLARE(gimbalConfig_t, gimbalConfig);

typedef enum {
GIMBAL_MODE_FOLLOW = 0,
GIMBAL_MODE_TILT_LOCK = (1<<0),
GIMBAL_MODE_ROLL_LOCK = (1<<1),
GIMBAL_MODE_PAN_LOCK = (1<<2),
} gimbal_htk_mode_e;

#define GIMBAL_MODE_DEFAULT GIMBAL_MODE_FOLLOW
#define GIMBAL_MODE_TILT_ROLL_LOCK (GIMBAL_MODE_TILT_LOCK | GIMBAL_MODE_ROLL_LOCK)
#define GIMBAL_MODE_PAN_TILT_ROLL_LOCK (GIMBAL_MODE_TILT_LOCK | GIMBAL_MODE_ROLL_LOCK | GIMBAL_MODE_PAN_LOCK)

void gimbalCommonInit(void);
void gimbalCommonSetDevice(gimbalDevice_t *gimbalDevice);
gimbalDevice_t *gimbalCommonDevice(void);

// VTable functions
void gimbalCommonProcess(gimbalDevice_t *gimbalDevice, timeUs_t currentTimeUs);
gimbalDevType_e gimbalCommonGetDeviceType(gimbalDevice_t *gimbalDevice);
bool gimbalCommonIsReady(gimbalDevice_t *gimbalDevice);


void taskUpdateGimbal(timeUs_t currentTimeUs);

bool gimbalCommonIsEnabled(void);
bool gimbalCommonHtrkIsEnabled(void);

#ifdef __cplusplus
}
#endif

#endif
Loading
Loading