{"id":420,"date":"2013-08-02T09:49:42","date_gmt":"2013-08-02T09:49:42","guid":{"rendered":"http:\/\/blog.daft-ideas.co.uk\/?p=420"},"modified":"2013-08-02T09:49:42","modified_gmt":"2013-08-02T09:49:42","slug":"uav-reading-sensor-data-part-ii","status":"publish","type":"post","link":"https:\/\/blog.daft-ideas.co.uk\/2013\/08\/02\/uav-reading-sensor-data-part-ii\/","title":{"rendered":"UAV, reading sensor data Part II"},"content":{"rendered":"

In our previous adventure, Matt and I defeated the dragon and rescued a fake princess who turned into a giant spider\u00a0<\/del> managed to get some meaningful data from both the gyrometer and the accelerometer. We also made some pretty graphs.<\/p>\n

The next step is for us to compare the outputs from the Gyro and the Accelerometer. This is currently impossible, given that the\u00a0Accelerometer is transformed into meaningul readings (degrees) already, and the gyro is just a load of “rate of change” readings.<\/p>\n

We can get the orientation readings from the Gyro like this:<\/p>\n

  \/\/Create variables for outputs\r\n  float xGyroRate, yGyroRate, zGyroRate, xGyroRate2, yGyroRate2, zGyroRate2;\r\n  long Time;\r\n  \/\/Read the x,y and z output rates from the gyroscope & correct for some innacuracy; convert to seconds\r\n  xGyroRate = (gyroReadX())\/57.5;\r\n  yGyroRate = (gyroReadY())\/57.5;\r\n  zGyroRate = (gyroReadZ())\/57.5;\r\n  \/\/Determine how long it's been moving at this 'rate', in seconds\r\n  Time = (millis()-previousMillis);\r\n  \/\/Multiply rates by duration\r\n  xGyroRate2 = -(xGyroRate\/Time)\/4;\r\n  yGyroRate2 = -(yGyroRate\/Time)\/4;\r\n  zGyroRate2 = -(zGyroRate\/Time)\/4;\r\n  \/\/Add to cumulative figure\r\n  if (((xGyroRate2)>(gyroLPF))||((xGyroRate2)<(-gyroLPF)))   CumulatGyroX += (xGyroRate2);   if (yGyroRate2>gyroLPF||yGyroRate2<-gyroLPF)   CumulatGyroY += (yGyroRate2);   if (zGyroRate2>gyroLPF||zGyroRate2<-gyroLPF)\r\n  CumulatGyroZ += (zGyroRate2);<\/pre>\n

Now that we’ve done this, we can measure an axis from both the Gyro and the Accelerometer at the same time, and overlay them on top of one another in gnu plot.<\/p>\n

Like so:<\/p>\n

\"Yeah,<\/a>

Yeah, that didn’t really work.<\/p><\/div>\n

Ok, so there was something wrong with that. We tweaked the code some more, and got something a bit better:<\/p>\n

\"No,<\/a>

Much worse.<\/p><\/div>\n

Finally, we figure out where we went wrong with the code. We don’t have the old versions, so we can’t show you our idiotic mistakes. After fixing it, we get something much closer to what we were expecting:<\/p>\n

\"Roll<\/a>

Roll measurement from Gyro and Accelerometer<\/p><\/div>\n

We can see from this graph that both sensors are outputting more or less the same thing. However the gyro measurements are actually off by a bit at the start, and are slowly producing a more noticeably incorrect orientation. If we used just the gyro, we’d end up with the plane downside up. There are also “spikes” in the accelerometer readings, at 700 and 1300 – these are probably noisy readings from the sensor.<\/p>\n

To get an idea of how much the gyro readings drift, we turned on all the gyro sensors and then left the board still for a few seconds:<\/p>\n

\"Gyro<\/a>

Gyro drift in three axes.<\/p><\/div>\n

This is obviously not going to work long term – we can’t be certain of either sensor. We need a way to combine the readings from both sensors, or face the consequences.<\/p>\n","protected":false},"excerpt":{"rendered":"

In our previous adventure, Matt and I defeated the dragon and rescued a fake princess who turned into a giant spider\u00a0 managed to get some meaningful data from both the gyrometer and the accelerometer. We also made some pretty graphs. The next step is for us to compare the outputs… Continue reading → <\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,9],"tags":[65,14,66,10],"_links":{"self":[{"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/posts\/420"}],"collection":[{"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":2,"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/posts\/420\/revisions"}],"predecessor-version":[{"id":426,"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/posts\/420\/revisions\/426"}],"wp:attachment":[{"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/media?parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/categories?post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.daft-ideas.co.uk\/wp-json\/wp\/v2\/tags?post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}