hybridgroup / gobot-site

Website for Gobot - Golang framework/set of libraries for robotics and physical computing
http://gobot.io/
9 stars 18 forks source link

Add docs for using Gobot "bare metal" #48

Closed deadprogram closed 7 years ago

deadprogram commented 8 years ago

We need to add some docs that show how to use Gobot as a library, without using the entire framework, as discussed over in https://github.com/hybridgroup/gobot/issues/302

trevrosen commented 8 years ago

This subject is dear to my heart b/c it was the impetus behind my first submission to the project. I think it's important to provide a clear narrative in the docs helping people understand that the robot abstraction is powerful and useful, but that Gobot also shines as a way to just directly interact with things.

B/c of the adapter interface, I think that the docs can probably just choose one SBC as an example (RPi, BeagleBone, Edison). I vote for Beagle since we've already got an example of using the lib this way in our examples dir.

deadprogram commented 8 years ago

BTW, I am working on making the following syntax work as you would expect:

package main

import (
    "fmt"
    "github.com/hybridgroup/gobot/platforms/gpio"
    "github.com/hybridgroup/gobot/platforms/intel-iot/edison"
    "time"
)

func main() {
    e := edison.NewEdisonAdaptor("edison")
    led := gpio.NewLedDriver(e, "led", "13")
    button := gpio.NewButtonDriver(e, "button", "4")

    e.Connect()
    led.Start()
    button.Start()

    for {
        select {
        case event := <-button.Events:
            fmt.Println("Event:", event.Name, event.Data)
            if event.Name == "pushed" {
                led.Toggle()
            }
        }
    }
}

It does not work quite yet, but that is a temporary condition.

deadprogram commented 8 years ago

Progress! This actually works in my branch:

package main

import (
    "fmt"
    "github.com/hybridgroup/gobot/platforms/gpio"
    "github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
    e := edison.NewEdisonAdaptor("edison")
    led := gpio.NewLedDriver(e, "led", "13")
    button := gpio.NewButtonDriver(e, "button", "5")

    e.Connect()
    led.Start()
    button.Start()

    led.Off()

    buttonEvents := button.Subscribe()
    for {
        select {
        case event := <-buttonEvents:
            fmt.Println("Event:", event.Name, event.Data)
            if event.Name == "push" {
                led.Toggle()
            }
        }
    }
}
trevrosen commented 8 years ago

Nice!

On Aug 30, 2016, at 6:19 AM, Ron Evans notifications@github.com wrote:

Progress! This actually works in my branch:

package main

import ( "fmt" "github.com/hybridgroup/gobot/platforms/gpio" "github.com/hybridgroup/gobot/platforms/intel-iot/edison" )

func main() { e := edison.NewEdisonAdaptor("edison") led := gpio.NewLedDriver(e, "led", "13") button := gpio.NewButtonDriver(e, "button", "5")

e.Connect()
led.Start()
button.Start()

led.Off()

buttonEvents := button.Subscribe()
for {
    select {
    case event := <-buttonEvents:
        fmt.Println("Event:", event.Name, event.Data)
        if event.Name == "push" {
            led.Toggle()
        }
    }
}

} — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

trevrosen commented 8 years ago

is there anything I can do to help w/ this or you got it? Do we need further additions/explanations in the docs?

deadprogram commented 8 years ago

Hi @trevrosen please check out https://github.com/hybridgroup/gobot/pull/306 and give feedback!

Also, I have entered an issue for a proposed change related to new driver and new adaptor function signatures. Please check it out at https://github.com/hybridgroup/gobot/issues/307

deadprogram commented 7 years ago

This was released as part of Gobot 1.0 so closing.