Skip to content
adrnp edited this page Mar 25, 2015 · 1 revision

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() {

	if (new_pic) {

		// TODO: run picture result logic here......
		float diameter = pic_result.pic_d;

		// set new_pic to false, as just processed this pic result (DO NOT REMOVE THIS)
		new_pic = false;
	}

	// 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

Taking a Picture

In order to take a picture, a request must be sent to the virtual camera. This request is made by calling the take_picture() function. Once a picture is successfully taken, the new_pic variable flag will be set to true and the pic_result variable will contain new information.

At the beginning of the skeleton provided to you there is the following check for new_pic where you can execute any code you wish to execute when a picture has been successfully taken. The pic_result variable can also be used outside of this if statement.

	if (new_pic) {

		// TODO: run picture result logic here......
		float diameter = pic_result.pic_d;	/**< example of getting pic result info */

		// set new_pic to false, as just processed this pic result (DO NOT REMOVE THIS)
		new_pic = false;
	}

Notes on picture taking:

  • take_picture() can only be called from either the high priority module or the low priority module. DO NOT CALL IT FROM BOTH MODULES!!
  • new_pic will be set to true when there is new picture data in pic_result
  • When a picture is successfully taken, the result is available to both the high and low priority modules
  • If you call take_picture() and new_pic does not get set to true, it means that a picture taking condition has been violated

Dropping Water

Much like taking a picture, dropping water is done by sending a request to drop water from your current location using the drop_water() function.

Notes on water dropping:

  • drop_water() can only be called from either the high priority or the low priority module. DO NOT CALL IT FROM BOTH MODULES!!
  • You will have no direct feedback from the water drop function.
Clone this wiki locally