Flies adaptively control flight to compensate for added inertia

Animal locomotion is highly adaptive, displaying a large degree of flexibility, yet how this flexibility arises from the integration of mechanics and neural control remains elusive. For instance, animals require flexible strategies to maintain performance as changes in mass or inertia impact stability. Compensatory strategies to mechanical loading are especially critical for animals that rely on flight for survival. To shed light on the capacity and flexibility of flight neuromechanics to mechanical loading, we pushed the performance of fruit flies (Drosophila) near its limit and implemented a control theoretic framework. Flies with added inertia were placed inside a virtual reality arena which permitted free rotation about the vertical (yaw) axis. Adding inertia increased the fly's response time yet had little influence on overall gaze stabilization performance. Flies maintained stability following the addition of inertia by adaptively modulating both visuomotor gain and damping. By contrast, mathematical modelling predicted a significant decrease in gaze stabilization performance. Adding inertia altered saccades, however, flies compensated for the added inertia by increasing saccade torque. Taken together, in response to added inertia flies increase reaction time but maintain flight performance through adaptive neural control. Overall, adding inertia decreases closed-loop flight robustness. Our work highlights the flexibility and capacity of motor control in flight.


Introduction
Organisms display a wide array of compensatory strategies to maintain function and performance.Compensatory strategies to mechanical loading are particularly important for flying animals that rely on stable flight for finding food, mating, escaping predators, etc.In flying insects, the most drastic weight fluctuations can arise from feeding [1] and carrying loads [2], and can triple overall weight in some cases [3].Previous studies have investigated the robustness of flying insects to small changes in weight or inertia, e.g.[4], but the underlying neuromechanical control strategies used to maintain performance are not well understood.Pushing flying insects beyond minor changes in weight, in conjunction with a control theoretic framework, could unravel modes and control strategies that are obscured under natural conditions [5].This approach in turn could provide unique insights into the capacity of the nervous system outside the natural context and the role that different sensory modalities play in flight compensation.Indeed, pushing insects beyond their natural context has been fruitful to study the neuromechanics of locomotion on land and in air [6][7][8][9].
Here, we apply tools from linear control theory to quantify the influence of added inertia on visual scene stabilization in flight.During visual scene stabilization flies operate about a putative equilibrium point, i.e. zero retinal image velocity.For tasks operating local to an equilibrium point, nonlinear systems such as insect sensorimotor control can be linearized and unravel general principles of sensorimotor control [10,11].Quantifying where behaviour departs from linear time invariance (LTI) assumptions can elucidate underlying timedependent, nonlinear phenomena such as adaptive neural control.Here, we apply linear control theory to generate specific hypotheses about the influence of added inertia on flight control and use system identification to experimentally test these hypotheses.
We applied such a framework to examine the impact of added yaw inertia on the flight performance of tethered fruit flies free to rotate about the yaw axis.To quantify compensatory strategies, we perturbed the gaze stabilization response of flies by placing flies inside a yaw-free virtual reality flight simulator.Our paradigm allowed flies to close the loop between visual stimulus and their gaze by rotating about the yaw axis.The yaw inertia of flies was altered by mounting three-dimensional printed cylinders with distinct inertia onto a magnetic pin.This paradigm pushed the performance of flies beyond natural conditions as lift generation and yaw stabilization were decoupled, thus providing insights into the capacity of the nervous system to adapt yaw steering.By increasing the yaw inertia of flies by up to 64 times (64×), we found that altering inertia had a notable impact on both the performance and timing of the yaw gaze stabilization response.Using a control theoretic framework, we demonstrated that adding inertia did not significantly alter the yaw response of flies but intriguingly resulted in a larger response time or time delay.Flies maintained similar performance across a range of added inertia by increasing both damping and visuomotor gain, likely through the integration of visual and mechanosensory feedback.

(a) Increasing yaw inertia leads to oscillatory body motion
Flies were tethered to a magnetic pin and placed inside a virtual reality arena.This configuration restricted the motion of flies to rotation about the yaw axis.The yaw inertia of flies was altered by mounting three-dimensional printed cylinders of distinct sizes onto a magnetic pin (figure 1a-c and Methods).We designed eight cylinders with logarithmically increasing yaw inertia to push the performance of flies (see Methods).The smallest cylinder was approximately the same yaw inertia as Drosophila (5.2 × 10 −13 kg m 2 ; 1×), whereas the yaw inertia of the largest cylinder was approximately 64×.To measure the impact of altering inertia on flight performance and stability, we investigated how increasing inertia altered yaw stability in the presence of a static visual panorama.Failure to maintain a stable heading following changes in inertia could indicate a decrease in flight stability.Increasing the yaw inertia by 16× or more caused flies to oscillate about the yaw axis (figure 1d and electronic supplementary material, movie S1).With increasing inertia, the magnitude and frequency of these oscillations increased and decreased, respectively (figure 1e).By contrast, flies with no added inertia did not exhibit such large oscillations (figure 1d,e).The presence of oscillations suggests that stability is impaired by adding inertia.

