From 409cdfb0412a7349aa94ddb88b372c18d0230a87 Mon Sep 17 00:00:00 2001 From: Josh Finken Date: Fri, 2 Sep 2016 06:44:50 -0600 Subject: [PATCH] Removing the raspi_adafruit program as it has been split into three separate programs, removing my Makefile for the raspi adafruit programs, and fixing up a few comments. --- examples/Makefile | 23 -------- examples/raspi_adafruit.go | 82 --------------------------- examples/raspi_adafruit_stepper.go | 4 +- platforms/i2c/adafruit_driver_test.go | 9 ++- 4 files changed, 6 insertions(+), 112 deletions(-) delete mode 100644 examples/Makefile delete mode 100644 examples/raspi_adafruit.go diff --git a/examples/Makefile b/examples/Makefile deleted file mode 100644 index 7cced90e..00000000 --- a/examples/Makefile +++ /dev/null @@ -1,23 +0,0 @@ - -ip := 192.168.0.2 -build_dcmotor := GOARM=7 GOARCH=arm GOOS=linux go build -v raspi_adafruit_dcmotor.go -build_stepper := GOARM=7 GOARCH=arm GOOS=linux go build -v raspi_adafruit_stepper.go -build_servo := GOARM=7 GOARCH=arm GOOS=linux go build -v raspi_adafruit_servo.go - -all: - $(build_stepper) - $(build_dcmotor) - $(build_servo) - scp raspi_adafruit_stepper raspi_adafruit_dcmotor raspi_adafruit_servo pi@$(ip):~ - -stepper: - $(build_stepper) - scp raspi_adafruit_stepper pi@$(ip):~ - -dc: - $(build_dcmotor) - scp raspi_adafruit_dcmotor pi@$(ip):~ - -servo: - $(build_servo) - scp raspi_adafruit_servo pi@$(ip):~ diff --git a/examples/raspi_adafruit.go b/examples/raspi_adafruit.go deleted file mode 100644 index 08d98f76..00000000 --- a/examples/raspi_adafruit.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "log" - "time" - - "github.com/hybridgroup/gobot" - "github.com/hybridgroup/gobot/platforms/i2c" - "github.com/hybridgroup/gobot/platforms/raspi" -) - -func adafruitStepperMotorRunner(a *i2c.AdafruitMotorHatDriver, motor int) (err error) { - log.Printf("Stepper Motor Run Loop...\n") - // set the speed state: - speed := 30 // rpm - a.SetStepperMotorSpeed(motor, speed) - - //fmt.Println("Single coil steps") - if err = a.Step(motor, 100, i2c.AdafruitForward, i2c.AdafruitSingle); err != nil { - log.Printf(err.Error()) - return - } - if err = a.Step(motor, 100, i2c.AdafruitBackward, i2c.AdafruitSingle); err != nil { - log.Printf(err.Error()) - return - } - return -} -func adafruitDCMotorRunner(a *i2c.AdafruitMotorHatDriver, dcMotor int) (err error) { - - log.Printf("DC Motor Run Loop...\n") - // set the speed: - var speed int32 = 255 // 255 = full speed! - if err = a.SetDCMotorSpeed(dcMotor, speed); err != nil { - return - } - // run FORWARD - if err = a.RunDCMotor(dcMotor, i2c.AdafruitForward); err != nil { - return - } - // Sleep and RELEASE - <-time.After(2000 * time.Millisecond) - if err = a.RunDCMotor(dcMotor, i2c.AdafruitRelease); err != nil { - return - } - // run BACKWARD - if err = a.RunDCMotor(dcMotor, i2c.AdafruitBackward); err != nil { - return - } - // Sleep and RELEASE - <-time.After(2000 * time.Millisecond) - if err = a.RunDCMotor(dcMotor, i2c.AdafruitRelease); err != nil { - return - } - return -} -func main() { - gbot := gobot.NewGobot() - r := raspi.NewRaspiAdaptor("raspi") - adaFruit := i2c.NewAdafruitMotorHatDriver(r, "adafruit") - - work := func() { - gobot.Every(5*time.Second, func() { - - //dcMotor := 3 // 0-based - //adafruitDCMotorRunner(adaFruit, dcMotor) - - motor := 0 // 0-based - adafruitStepperMotorRunner(adaFruit, motor) - }) - } - - robot := gobot.NewRobot("adaFruitBot", - []gobot.Connection{r}, - []gobot.Device{adaFruit}, - work, - ) - - gbot.AddRobot(robot) - - gbot.Start() -} diff --git a/examples/raspi_adafruit_stepper.go b/examples/raspi_adafruit_stepper.go index 697ff41e..5a2956ac 100644 --- a/examples/raspi_adafruit_stepper.go +++ b/examples/raspi_adafruit_stepper.go @@ -13,8 +13,8 @@ func adafruitStepperMotorRunner(a *i2c.AdafruitMotorHatDriver, motor int) (err e log.Printf("Stepper Motor Run Loop...\n") // set the speed state: speed := 30 // rpm - style := i2c.AdafruitMicrostep - steps := 50 + style := i2c.AdafruitDouble + steps := 20 a.SetStepperMotorSpeed(motor, speed) diff --git a/platforms/i2c/adafruit_driver_test.go b/platforms/i2c/adafruit_driver_test.go index 494e0093..bcc01044 100644 --- a/platforms/i2c/adafruit_driver_test.go +++ b/platforms/i2c/adafruit_driver_test.go @@ -90,8 +90,8 @@ func TestAdafruitMotorHatDriverRunDCMotor(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() dcMotor := 1 - // NOT using this prevents importing the i2c package - //dir := i2c.AdafruitForward + // NOTE: not using the direction constant to prevent importing + // the i2c package err := ada.RunDCMotor(dcMotor, 1) gobottest.Assert(t, err, nil) } @@ -107,9 +107,8 @@ func TestAdafruitMotorHatDriverSetStepperMotorSpeed(t *testing.T) { func TestAdafruitMotorHatDriverStepperStep(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - // NOT using these prevents importing the i2c package - //dir := i2c.AdafruitForward - //style := i2c.AdafruitMicrostep + // NOTE: not using the direction and style constants to prevent importing + // the i2c package stepperMotor := 0 steps := 50 err := ada.Step(stepperMotor, steps, 1, 3)