<commit_before>'use strict';

var util = require('util');
var EventEmitter = require('events').EventEmitter;

// Available updaters
var updatersNames = ['dummy', 'rate', 'rate-simple', 'stabilize-simple'];

// require() updaters
var updaters = {};
updatersNames.forEach(function (name) {
	updaters[name] = require('./'+name);
});

class Controller extends EventEmitter {
	constructor(quad) {
		this.quad = quad;

		var that = this;

		// Initialize controller targets
		this.target = {};
		['x', 'y', 'z'].forEach(function (axis) {
			that.target[axis] = 0;
		});

		// Instanciate updaters
		this.updaters = {};
		for (var updaterName in updaters) {
			this.updaters[updaterName] = updaters[updaterName](quad, this);
		}
	}

	/**
	 * Update this controller target.
	 */
	setTarget(target) {
		this.target = target;
		this.emit('target', target);

		// TODO: reset integral term for PIDs?
		// What about other terms?
	}
	
	/**
	 * Reset the controller.
	 */
	reset() {
		this.emit('reset');
	}
	
	/**
	 * Feed the controller with new data from sensors,
	 * and get the new correction for motors.
	 * Returns an object containg x, y, z keys with forces delta.
	 */
	update(data) {
		var updater = this.quad.config.pid.controller;

		// IMU not available OR quadcopter on ground:
		// Do not use PIDs
		if (!data/* || this.quad.power <= 0.2*/) {
			updater = 'dummy';
		}

		// Get the result from the currently enabled updater
		// If the updater returns a string, use this string as updater
		// TODO: deprecate this feature?
		while (true) {
			var result = this.updaters[updater](data);
			if (typeof result == 'string') {
				updater = result;
			} else {
				return result;
			}
		}
	}
}

Controller.available = updatersNames;

module.exports = Controller;<commit_msg>Update index.js<commit_after>'use strict';

var EventEmitter = require('events').EventEmitter;

// Available updaters
var updatersNames = ['dummy', 'rate', 'rate-simple', 'stabilize-simple'];

// require() updaters
var updaters = {};
updatersNames.forEach(function (name) {
	updaters[name] = require('./'+name);
});

class Controller extends EventEmitter {
	constructor(quad) {
		this.quad = quad;

		// Instanciate updaters
		this.updaters = {};
		for (var updaterName in updaters) {
			this.updaters[updaterName] = updaters[updaterName](quad);
		}
	}
	
	_currentUpdater() {
		var updaterName = this.quad.config.pid.controller;
		return this.updaters[updaterName];
	}

	/**
	 * Update the controller target.
	 */
	setTarget(target) {
		this._currentUpdater().setTarget(target);
	}
	
	/**
	 * Reset the controller.
	 */
	reset() {
		this._currentUpdater().reset();
	}
	
	/**
	 * Feed the controller with new data from sensors,
	 * and get the new correction for motors.
	 * Returns an object containg x, y, z keys with forces delta.
	 */
	update(data) {
		var updater = this.quad.config.pid.controller;

		// IMU not available OR quadcopter on ground:
		// Do not use PIDs
		if (!data/* || this.quad.power <= 0.2*/) {
			updater = 'dummy';
		}

		// Get the result from the currently enabled updater
		// If the updater returns a string, use this string as updater
		// TODO: deprecate this feature?
		while (true) {
			var result = this.updaters[updater](data);
			if (typeof result == 'string') {
				updater = result;
			} else {
				return result;
			}
		}
	}
	
	static get available() {
		return updatersNames;
	}
}

module.exports = Controller;
{'fraction_non_alphanumeric': 0.14227286006427112, 'fraction_numerical': 0.001460706982179375, 'mean_word_length': 3.28, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1842207', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1115, 'n_words': 313}