(b) Flies maintained similar gaze performance at the expense of increased response time
To quantify the impact of increasing inertia on gaze stabilization performance, we presented flies with a sum-of-sines visual stimulus composed of nine sine waves with distinct frequencies and phase (see Methods and electronic supplementary material, movie S2).The stimulus elicited an optomotor response in all the tested groups with and without added inertia (figure 1f and electronic supplementary material, figure S1a).Interestingly, even flies with added inertia up to 64× stabilized the moving background.However, a closer inspection of the time domain data revealed a change in performance when the fly's inertia was increased by 16× or more, consistent with our findings for flies presented a static visual stimulus (figure 1f and electronic supplementary material, figure S1).When the inertia of flies was increased by more than 8×, the average response appeared smoother due to the attenuation of the higher frequency components, suggesting that adding inertia primarily influences highfrequency gaze stabilization performance.At the highest tested inertia (64×), the optomotor response was significantly attenuated and no longer coherent with the visual stimulus at most frequencies (electronic supplementary material, figure S1b).Therefore, we excluded data collected at this inertia from further analysis.
To further examine the impact of added inertia on flight performance, we conducted a frequency domain analysis of the flight responses.By computing gain and phase difference, we mathematically quantified the changes in performance at each frequency component of the stimulus.First, we predicted how the performance of flies might be modified without changes in controller parameters (neural control).We modelled the yaw body dynamics of the fly as a first-order system (figure 1c) of the form where I t is the total yaw inertia (fly inertia + cylinder inertia), C is the yaw damping, v is the yaw angular velocity, and t is the yaw torque produced by the fly [12].By assuming that the visual system acts primarily as a proportional gain on velocity-consistent with previous studies that showed little contribution of integral feedback during rapid, yaw gaze stabilization manoeuvres [5,13]-the open-loop transfer function VðsÞ=EðsÞ ¼ GðsÞ can be written as where s is the complex frequency, E(s) is the Laplace transform of the error (velocity) between the stimulus and fly motion, K p is the visuomotor gain and t d is time delay due to neural processing.Increasing the inertia in equation (2.1) alters the pole location (roots of the denominator) and consequently the open-loop stability of the system.Therefore, increasing yaw inertia without changing damping would push the openloop pole towards the imaginary axis.When considering the closed-loop system-which is expressed as and considering a constant proportional gain, increasing inertia increases the system's time constant (ratio of inertia to damping), and thus a large added inertia could push the system close to a marginally stable or unstable state.For this closed-loop first-order system, there is only one pole.Its sign determines the stability of the system: a negative pole in the left half-plane implies stability [14].
By simulating an increase in inertia (without changing other parameters) and using experimentally determined constants for t d , K p and C (equation (2.2)), we predicted the closed-loop frequency response of flies with added inertia.Importantly, baseline parameters were estimated from flies with no added inertia (see Methods).We predicted that the gain would significantly drop at all frequencies if the inertia was altered without changing the baseline damping and visuomotor gain (figure 2a).We further predicted that the phase difference would decrease significantly at the lower frequencies but converge to the same value at higher frequencies (figure 2a).The experimentally measured frequency domain response did not resemble our prediction (figure 2b).The gain was almost unchanged for all inertias up until 0.9 Hz, and the phase difference decreased far beyond our predicted limit (figure 2b top panel, electronic supplementary material, table S1 and figure S2).Because mechanics alone could not account for the experimental data, our results strongly imply that flies tune internal gains to compensate for added inertia.At frequencies higher than 0.9 Hz, the difference in gain among the inertia altered flies became statistically significant (electronic supplementary material, table S1) but did not follow a specific pattern.In fact, flies that had their inertia increased by 16 and 32 times had the largest gains at 1.45 Hz and 2.25 Hz.However, the increase in inertia began to reduce the gain at frequencies above 3.45 Hz.At frequencies higher than 3.45 Hz, the gain was significantly smaller at all added inertias compared to the intact case (electronic supplementary material, table S1).Interestingly, the response when the yaw inertia was increased by 32× resembled the response of a second-order underdamped system rather than that of a firstorder system.The gain peaked at 2.25 Hz and was greater than unity.However, the frequency at which the peak occurred coincided with the frequency of observed oscillations with a static stimulus (figures 1e and 2b).This peak complicated the interpretation of the gain data at this inertia as it could be a result of superimposed noise or due to higher-order dynamics.
Looking at the phase data can shed light on the underlying cause behind this rise in gain.Increasing inertia altered the phase difference in a completely different manner than predicted by simulation (figure 2a,b).The variation in phase difference became more significant at larger inertias for stimulus frequencies at and above 1.45 Hz (figure 2b lower panel; electronic supplementary material, table S2).Such changes in phase cannot be explained purely by altering the damping or inertia in our model (equation (2.2)).In the absence of a time delay, the phase difference of first-order systems converges to −90°at high frequencies.Hence, the observed changes in phase difference are likely a result of an increase in the time delay ðt d Þ or unmodelled higher-order dynamics.Simulating equation (2.2) with no added inertia and delays estimated from the empirical phase difference (see Methods) captured the changes in both the gain and phase difference (figure 2c).Altering the time delay even captured the peak observed at 32×.The interpretation of this result is not intuitive as time delays are usually associated with changes in phase difference but not gain.However, altering the delay in the open-loop system influenced both the gain and phase of the closed-loop system.Changes in the time delay of the intact system could royalsocietypublishing.org/journal/rspb Proc.R. Soc.B 290: 20231115 capture our empirical results; however, this simulation did not account for changes in inertia and did not consider how the remaining internal parameters are modulated to maintain the same gain.Altogether, our findings demonstrate that flies can compensate for an increase in inertia, with the trade-off of increased time delay.

