<commit_before>(function () {
  var DISABLED = 'DISABLED';
  var ArduinoHelper = require('../../lib/ArduinoHelper');
  var ROVPilot = function ROVPilot(deps) {
    deps.logger.debug('The rovpilot plugin.');
    var self = this;
    self.SAMPLE_PERIOD = 1000 / deps.config.sample_freq;
    this.physics = new ArduinoHelper().physics;
    self.cockpit = deps.cockpit;
    self.globalEventLoop = deps.globalEventLoop;
    self.sendToROVEnabled = true;
    self.sendUpdateEnabled = true;
    self.priorControls = {};
    self.powerLevel = 2;
    self.setPowerLevel(2);
    //rov.powerLevel = 2;
    self.positions = {
      throttle: 0,
      yaw: 0,
      lift: 0,
      pitch: 0,
      roll: 0,
      strafe: 0
    };
    deps.cockpit.on('plugin.rovpilot.getState', function (callback) {
      var state = {
          senToROVEnabled: self.sendToROVEnabled,
          sendUpdateEnabled: self.sendUpdateEnabled,
          powerLevel: self.powerLevel,
          positions: self.positions
        };
        
      callback(state);
    });
    deps.cockpit.on('plugin.rovpilot.setPowerLevel', function (value) {
      self.setPowerLevel(value);
    });
    //Send initial state
    deps.cockpit.emit('plugin.rovpilot.setPowerLevel', 2);
    deps.cockpit.on('plugin.rovpilot.allStop', function () {
      self.allStop();
    });
    deps.cockpit.on('plugin.rovpilot.rates.setThrottle', function (value) {
      self.positions.throttle = value;
      if (value === 0) {
        self.positions.throttle = self.ttrim;
      }
    });
    deps.cockpit.on('plugin.rovpilot.rates.setYaw', function (value) {
      self.positions.yaw = value;
    });
    deps.cockpit.on('plugin.rovpilot.rates.setLift', function (value) {
      self.positions.lift = value;
    });
    deps.cockpit.on('plugin.rovpilot.rates.setPitch', function (value) {
      self.positions.pitch = value;
    });
    deps.cockpit.on('plugin.rovpilot.rates.setRoll', function (value) {
      self.positions.roll = value;
    });
    deps.cockpit.on('plugin.rovpilot.disable', function () {
      self.sendToROVEnabled = false;
    });
    deps.cockpit.on('plugin.rovpilot.enable', function () {
      self.sendToROVEnabled = true;
    });
    deps.cockpit.on('plugin.rovpilot.desiredControlRates', function (rates, ack, fn) {
      self.positions = rates;
      fn(ack);  //ack
    });
    this.startInterval = function () {
      setInterval(function () {
        self.sendPilotingData();
      }, 25);  //constantly check to see if new commands need to be sent to arduino
    };
    this.startInterval();
    return this;
  };
  // --------------------
  ROVPilot.prototype.adjustForPowerLimit = function adjustForPowerLimit(value) {
    return value * this.power;
  };
  ROVPilot.prototype.adjustYawForPowerLimit = function adjustYawForPowerLimit(value) {
    return Math.min(Math.max(value * this.power * 1.5, -1), 1);
  };
  ROVPilot.prototype.setPowerLevel = function setPowerLevel(value) {
    switch (value) {
    case 1:
      this.power = 0.12;
      break;
    case 2:
      this.power = 0.25;<commit_msg>Guard to ensure callback exists<commit_after>(function () {
  var DISABLED = 'DISABLED';
  var ArduinoHelper = require('../../lib/ArduinoHelper');
  var ROVPilot = function ROVPilot(deps) {
    deps.logger.debug('The rovpilot plugin.');
    var self = this;
    self.SAMPLE_PERIOD = 1000 / deps.config.sample_freq;
    this.physics = new ArduinoHelper().physics;
    self.cockpit = deps.cockpit;
    self.globalEventLoop = deps.globalEventLoop;
    self.sendToROVEnabled = true;
    self.sendUpdateEnabled = true;
    self.priorControls = {};
    self.powerLevel = 2;
    self.setPowerLevel(2);
    //rov.powerLevel = 2;
    self.positions = {
      throttle: 0,
      yaw: 0,
      lift: 0,
      pitch: 0,
      roll: 0,
      strafe: 0
    };
    deps.cockpit.on('plugin.rovpilot.getState', function (callback) {
      var state = {
          senToROVEnabled: self.sendToROVEnabled,
          sendUpdateEnabled: self.sendUpdateEnabled,
          powerLevel: self.powerLevel,
          positions: self.positions
        };
        
      callback(state);
    });
    deps.cockpit.on('plugin.rovpilot.setPowerLevel', function (value) {
      self.setPowerLevel(value);
    });
    //Send initial state
    deps.cockpit.emit('plugin.rovpilot.setPowerLevel', 2);
    deps.cockpit.on('plugin.rovpilot.allStop', function () {
      self.allStop();
    });
    deps.cockpit.on('plugin.rovpilot.rates.setThrottle', function (value) {
      self.positions.throttle = value;
      if (value === 0) {
        self.positions.throttle = self.ttrim;
      }
    });
    deps.cockpit.on('plugin.rovpilot.rates.setYaw', function (value) {
      self.positions.yaw = value;
    });
    deps.cockpit.on('plugin.rovpilot.rates.setLift', function (value) {
      self.positions.lift = value;
    });
    deps.cockpit.on('plugin.rovpilot.rates.setPitch', function (value) {
      self.positions.pitch = value;
    });
    deps.cockpit.on('plugin.rovpilot.rates.setRoll', function (value) {
      self.positions.roll = value;
    });
    deps.cockpit.on('plugin.rovpilot.disable', function () {
      self.sendToROVEnabled = false;
    });
    deps.cockpit.on('plugin.rovpilot.enable', function () {
      self.sendToROVEnabled = true;
    });
    deps.cockpit.on('plugin.rovpilot.desiredControlRates', function (rates, ack, fn) {
      self.positions = rates;
      if (typeof(fn)==="function"){
        fn(ack);  //ack
      }
    });
    this.startInterval = function () {
      setInterval(function () {
        self.sendPilotingData();
      }, 25);  //constantly check to see if new commands need to be sent to arduino
    };
    this.startInterval();
    return this;
  };
  // --------------------
  ROVPilot.prototype.adjustForPowerLimit = function adjustForPowerLimit(value) {
    return value * this.power;
  };
  ROVPilot.prototype.adjustYawForPowerLimit = function adjustYawForPowerLimit(value) {
    return Math.min(Math.max(value * this.power * 1.5, -1), 1);
  };
  ROVPilot.prototype.setPowerLevel = function setPowerLevel(value) {
    switch (value) {
    case 1:
      this.power = 0.12;
      break;
    case 2:
      this.power = 0.25;
{'fraction_non_alphanumeric': 0.14513530927835053, 'fraction_numerical': 0.009342783505154639, 'mean_word_length': 2.6182983682983685, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2987830', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2058, 'n_words': 351}