2015-08-16 23:33:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-08-31 03:30:09 +00:00
|
|
|
"../mpu6050"
|
2015-08-16 23:33:34 +00:00
|
|
|
"fmt"
|
|
|
|
"net"
|
2015-08-20 20:47:05 +00:00
|
|
|
"time"
|
2015-08-16 23:33:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var attSensor *mpu6050.MPU6050
|
|
|
|
|
|
|
|
func readMPU6050() (float64, float64) {
|
|
|
|
pitch, roll := attSensor.PitchAndRoll()
|
|
|
|
|
|
|
|
return pitch, roll
|
|
|
|
}
|
|
|
|
|
|
|
|
func initMPU6050() {
|
2015-12-27 21:26:14 +00:00
|
|
|
attSensor = mpu6050.New()
|
2015-08-16 23:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
initMPU6050()
|
|
|
|
addr, err := net.ResolveUDPAddr("udp", "192.168.1.255:49002")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
outConn, err := net.DialUDP("udp", nil, addr)
|
|
|
|
for {
|
|
|
|
pitch, roll := readMPU6050()
|
2015-08-20 23:47:05 +00:00
|
|
|
s := fmt.Sprintf("XATTMy Sim,%f,%f,%f", attSensor.Heading(), pitch, roll)
|
2015-08-16 23:33:34 +00:00
|
|
|
fmt.Printf("%f, %f\n", pitch, roll)
|
|
|
|
outConn.Write([]byte(s))
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
}
|
2015-08-20 20:47:05 +00:00
|
|
|
}
|