(c) The head compensates for loss of stability but not for changes in gaze performance
Increasing the yaw inertia of flies caused a modest change in flight performance and stability whereas flies presented with a static stimulus began to oscillate about the yaw axis and failed to maintain stable body heading.Collectively, these results indicate that the body response of flies deteriorated with the addition of inertia.However, this may not be the case for the overall gaze as head motion could be used to compensate for changes in body motion [15].Previous work explored the overall role of the head in gaze stabilization [15].The head compensates for fast visual motion, whereas the body compensates for slower visual motion.By combining head and body motion, flies can improve overall gaze stabilization performance over a large range of visual motion velocities [13].When presented with a sum-of-sines stimulus, the head did not appear to play a large compensatory role (electronic supplementary material, figure S5a).The gain and phase difference of the head were similar across all groups of flies.While the phase difference at the highest three frequencies fluctuated among different inertia treatments, it did not follow a clear trend.This is likely because body motion influences the visual input to the head controller, and body motion varies greatly at high frequencies for added inertia (figure 2b).Thus, changes in visual feedback likely led to these changes in head phase.Of interest was the peak in gain observed at approximately 2.3 Hz (electronic supplementary material, figure S5a), which coincided with the peak observed in body gain at the same frequency (figure 2b).
Changes in head gain at this frequency are likely an attempt to compensate for elevated oscillatory body motion.Flies presented with a static stimulus increased head motion to compensate for body oscillations (electronic supplementary material, figure S5b).However, the change in head motion was not sufficient to completely cancel body motion (electronic supplementary material, figure S5b).Interestingly, the time difference between the head and body increased with larger inertia (electronic supplementary material, figure S5c) ( p < 0.001, ANOVA; d.f.= 3).

(d) Flies increased visuomotor gain and damping to maintain the same open-loop dynamics
We demonstrated that increasing inertia notably altered the performance of the optomotor response especially at higher frequencies (figure 2b).From a control perspective, increasing the inertia of a first-order system with a proportional controller shifts the pole of this system closer to the imaginary axis, and causes a significant drop in the gain and phase difference (figure 2a).A closed-loop system could possibly compensate for changes in stability by altering its controller through an adaptive control scheme.However, if the goal is to maintain the same performance and stability, a change in proportional control alone cannot produce the desired change in the system's dynamics.
To shed light on how increasing yaw inertia altered the yaw dynamics of flies, we fit the empirical frequency The empirical frequency response function of flies with added inertia in response to a sum-of-sines stimulus.Addition of inertia had a significant influence on the phase difference and gain for frequencies greater than approximately 0.9 Hz (see electronic supplementary material, table S1 for exact values and statistics).royalsocietypublishing.org/journal/rspb Proc.R. Soc.B 290: 20231115 response functions (FRFs) (figure 2b) to a first-order transfer function with a delay, one pole and no zeros [13].Specifically, we used a least-square estimate to fit the open-loop transfer function G(s) of flies with and without added inertia (electronic supplementary material, figure S3a), where the open-loop transfer function is of the form shown in equation (2.2).There was some individual variation between animals when fitting, and this variation became more prominent at the higher inertias.However, a first-order model captured the open-loop dynamics of the optomotor response of all groups (r 2 ∼ 88%, see electronic supplementary material, figure S3b).To verify that our fit model properly captured the time domain response, we simulated the fit transfer functions using the same sum-of-sines visual stimulus as the input.The simulated response closely resembled the actual response of flies, but with lower fidelity for higher inertia (electronic supplementary material, figure S4).
Estimating the open-loop parameters can shed light on the underlying neuromechanical control strategies used by flies to compensate for changes in inertia.The numerator is the visuomotor gain which could be modulated by the fly.On the other hand, the denominator is used to determine the location of the open-loop pole and thereby measure the stability of the open-loop system.Finally, the delay term can provide an estimate of the system's phase lag due to sensorimotor processing.Comparing the various fits, we determined that changes in the system time delay were positively correlated to changes in inertia (figure 3a).With no added inertia, the time delay was approximately 0.02 s, which is consistent with previous studies [13].However, this delay steadily increased with increasing inertia, up to approximately 0.08 s (figure 3a).
Concomitantly, the visuomotor gain and damping significantly changed with increasing inertia (figure 3b,c).The mean visuomotor gain increased by two orders of magnitude from no added inertia to 32× (figure 3b).Similarly, the damping increased by more than one order of magnitude (figure 3c).The location of the open-loop pole changed modestly when the inertia of flies was increased by 32× (figure 3d, electronic supplementary material, figure S3c).While adding inertia did alter open-loop pole locations ( p = 0.04, ANOVA, 6 d.f.), the statistical analysis yielded a p-value that is marginally significant.Consequently, this statistical significance may be a result of the fluctuations in pole locations at different inertias.Flies drastically modulated their visuomotor gain and yaw damping in response to changes in inertia; however, it is where K ol is defined as the open-loop visuomotor gain and t f is the system time constant.Estimating the open-loop gain and time constant showed that these two parameters only marginally changed (figure 3e,f ).While subject to fluctuations with added inertia, the open-loop gain and the time constant remained approximately the same regardless of how much inertia was added ( p = 0.5 and 0.9, respectively; ANOVA, d.f.= 6).Thus, flies increased their damping and visuomotor gain to maintain approximately the same openloop dynamics.Compared to our predictions (figure 2a), flies only experienced a marginal drop in performance following the addition of inertia.This suggests that flies modulate both parameters to maintain the same open-loop dynamics.By estimating the yaw damping coefficient, we found that flies significantly increased this term to maintain the same open-loop pole location, and hence, the same body dynamics.Considering the movement of the headwhich plays a critical role in shaping visual inputs [13,15,16]-did not change these conclusions (electronic supplementary material, figure S5).Therefore, flies maintained roughly the same body dynamics at the expense of a delayed response to the visual stimulus.

