Robotics API 2.0 Multicopter Example

From Robotics API
Jump to: navigation, search
package quadcoptertest;

import org.roboticsapi.core.exception.InitializationException;
import org.roboticsapi.core.exception.RoboticsException;
import org.roboticsapi.feature.startup.multicopter.autoquad.indoor.MulticopterApplication;
import org.roboticsapi.framework.cartesianmotion.activity.LinearMotionInterface;
import org.roboticsapi.framework.quadrotor.Quadrotor;

// a simple application for rapid prototyping, will open a simple test GUI with buttons to try out certain methods (see below)
public class SimpleQuadcopterApplication extends MulticopterApplication {

	// a simple quadcopter
	private Quadrotor quad;

	public static void main(String[] args) throws InitializationException {
		new SimpleQuadcopterApplication().start();

	public SimpleQuadcopterApplication() throws InitializationException {
		super(true); // true means simulation mode

	protected void configure() throws RoboticsException {

		// create a simulated quadcopter
		quad = createSimulatedMulticopter("quad", 0, 0);

	// all public methods that start with 'test' will have an auto-generated
	// button in the application's test GUI
	public void testSimpleMovement() throws RoboticsException {
		// helper function for takeoff, will arm the quad and fly a linear
		// motion to the given height above the start point
		takeoff(1, quad);

		// define a goal relative to the quadcopter's position; this goal will
		// move with the quadcopter
		Pose relativeGoal = quad.getMovingFrame().asPose().plus(1, 1, 0);

		// fix the above goal relative to the global world origin
		Pose fixedGoal = relativeGoal.snapshot(getRapi().getWorld().getOrigin());

		// now we fly to the fixed goal

		// helper function for landing, will fly the quad a little below ground
		// and disarm it