<commit_before>var async = require('async');

var tessel = require('tessel');
var servolib = require('servo-pca9685');

var servo = servolib.use(tessel.port['A']);


var frequency = 100;
var servo1    = 5; // We have a servo plugged in at position 1

var maxForward = 0.20;
var maxReverse = 0.10;
var neutral    = 0.15;

var delay      = 3750;

function calibrate(done) {
  async.series([
    function(callback) {
      console.log('duty cycle: maxForward');
      servo.setDutyCycle(servo1, maxForward, callback);
    },
    function(callback) {
      setTimeout(callback, delay);
    },
    function(callback) {
      console.log('duty cycle: maxReverse');
      servo.setDutyCycle(servo1, maxReverse, callback);
    },
    function(callback) {
      setTimeout(callback, delay);
    },
    function(callback) {
      console.log('duty cycle: neutral');
      servo.setDutyCycle(servo1, neutral, callback);
    },
    function(callback) {
      done();
    }
  ]);
}

servo.on('ready', function () {
  console.log('servo ready');

  async.series([
    function(callback) {
      servo.setModuleFrequency(frequency, callback);
    },
    function(callback) {
      console.log('servo module frequency set: ', frequency);
      callback();
    },
    function(callback) {
      console.log('duty cycle: neutral');
      servo.setDutyCycle(servo1, neutral, callback);
    }
  ]);
});

// ?.??? -> reverse -> 1.0 ms               0.114
// 0.171 -> neutral -> 1.5 ms ??? 1.48 ms
// ?.??? -> forward -> 2.0 ms               0.228

process.stdin.resume();
process.stdin.on('data', function (data) {
  data = String(data).replace(/[\r\n]*$/, '');  //  Removes the line endings

  if (data === 'calibrate') {
    console.log('calibrating ...');
    calibrate(function() {
      console.log('calibration complete');
    });
  } else {
    var dutyCycle = parseFloat(data);

    if (dutyCycle > 0.1 && dutyCycle < 0.2) {
      console.log('setting duty cycle to: ', dutyCycle);
      servo.setDutyCycle(servo1, dutyCycle);
    }
  }
});
<commit_msg>- initial rudder support (manual)<commit_after>var async = require('async');

var tessel = require('tessel');
var servolib = require('servo-pca9685');

var servo = servolib.use(tessel.port['A']);


var frequency = 100;
var motorPin    = 5;
var rudderPin   = 4;

var maxForward = 0.20;
var maxReverse = 0.10;
var neutral    = 0.15;

var delay      = 3750;

function calibrate(done) {
  async.series([
    function(callback) {
      console.log('motor duty cycle: maxForward');
      servo.setDutyCycle(motorPin, maxForward, callback);
    },
    function(callback) {
      setTimeout(callback, delay);
    },
    function(callback) {
      console.log('motor duty cycle: maxReverse');
      servo.setDutyCycle(motorPin, maxReverse, callback);
    },
    function(callback) {
      setTimeout(callback, delay);
    },
    function(callback) {
      console.log('motor duty cycle: neutral');
      servo.setDutyCycle(motorPin, neutral, callback);
    },
    function(callback) {
      done();
    }
  ]);
}

servo.on('ready', function () {
  console.log('servo ready');

  async.series([
    function(callback) {
      servo.setModuleFrequency(frequency, callback);
    },
    function(callback) {
      console.log('servo module frequency set: ', frequency);
      callback();
    },
    function(callback) {
      console.log('motor duty cycle: neutral');
      servo.setDutyCycle(motorPin, neutral, callback);
    },
    function(callback) {
      console.log('rudder duty cycle: neutral');
      servo.setDutyCycle(rudderPin, neutral, callback);
    }
  ]);
});

// ?.??? -> reverse -> 1.0 ms               0.114
// 0.171 -> neutral -> 1.5 ms ??? 1.48 ms
// ?.??? -> forward -> 2.0 ms               0.228

process.stdin.resume();
process.stdin.on('data', function (data) {
  data = String(data).replace(/[\r\n]*$/, '');  //  Removes the line endings

  if (data === 'calibrate') {
    console.log('calibrating ...');
    calibrate(function() {
      console.log('calibration complete');
    });
  } else {
    var dutyCycle = parseFloat(data);

    if (dutyCycle >= 0.1 && dutyCycle <= 0.2) {
      console.log('setting duty cycle to: ', dutyCycle);
      servo.setDutyCycle(rudderPin, dutyCycle);
    }
  }
});

{'fraction_non_alphanumeric': 0.16482482953209499, 'fraction_numerical': 0.023512814483893724, 'mean_word_length': 2.7982142857142858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '5570925', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1398, 'n_words': 290}