(e) Adding inertia decreases closed-loop flight robustness
While adding inertia had little influence on modelled openloop flight dynamics, it is important to consider how the modelled response time ( phase lag due to time delay) influences closed-loop stability.Indeed, an increase in phase lag can lead to catastrophic instability in a closed-loop system [14,17].To quantify the 'safety margin' for stability, we computed the phase and gain margins of the FRFs for each inertia treatment.The gain margin is the amount of gain needed to make the system unstable, whereas the phase margin is the amount of phase lag needed to make the system unstable (figure 4a).While a system is stable if the gain and phase margins are both positive, smaller gain and phase margins imply a less robust system that is more prone to instabilities.Our analysis revealed that both gain and phase margins decreased with increasing inertia (figure 4b,d), suggesting that an increased response time makes the system less robust.Concomitantly, phase and gain crossover frequency decreased with increasing inertia, suggesting that inertia decreases the available bandwidth for stable flight (figure 4c, e).To characterize the closed-loop stability of flies to added inertia, we generated a Nyquist plot of the modelled openloop system for each inertia treatment.For a Nyquist plot of our first-order system, the closer the curve is to encircling −1, the closer to instability and the less robust the closed-loop system.Higher inertia resulted in decreased closed-loop robustness (figure 4f ).Taken together, these results suggest that adding inertia decreases closed-loop flight robustness due to an increase in phase lag.
(f ) Changes in yaw damping cannot be explained by passive aerodynamics and require active feedback Using system identification techniques, we found that flies regulated yaw damping to maintain the same open-loop body dynamics following changes in inertia.Damping could be actively modulated through neural control using an inner mechanosensory feedback loop (figure 5a) [17,18].Alternatively, changes in damping can be passively regulated as a by-product of changes in wing kinematics to meet the larger torque requirements imposed by adding inertia.Flapping flight exhibits passive damping about the yaw axis which is generated as a by-product of drag on wings during flapping.Hence, when flying animals with flapping wings rotate about yaw, a torque is passively produced in the opposite direction of motion.This torque is dubbed flapping countertorque (FCT) and damps out turns [19], and can be estimated To determine if the change in yaw damping was actively modulated or a by-product of the increase in FCT due to changes in wing kinematics, we estimated the threedimensional wing kinematics of magnetically tethered flies with distinct added inertia (see electronic supplementary material).We found that the FCT does not notably change following the addition of inertia if wingbeat frequency and rotation angle were to remain the same (figure 5b,c).This result may be skewed as flies can regulate wingbeat frequency and the rotation angle, hence modulating these two parameters can significantly influence the FCT.To tease out their relative contribution to the changes in passive yaw damping, we simulated the FCT model and found that flies would need to flap at around 800 Hz to achieve the damping estimated in the FRFs regardless of changes in rotation angle (figure 5d).This value is far beyond the physical limit of Drosophila.Therefore, an increase in FCT is not enough to explain the increase in the yaw damping and requires active control.
Flies combine sensory information from multiple modalities to control and regulate flight [20].Therefore, the damping coefficient of the body is likely regulated through an inner sensory feedback loop other than vision (figure 5a).By integrating an inner loop within the open-loop transfer function G(s), equation (2.2) can be written as where C fct is the passive yaw damping due to FCT and K h is the inner loop feedback gain that modulates damping (here we omit the delay term e Àt d s for clarity).The visuomotor gain, K p , can be factored out of equation (2.4) to obtain the formulation of the second inner loop: Since the halteres play an important role in encoding angular velocity about the yaw axis and act faster than vision [21], the inner feedback loop is likely driven using mechanosensory feedback from the halteres.Therefore, by modulating K h flies could actively increase damping about the yaw axis to maintain flight performance.Changes in the haltere feedback can be estimated by subtracting the FCT from the active yaw damping: However, this results in negative values of K h at 1× inertia which implies that haltere feedback transitions from positive to negative feedback as inertia is increased.To facilitate comparison across all inertia, we shifted our data so that the lowest estimated value of haltere gain was zero.Using this posited control architecture, we estimated that the haltere gain increased with increased inertia to maintain the same yaw damping (figure 5e).On the other hand, the open-loop visuomotor gain K p is regulated using visuomotor feedback and maintains the same open-loop performance which would have significantly deteriorated due to elevated inertia and damping.To summarize, our simulation suggests that flies rely on feedback from multiple sensory modalities to maintain flight performance in response to changes in inertia.

(g) Flies compensate for added inertia in the control of saccades
Saccades are ballistic movements in which flies change their heading in the span of 50-100 ms [22].Such manoeuvres have been observed in free and tethered flight [23][24][25].In the magnetic tether, these saccades can be externally triggered from visual cues or internally triggered (spontaneous saccades) [26,27].By presenting inertia altered flies with a static stimulus, we measured the impact of inertia on the dynamics of spontaneous saccades.Our simulation (see Methods) predicted that without active control of yaw torque, the displacement, peak velocity and duration of saccades should greatly diminish following any increase in inertia (figure 6a bottom panel).Compared to unaltered flies, flies with added inertia exhibited a clear change in saccade dynamics that did not match our prediction (figure 6a top panel, electronic supplementary material, figure S6).This was also accompanied by an increase in peak yaw torque during a saccade (figure 6b).Flies with added inertia exhibited an increase in saccade displacement compared to unaltered flies.This difference became more prominent as the inertia increased (figure 6c).By contrast, the peak velocity of saccades marginally decreased with increasing inertias (figure 6d).However, saccade durations exhibited the most change with increasing inertia (figure 6e).At no added inertia, the mean saccade duration was just below 0.1 s.This value steadily increased with added inertia, and approached 0.4 s when the inertia of flies was increased 64 times.Complicating this analysis is the large number of samples collected for each inertia treatment, thus tiny differences in saccade dynamics could potentially result in a small p-value using conventional statistical methods.To address this limitation, we computed Hedge's g, which is a metric that is independent of sample size (see Methods).Using this effect size model, we found that adding inertia had the largest overall impact on saccade duration and resulted in the largest values of Hedge's g (electronic supplementary material, table S4).As expected, such changes in saccade dynamics required overall higher torques exerted over a longer duration (figure 6b).
Together, these results suggest that flies adaptively control saccade dynamics to compensate for added inertia.Adding inertia led to a slight increase in saccade displacement, a slight decrease in peak velocity and a notable increase in saccade duration (electronic supplementary material, table S4).For (a,b), grey vertical line: peak velocity.For all panels: no added inertia: n = 301 saccades from 13 flies; 8×: n = 148 saccades from nine flies; 16×: n = 139 saccades from seven flies; 32×: n = 89 saccades from nine flies; 64×: n = 118 saccades from 13 flies.For saccade variation data see electronic supplementary material, figure S6.

