stratux/test/sensortest.go

37 wiersze
642 B
Go
Czysty Zwykły widok Historia

2015-08-16 23:33:34 +00:00
package main
import (
"../mpu6050"
2015-08-16 23:33:34 +00:00
"fmt"
"net"
"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() {
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)
}
}