diff --git a/examples/Makefile b/examples/Makefile deleted file mode 100644 index 7cced90ec..000000000 --- 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 08d98f766..000000000 --- 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 697ff41e1..5a2956acd 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 494e00938..bcc01044d 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)