Discussion
We discovered that flies adaptively control flight following a large increase in yaw inertia.Specifically, by modulating visuomotor gain and damping, flies compensated for changes in inertia with only minor changes in performance at the cost of overall stability associated with a larger response time (phase lag).Such compensatory changes could not be explained by feedback alone (figure 2a), nor could they be achieved using feedback from one sensory modality (figures 4 and 5).Flies adjusted the initial torque to generate compensatory saccades to added inertia, suggesting that they modulate internal control commands and sense the extra mechanical load via mechanosensory feedback.Our results support a control scheme which is composed of two feedback loops: a nested loop is driven by mechanosensory feedback that regulates yaw damping and an outer loop that regulates visuomotor gain (figure 5).
(a) Flies compensate for added inertia by trading off response time Flies with added inertia suffered only a marginal drop in gain, but a significant drop in phase during gaze stabilization.
When the yaw inertia of flies was increased by 32×, flies began to exhibit a peak in closed-loop (behavioural) gain which is characteristic of underdamped second-order systems, indicating that performance had begun to suffer as the gain was larger than unity around this peak (figure 2b).The dip in phase became more prominent at higher inertia and was a direct result of changes in the system time delay.At present, the mechanism driving this change in time delay remains obscure.Changes in time delay could be a manifestation of higher-order dynamics that cannot be modelled using the current framework (e.g. through pole-zero cancellation).Studies of hawkmoths in environments with different levels of luminance found that lower levels of light resulted in larger time delays, which can be modelled by a change in the low-pass filter time constant of visual processing [28].This study hints that the observed changes in delay in flies may be due to neural control.Alternatively, the increase in time delay could be a result of an increase in reaction time, that is a consequence of the fly compensating for an extreme perturbation.Indeed, larger time delays can negatively impact system yaw stability in insect flight [17].
Our paradigm allowed us to push the performance of flies beyond natural conditions as lift generation and yaw stabilization were decoupled, which here we used to reveal the capacity of the nervous system to adapt yaw steering.Indeed, in free flight, flies with 1× or 2× added inertia may be more naturalistic.Nevertheless, the ability of flies with large added inertia to stabilize gaze in the magnetic tether is a strong indication of the capacity for adaptive compensatory behaviour.This capacity of the nervous system could allow flies to rapidly adapt to more natural situations that compromise their ability to control steering, for instance following asymmetrical wing damage [5,29] or when flying in windy conditions [18].Indeed, it has been argued that flies' motor flexibility-e.g.their ability to generate large changes in wing motion-could have evolved to compensate for large internal perturbations such as wing damage [30].Thus, our results, along with previous studies, point to considerable flexibility and robustness in fly flight control.Our results should be interpreted with appropriate caution as the tethering paradigm restricts the motion of flies to rotation about the yaw axis.This is unnatural for flies, although they can perform nearly pure yaw rotation in free flight [31].Further, the tether supports the weight of the fly and cylinder which eliminates the need for lift generation.As a result, the wing kinematics of magnetically tethered flies likely deviate from those in free flight.

(b) Flies adaptively control saccade dynamics
By modelling the yaw dynamics of tethered flies with added inertia, we could predict how saccade dynamics should change in the absence of sensory feedback and yaw torque modulation (figure 6a).Differences between the model and data suggest a mechanism that modulates saccade dynamics due to mechanical loading (figure 6).Previous work found that altering haltere feedback had a significant impact on saccade dynamics [32].Therefore, one possibility is that changes in saccade dynamics are a result of changes in haltere gyroscopic feedback due to alterations in body inertia.This hypothesis presumes that the fly has some internal model or, alternatively, a goal at the start of the saccade and relies on mechanosensory feedback to achieve this goal.This hypothesis also suggests that flies employ mechanosensory feedback not only when 'braking' during a saccade, but also to modulate saccade initiation.Alternatively, flies may have updated an internal model which accounted for the added inertia.By comparing the saccade torque profile of flies with added inertia to unaltered flies, we found a clear increase in torque production with increasing inertia (figure 6b).While larger in magnitude, the torque profile flies with added inertia resembled that of intact flies, which suggests that changes in saccade dynamics may be a result of mechanosensory feedback instead of an internal model update.Further supporting this conclusion is the elevation in saccade duration with increasing inertia.

