Skip to content

Commit 34b8274

Browse files
committed
Fix upflow data msg bugs.
1 parent 8742e5c commit 34b8274

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

libraries/AP_Common/AP_UpFlow_TOF.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
static UPFLOW_TOF UPFLOW_TOF_DATA;
44

5-
UPFLOW_TOF* get_upflow_tof()
5+
/* UPFLOW_TOF* get_upflow_tof_ptr()
66
{
77
return &UPFLOW_TOF_DATA;
8-
}
8+
} */
9+
10+
UPFLOW_TOF get_upflow_tof()
11+
{
12+
return UPFLOW_TOF_DATA;
13+
}
14+
15+
void set_upflow_tof( UPFLOW_TOF data )
16+
{
17+
UPFLOW_TOF_DATA = data;
18+
}

libraries/AP_Common/AP_UpFlow_TOF.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ typedef struct{
88
bool if_opt_ok;
99
}UPFLOW_TOF;
1010

11-
UPFLOW_TOF* get_upflow_tof();
11+
//UPFLOW_TOF* get_upflow_tof_ptr();
12+
UPFLOW_TOF get_upflow_tof();
13+
void set_upflow_tof( UPFLOW_TOF data );

libraries/AP_OpticalFlow/AP_OpticalFlow_UPFLOW_LC30x.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
#define UPFLOW_TIMEOUT_SEC 0.3f
5353

5454
extern const AP_HAL::HAL& hal;
55-
static bool upflow_lc30x_message_sent = false;
55+
56+
/* static bool upflow_lc30x_message_sent = false;
5657
5758
// internal parameter configuration instructions
5859
static const uint8_t upflow_internal_para[4] = {0x96, 0x26, 0xbc, 0x50};
@@ -77,7 +78,7 @@ static const uint8_t upflow_sensor_cfg[]= {
7778
0xab, 0x16, 0xac, 0x3c, 0xad, 0xf0, 0xae, 0x57, 0xc6, 0xaa, 0xd2, 0x78, 0xd0, 0xb4, 0xd1, 0x00, 0xc8, 0x10, 0xc9, 0x12,
7879
0xd3, 0x09, 0xd4, 0x2a, 0xee, 0x4c, 0x7e, 0xfa, 0x74, 0xa7, 0x78, 0x4e, 0x60, 0xe7, 0x61, 0xc8, 0x6d, 0x70, 0x1e, 0x39,
7980
0x98, 0x1a
80-
};
81+
}; */
8182

8283

8384
// constructor
@@ -126,7 +127,7 @@ void AP_OpticalFlow_UPFLOW_LC30x::update(void)
126127
}
127128

128129
// init upflow,only once
129-
if (!upflow_lc30x_message_sent) {
130+
/* if (!upflow_lc30x_message_sent) {
130131
131132
uint8_t buf[30];
132133
uint16_t len = sizeof(upflow_sensor_cfg);
@@ -154,7 +155,7 @@ void AP_OpticalFlow_UPFLOW_LC30x::update(void)
154155
uart->write( buf, 1 );
155156
156157
upflow_lc30x_message_sent = true;
157-
}
158+
} */
158159

159160

160161
// record gyro values as long as they are being used

libraries/AP_OpticalFlow/AP_OpticalFlow_UPFLOW_Tx.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void AP_OpticalFlow_UPFLOW_Tx::update(void)
105105
return;
106106
}
107107

108-
static UPFLOW_TOF* UPFLOW_TOF_DATA = get_upflow_tof();
108+
static UPFLOW_TOF UPFLOW_TOF_DATA = get_upflow_tof();
109109

110110
// setup upflow link, only once
111111
if (!upflow_tx_message_sent) {
@@ -196,9 +196,9 @@ void AP_OpticalFlow_UPFLOW_Tx::update(void)
196196
_applyYaw(state.flowRate);
197197

198198
//update tof
199-
UPFLOW_TOF_DATA->if_opt_ok = true;
200-
UPFLOW_TOF_DATA->ground_distance = updata.ground_distance;
201-
UPFLOW_TOF_DATA->tof_valid = updata.tof_valid;
199+
UPFLOW_TOF_DATA.if_opt_ok = true;
200+
UPFLOW_TOF_DATA.ground_distance = updata.ground_distance;
201+
UPFLOW_TOF_DATA.tof_valid = updata.tof_valid;
202202

203203
//GCS_SEND_TEXT(MAV_SEVERITY_INFO, "UPFLOW_Tx: OK");
204204

@@ -208,11 +208,14 @@ void AP_OpticalFlow_UPFLOW_Tx::update(void)
208208
state.bodyRate.zero();
209209

210210
//update tof
211-
UPFLOW_TOF_DATA->if_opt_ok = false;
212-
UPFLOW_TOF_DATA->ground_distance = 0;
213-
UPFLOW_TOF_DATA->tof_valid = 0;
211+
UPFLOW_TOF_DATA.if_opt_ok = false;
212+
UPFLOW_TOF_DATA.ground_distance = 0;
213+
UPFLOW_TOF_DATA.tof_valid = 0;
214214
}
215215

216+
// update the rangefinder state
217+
set_upflow_tof(UPFLOW_TOF_DATA);
218+
216219
_update_frontend(state);
217220

218221
// reset gyro sum

libraries/AP_RangeFinder/AP_RangeFinder_UPFLOW_TOF.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ bool AP_RangeFinder_UPFLOW_TOF::detect()
4646
*/
4747
void AP_RangeFinder_UPFLOW_TOF::update(void)
4848
{
49-
static UPFLOW_TOF* tof_data = get_upflow_tof();
49+
static UPFLOW_TOF tof_data = get_upflow_tof();
5050
// check validity of the data
51-
if( tof_data->if_opt_ok == true && tof_data->tof_valid != 0 ){
52-
state.distance_m = tof_data->ground_distance * 0.001f;
53-
tof_data->if_opt_ok = false;
51+
if( tof_data.if_opt_ok == true && tof_data.tof_valid != 0 ){
52+
state.distance_m = tof_data.ground_distance * 0.001f;
53+
tof_data.if_opt_ok = false;
5454
e = 0;
5555
//GCS_SEND_TEXT(MAV_SEVERITY_INFO, "tof: OK");
5656
}else{
@@ -61,6 +61,9 @@ void AP_RangeFinder_UPFLOW_TOF::update(void)
6161
//GCS_SEND_TEXT(MAV_SEVERITY_INFO, "tof: err");
6262
}
6363
}
64+
65+
// update the rangefinder state
66+
set_upflow_tof(tof_data);
6467

6568
// update range_valid state based on distance measured
6669
update_status();

0 commit comments

Comments
 (0)