Skip to content
msberk edited this page Apr 14, 2016 · 2 revisions

Here is some helpful information for writing your GNC code and mission logic code.

Writing Your Code

When it comes to writing your control law, you have 2 modules to make use of, a high priority module and a low priority module.

Both of these modules have a aa241x_*_control_law.cpp file that contains a function where your code will be executed.

High Priority

For the high priority module, the function of interest is void flight_control() {} which is run every 17ms or at ~59 Hz.

Some notes on the flight_control() function:

  • All the servo outputs must be set in this function
  • Any data to be sent to the low priority module via the high_data struct must be set in this function
  • Excessive computation can potentially increase time between runs which may cause instabilities in your control law

Below is the provided skeleton for the flight_control() function:

void flight_control() {

	// TODO: write all of your flight control here...

	// setting high data values (for example)
	high_data.variable_name1 = roll;


	// ENSURE THAT YOU SET THE SERVO OUTPUTS!!!
	// outputs should be set to values between -1..1 (except throttle is 0..1)
	// where zero is no actuation, and -1,1 are full throw in either the + or - directions
	roll_servo_out = man_roll_in;		// as an example, just passing through manual control
	pitch_servo_out = -man_pitch_in;
	yaw_servo_out = man_yaw_in;
	throttle_servo_out = man_throttle_in;
}

Low Priority

For the low priority module, the function of interest is void low_loop() {} which runs at most every 20ms or 50 Hz. Because this module runs on a lower priority thread there is a bit more variability in the execution of the low_loop() function so the loop time is not guaranteed in this module!

Some notes of the low_loop() function:

  • Any data to be sent to the high priority module via the low_data struct must be set in this function
  • Loop execution frequency is NOT GUARANTEED!
  • Heavy computation leading to increased running time should not cause any problems
  • Recommended for more computation intensive tasks
Clone this wiki locally