(c) Flies maintain stability by combining sensory feedback with adaptive control
Based on our findings, we propose an adaptive control strategy which allows flies to regulate damping and visuomotor gain using multiple feedback loops.As flies integrate visual and mechanosensory feedback to stabilize flight [20], we posit that flies regulate damping using a nested loop driven by mechanosensory feedback, whereas visuomotor gain may be regulated through an outer loop using visual feedback (figure 4a) [17,33].Using this scheme, flies could regulate task-level damping by changing the haltere gain, whereas the open-loop gain regulates the visuomotor performance of the system.Had flies only regulated yaw damping in response to an increase in inertia, the optomotor response would have suffered a significant decrease in gaze stabilization gain at all frequencies (electronic supplementary material, figure S7).This is in stark contrast to our experimental results.Hence, tuning the visuomotor gain enabled flies to reduce the overall impact of added inertia by regulating the amount of torque produced.Through simulations, changes in inertia predicted an overall decrease in gain, even in the presence of feedback and in the absence of any changes in internal gains (figure 2a), thus we can conclude that flies likely implement an adaptive control scheme to compensate for changes in inertia.However, how flies regulate these internal parameters is not clear.We speculate that flies may implement an adaptive control scheme similar to a model reference adaptive scheme royalsocietypublishing.org/journal/rspb Proc.R. Soc.B 290: 20231115 (MRAS) [34].In this scheme, a system regulates the input to the plant (e.g.fly body) by comparing the observed output to the reference output generated from a desired model.This hypothesis does not rule out that flies implement another adaptive scheme, or even a parallel robust scheme that relies solely on feedback.It is also possible that flies rely solely on a robust control scheme that contains a number of nested feedback loops which cannot be modelled by our current framework.Overall, our results hint that flies implement an adaptive control scheme regulated by nested feedback loops to mitigate changes in inertia.

Material and methods (a) Animal preparation
Animal preparation was previously described in another study [35].Briefly, female fruit flies Drosophila melanogaster aged 3-5 days were cold anaesthetized at 4°C using a Peltier cooling stage.
The yaw inertia was altered by gluing a three-dimensional printed cylinder onto the stainless-steel pin (figure 1b; electronic supplementary material).Flies rested approximately 1 h before the start of experiments.After the rest period, flies were suspended between two magnets inside a virtual reality arena (figure 1a) [36].The pin's yaw inertia was less than 1% that of the fly's inertia (rod diameter = 100 µm, tip diameter = 12.5 µm; Minutien pin, Fine Science Tools).Hence, the pin introduces negligible inertia.Only flies that successfully completed at least three trials were used in subsequent analysis.Flies that continuously stopped flying during experiments or had very low baseline wingbeat amplitude (less than 100°) were not used in the analysis.

(b) Cylinder design and printing
Seven cylinders were designed to have progressively larger inertias that were integer multiples of the yaw body inertia of fruit flies (5.2×10 −13 kg m 2 [23]).To sample across a wide range of inertia and push the limit of flight performance, the cylinders were designed with logarithmically increasing yaw inertia (Table S5).The smallest cylinder had approximately the inertia of a fly, whereas the inertia of the largest cylinder was around sixty-four times that of a fly.To ensure the inertia of cylinders closely matched the desired value, we printed the cylinders using a resin 3D printer with a tolerance of 25 μm (Formlabs Form 3+ SLA printer).The cylinders were printed using a clear resin that had a density of 1.12-1.15g/ cm 3 .We determined the mass of each cylinder using an analytical scale with a resolution of 0.1 mg.Due to the limitation in printer resolution, the actual inertias of the printed cylinders were slightly larger than designed (Table S5).However, the actual mass and inertia of all cylinders fell within 10% of the desired inertia.Larger inertias (128x) were printed but not used in this study as the magnetic tether system could not support the extra weight of these cylinders.To ensure the cylinders were not a significant source of damping due to air friction, we estimated the torque due to air friction at different angular velocities.Our calculations indicate the torque due to air friction is roughly two orders of magnitude smaller than the torque required to overcome yaw damping (Figure S8), thus providing assurance that air friction of the cylinders was not a significant source of damping.

(c) Stimuli and experimental set-up
We presented magnetically tethered flies with a visual stimulus (moving background) that elicited an optomotor response.The background consisted of uniformly spaced bars with a spatial wavelength of 22.5°subtending onto the fly eye.To test the impact of increasing yaw inertia on flight performance, we presented magnetically tethered flies with a visual sum-of-sines stimulus (figure 1).This stimulus was generated by adding nine sine signals with distinct frequencies that ranged from 0.35 Hz to 13.7 Hz.Each component of this stimulus had a random phase and an amplitude normalized to a velocity of 52°s −1 .This ensured the stimulus velocity did not saturate the visual and motor systems, as previously described [13].Each trial lasted 20 s and was presented five times to each fly.A second set of experiments was conducted to measure the impact of increasing inertia on the yaw stability of flies in the presence of a static stimulus.Flies were presented with the same uniform background which was kept stationary for 10 s and underwent five trials.Flies that did not complete more than three trials or had a low wingbeat amplitude (less than 100°) were not used in the analysis.Changes in heading of the flies were measured using a bottom view camera (Basler acA640-750 µm) recording at 80-100 frames per second (fps).Wing data were collected by measuring the wingbeat amplitude (extreme position at downstroke-to-upstroke reversal) using a modified version of Kinefly [37].To enable accurate measurements of wingbeat amplitude, the bottom view videos were registered with respect to the fly's reference frame prior to tracking the wings.

