vokkim / signalk-ruuvitag-plugin

Signal K plugin to provide RuuviTag data
MIT License
4 stars 8 forks source link

Attitude sensor #27

Open macjl opened 11 months ago

macjl commented 11 months ago

Hello,

Do you think the Ruuvi acceleration sensors could be used to provide attitude (yaw, pitch, roll) informations to signalk ?

macjl commented 11 months ago

I created a "signalk-derived-data" calculation that may work. maybe this could be integrated directly in this plugin ?

module.exports = function (app, plugin) {
  return {
    group: 'heading',
    optionKey: 'attitude',
    title:
      'Attitude Yall, Pitch (based on environment.inside.mainCabin.acceleration[X,Y,Z])',
    properties: {
      correctRoll: {
        type: 'number',
        title: 'Correction of roll',
        default: 0
      },
      correctPitch: {
        type: 'number',
        title: 'Correction of Pitch',
        default: 0
      }
    },
    derivedFrom: [
      'environment.inside.mainCabin.accelerationX',
      'environment.inside.mainCabin.accelerationY',
      'environment.inside.mainCabin.accelerationZ'
    ],
    calculator: function (accelerationX, accelerationY, accelerationZ) {
        var correctPitch = plugin.properties.heading.correctPitch
        var correctRoll  = plugin.properties.heading.correctRoll
        var pitch = correctPitch / 57.29578 + Math.asin( accelerationX / Math.sqrt( accelerationX^2 + accelerationY^2 + accelerationZ^2 ))
        var roll  = correctRoll  / 57.29578 + Math.asin( accelerationY / Math.sqrt( accelerationX^2 + accelerationY^2 + accelerationZ^2 ))
      return [
        {
          path: 'navigation.attitude',
          value: {
                pitch: pitch,
                roll: roll
                }
        }
      ]
    }
  }
}