From a3f086ccd77628f5ad312584e712f4362c10fab7 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Thu, 19 Oct 2017 12:40:35 +0200 Subject: [PATCH] holystone: Update example for correctness, and README as well Signed-off-by: deadprogram --- examples/holystone_hs200.go | 38 ++++++++++++++++++ platforms/holystone/hs200/README.md | 49 ++++++++++------------- platforms/holystone/hs200/hs200_driver.go | 2 +- 3 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 examples/holystone_hs200.go diff --git a/examples/holystone_hs200.go b/examples/holystone_hs200.go new file mode 100644 index 00000000..40f10f42 --- /dev/null +++ b/examples/holystone_hs200.go @@ -0,0 +1,38 @@ +// +build example +// +// Do not build by default. + +/* + How to run + go run examples/holystone_hs200.go + +*/ + +package main + +import ( + "time" + + "gobot.io/x/gobot" + "gobot.io/x/gobot/platforms/holystone/hs200" +) + +func main() { + drone := hs200.NewDriver("172.16.10.1:8888", "172.16.10.1:8080") + + work := func() { + drone.TakeOff() + + gobot.After(5*time.Second, func() { + drone.Land() + }) + } + + robot := gobot.NewRobot("hs200", + []gobot.Connection{}, + []gobot.Device{drone}, + work, + ) + + robot.Start() +} diff --git a/platforms/holystone/hs200/README.md b/platforms/holystone/hs200/README.md index 3bb14918..698f22a6 100644 --- a/platforms/holystone/hs200/README.md +++ b/platforms/holystone/hs200/README.md @@ -1,5 +1,10 @@ # Holystone HS200 +This package contains the Gobot driver for the Holystone HS200 drone. + +For more information on this drone, go to: +http://www.holystone.com/product/Holy_Stone_HS200W_FPV_Drone_with_720P_HD_Live_Video_Wifi_Camera_2_4GHz_4CH_6_Axis_Gyro_RC_Quadcopter_with_Altitude_Hold,_Gravity_Sensor_and_Headless_Mode_Function_RTF,_Color_Red-39.html + ## How to Install ``` @@ -17,40 +22,30 @@ Here is a sample of how you initialize and use the driver: package main import ( - "log" "time" - "fmt" - + "gobot.io/x/gobot" "gobot.io/x/gobot/platforms/holystone/hs200" ) func main() { - drone, err := hs200.NewDriver("172.16.10.1:8888", "172.16.10.1:8080") - if err != nil { - log.Fatal(err) + drone := hs200.NewDriver("172.16.10.1:8888", "172.16.10.1:8080") + + work := func() { + drone.TakeOff() + + gobot.After(5*time.Second, func() { + drone.Land() + }) } - fmt.Println("Enable!") - drone.Enable() - time.Sleep(5 * time.Second) - fmt.Println("Take off!") - drone.TakeOff() - time.Sleep(5 * time.Second) - fmt.Println("Full steam ahead!") - drone.Forward(1.0) - time.Sleep(3 * time.Second) - fmt.Println("Full steam back!") - drone.Forward(-1.0) - time.Sleep(3 * time.Second) - fmt.Println("Hover!") - drone.Forward(0) - time.Sleep(3 * time.Second) - fmt.Println("Land!") - drone.Land() - time.Sleep(5 * time.Second) - fmt.Println("Disable!") - drone.Disable() - time.Sleep(5 * time.Second) + + robot := gobot.NewRobot("hs200", + []gobot.Connection{}, + []gobot.Device{drone}, + work, + ) + + robot.Start() } ``` diff --git a/platforms/holystone/hs200/hs200_driver.go b/platforms/holystone/hs200/hs200_driver.go index eb603c82..a9527196 100644 --- a/platforms/holystone/hs200/hs200_driver.go +++ b/platforms/holystone/hs200/hs200_driver.go @@ -8,7 +8,7 @@ import ( "gobot.io/x/gobot" ) -// Driver reperesents the control information for the hs200 drone +// Driver represents the control information for the hs200 drone type Driver struct { name string mutex *sync.RWMutex // Protect the command from concurrent access