(d) Tracking in the magnetic tether
The head and body motion were tracked using a custom MATLAB code that has been previously described [13].The amplitude of both wings were estimated by measuring the angle the edge of the wing blur made with the axis of the fly's body.Prior to the measurement of wing and head kinematics, videos were registered to eliminate the yaw rotation of the body, as done previously [13].
(e) Flight performance metric The impact of adding inertia was measured using multiple performance metrics commonly used in the system identification of engineering systems.The system identification analysis was conducted using MATLAB, and each metric was estimated for individual flies and then averaged out across all flies to determine the grand mean for each inertia treatment.The gain was calculated by dividing the FFT magnitude of the fly's heading (output) with that of the visual stimulus (input).The phase difference was estimated by subtracting the output's phase from that of the input.The coherence was estimated using the MATLAB built-in function mscohere.Finally, we used the compensation error to quantify changes in flight performance [13].
The compensation error is a metric that combines gain and phase to indicate how well flies compensate for a moving stimulus.A gain of unity and a phase difference of zero produce zero compensation error and indicate perfect tracking.The compensation error ε is calculated by finding the vector distance in the complex plane (norm) between the actual tracking performance H and perfect tracking Z 0 which can be expressed as A compensation error of zero indicates that flies perfectly compensated for the visual stimulus, a compensation error between zero and one indicate imperfect compensation, and values greater than one indicate that the system can a better job at stabilizing the input by effectively not responding.To avoid phase wrapping, the averaged phase difference was calculated using the circular statistics toolbox in MATLAB [38].

(f ) Transfer function fitting and system identification
Transfer function fitting was performed using MATLAB and the method is detailed elsewhere [39].In short, we fit the visual error and fly response to a first-order transfer function (equation royalsocietypublishing.org/journal/rspb Proc.R. Soc.B 290: 20231115 (2.2)).We did not fit the value of the inertia, rather we assumed a constant value for each group (total inertia = fly inertia + cylinder inertia).These parameters were estimated using a least square estimate [39].Only fits with at least 65% goodness of fit (GoF) were used in the transfer function fitting and parameter estimation.The GoF was at least 84% for all groups and detailed estimate for each inertia treatment is in the electronic supplementary material, table S6 and figure S3b.The FRF obtained from flies with an added inertia of 64× was not used in transfer function fitting due to the low overall coherence.

(g) Flapping counter-torque estimates
We estimated the flapping counter-torque (FCT), which is a passively generated torque in flapping flight that is produced during turns [19].In the magnetic tether, the FCT counter acts rotation about the yaw axis, thus, it can be thought of as viscous damping about the yaw axis proportional to yaw angular velocity.The method for estimating FCT in the magnetic tether has been described previously [5].Briefly, we estimated the stroke angle of flies by multiplying the base stroke angle from free flight data [29] with a correction factor, which was then projected onto the stroke plane.For rotation angles, we used the intact baseline rotation angles measured in free flight [29].The wing morphological parameters required to calculate the FCT were estimated using images of wings taken under a microscope and analyzed using custom MATLAB code.To estimate how changes in wing kinematics altered the FCT, we estimated the FCT for a flapping frequency ranging from 200 Hz to 1000 Hz.We also modified the rotation angle by multiplying the baseline rotation angle for both wings with a scaling factor.The passive damping was then estimated for different combinations of flapping frequency and rotation angles (figure 5d).

(h) Saccade detection and analysis
Saccade detection was accomplished using methods previously described [26].Magnetically tethered flies began to oscillate about the pin's axis when yaw inertia was increased by more than 8×, which complicated automatic saccade detection as the dynamics of the oscillations were close to the dynamics of saccades.To ensure no false saccades were included, we designed custom code (MATLAB) which flagged saccades with a displacement smaller than 10°and with a duration smaller than 50 ms.We manually verified and removed flagged saccades to confirm their identity via a custom graphical user interface.Further complicating the comparison of saccade dynamics was the large sample size (>100 saccades per group), thus a tiny difference in saccade dynamics produces small pvalues.Therefore, a comparison may yield a statistically significant, but not a biologically relevant difference.To address this issue, we computed Hedge's g, which presents a metric of effect size independent of sample size [40].This allowed us to properly compare changes in saccade dynamics of the inertia added flies to that of the unaltered group.

(i) Statistics and comparison
For all box plots, the central line is the median, the bottom and top edges of the box are the 25th and 75th percentiles and the whiskers extend to approximately ±2.7 s.d.Unless otherwise specified, we report means ± 1 s.d.Significant differences are stated as *p ≤ 0.05, **p ≤ 0.01, ***p ≤ 0.001.Unless otherwise noted, saccade dynamics were compared using the effect size model Hedge's g.

Figure 1 .
Figure 1.Experimental set-up and paradigm to test the impact of increasing yaw inertia on the performance and stability of fly flight.(a) The magnetic tether system and virtual reality arena.Changes in the fly's heading were recorded using a bottom view high-speed camera.(b) An illustration of a magnetically tethered fly with a cylinder glued onto the magnetic pin (left).The cylinders (top right) were three-dimensional printed and mounted onto the magnetic pins to increase yaw inertia (bottom right).(c) Proposed control framework used to model the optomotor response of magnetically tethered flies.(d ) Sample data of individual flies presented a static visual stimulus with different added inertia.(e) Magnitude plot showing the average frequency and amplitude of the oscillations.( f ) The visual sum-of-sines stimulus (grey) and the mean response across all individuals for select amounts of added inertia.For individual trials, see electronic supplementary material, figure S1a.For (e), the shaded region is ± 1 s.d.No added inertia n = 13 flies; 16×: n = 7 flies; 32×: n = 9 flies; 64×: n = 13 flies.For ( f ), no added inertia: n = 41 flies; 2×: n = 14 flies; 32×: n = 17 flies; 64×: n = 8 flies.

Figure 2 .
Figure2.Flies maintained similar performance at the expense of increased response time to stabilize gaze.(a) The average experimental closed-loop response with no added inertia (red line) versus the simulated response to additional yaw inertia (dashed lines).(b) The empirical frequency response function of flies with added inertia in response to a sum-of-sines stimulus.Addition of inertia had a significant influence on the phase difference and gain for frequencies greater than approximately 0.9 Hz (see electronic supplementary material, tableS1for exact values and statistics).(c) Simulated frequency response functions for a no added inertia fly with increasing time delay.For (a) and (c), dashed lines are from the simulation and solid lines are the experimental results.Plots with ± 1 s.d. are shown in electronic supplementary material, figure S2.No inertia added: n = 41 flies; 1×: n = 11 flies; 2×: n = 15 flies; 4×: n = 19 flies; 8×: n = 17 flies; 16×: n = 17 flies; 32×: n = 8 flies.
Figure2.Flies maintained similar performance at the expense of increased response time to stabilize gaze.(a) The average experimental closed-loop response with no added inertia (red line) versus the simulated response to additional yaw inertia (dashed lines).(b) The empirical frequency response function of flies with added inertia in response to a sum-of-sines stimulus.Addition of inertia had a significant influence on the phase difference and gain for frequencies greater than approximately 0.9 Hz (see electronic supplementary material, tableS1for exact values and statistics).(c) Simulated frequency response functions for a no added inertia fly with increasing time delay.For (a) and (c), dashed lines are from the simulation and solid lines are the experimental results.Plots with ± 1 s.d. are shown in electronic supplementary material, figure S2.No inertia added: n = 41 flies; 1×: n = 11 flies; 2×: n = 15 flies; 4×: n = 19 flies; 8×: n = 17 flies; 16×: n = 17 flies; 32×: n = 8 flies.

Figure 3 .
Figure 3. Flies increased visuomotor gain and yaw damping to maintain the same open-loop dynamics.(a) Estimate of the time delay for intact flies and flies with added inertia.Increasing inertia caused the time delay to increase.This increase was proportional to the amount of added inertia (ANOVA; d.f.= 6; p < 0.001).Horizontal line: mean.(b) The predicted (grey asterisk) and estimated visuomotor gain.In response to increases in inertia, flies modulated their visuomotor gain (ANOVA, d.f.= 6; p < 0.001).(c) The estimated active damping.Flies actively modulated their yaw damping (ANOVA; d.f.= 6; p < 0.001).(d ) Pole location of flies with different added inertia.The overall pole location of flies changed marginally (ANOVA; d.f.= 6; p = 0.04).(e) The open-loop gain ðK ol Þ and ( f ) the system time constant ðt f Þ.Flies maintained the same open-loop gain and time constants.ANOVA, d.f.= 6, p = 0.53 and p = 0.94, respectively.For all panels: no inertia added: n = 41 flies; 1×: n = 11 flies; 2×: n = 15 flies; 4×: n = 19 flies; 8×: n = 17 flies; 16×: n = 17 flies; 32×: n = 8 flies.Further details on the goodness of fit and pole locations can be found in electronic supplementary material, figure S4.For (b-f ), grey asterisks are the prediction from unaltered fly model parameters (equation (2.3)) with inertia as the only parameter change.

Figure 5 .
Figure 5. Proposed mechanism for regulating yaw damping.(a) The proposed control architecture to modulate damping and maintain stability.Using a nested mechanosensory feedback loop, flies could alter yaw damping by regulating the gain from the haltere feedback.(b) The impact of increasing inertia on the difference in wingbeat amplitude (DWBA).Changes in inertia caused no significant changes in DWBA (ANOVA, d.f.= 3, p = 0.28).(c) Estimates of the passive damping using a FCT model.The model predicted marginal changes in the FCT damping coefficient based on the two-dimensional wing kinematics.(d ) Changes in the FCT as a function of changes in the flapping frequency and magnitude of the wing rotation angle ratio.The magnitude of the rotation angle was modified by multiplying the intact-wing rotation angle with a scaling factor, whereas the frequency was varied from 200 Hz to 1000 Hz.Red rectangle: region in which flies can feasibly modulate flapping frequency.(e) Estimated changes in haltere feedback gain in response to changes in inertia.For (b,c,e), no inertia added: n = 41 flies; 1×: n = 11 flies; 2×: n = 15 flies; 4×: n = 19 flies; 8×: n = 17 flies; 16×: n = 17 flies; 32×: n = 8 flies.

Figure 6 .
Figure 6.Flies adaptively control saccades.(a) The average velocity profile of saccades for flies with no or added inertia (top panel), and the predicted saccade velocity profiles estimated using simulation (bottom panel, dashed lines).(b) Torque profile of flies with added inertia.As more inertia is added, flies produce more torque over a larger duration of time.(c) Saccade displacement, (d) peak velocity and (e) duration for flies.Adding inertia led to a slight increase in saccade displacement, a slight decrease in peak velocity and a notable increase in saccade duration (electronic supplementary material, tableS4).For (a,b), grey vertical line: peak velocity.For all panels: no added inertia: n = 301 saccades from 13 flies; 8×: n = 148 saccades from nine flies; 16×: n = 139 saccades from seven flies; 32×: n = 89 saccades from nine flies; 64×: n = 118 saccades from 13 flies.For saccade variation data see electronic supplementary material, figure S6.