示例#1
0
def rollforward():
        try:

                m= grove_i2c_motor_driver.motor_driver()
                m.MotorSpeedSetAB(0,69)
                m.MotorDirectionSet(0b0101)
                time.sleep(0.25)
                m.MotorSpeedSetAB(0,0)

                
        except IOError:
                print("Unable to find the motor driver, check the addrees and press reset on the motor driver and try again")
示例#2
0
 def __init__(self):
     self.switch = switch.Switch()
     while not self.con:
         print("NO CONN DROPPER")
         time.sleep(2)
         try:
             self.motor = grove_i2c_motor_driver.motor_driver(address=0x0f)
             self.motor.MotorSpeedSetAB(100, 100)
         except IOError:
             continue
         self.con = True
     self.motor.MotorSpeedSetAB(0, 0)
     self.bus = smbus.SMBus(1)
示例#3
0
def rollback():
        try:

                m= grove_i2c_motor_driver.motor_driver()
                m.MotorSpeedSetAB(0,69)
                m.MotorDirectionSet(0b1010)
                while GPIO.input(11) != GPIO.HIGH:
                    continue
                m.MotorSpeedSetAB(0,0)

                
        except IOError:
                print("Unable to find the motor driver, check the addrees and press reset on the motor driver and try again")
示例#4
0
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import grove_i2c_motor_driver
import time

try:
	# You can initialize with a different address too: grove_i2c_motor_driver.motor_driver(address=0x0a)
	m= grove_i2c_motor_driver.motor_driver()

	#FORWARD
	print("Forward")
	m.MotorSpeedSetAB(100,100)	#defines the speed of motor 1 and motor 2;
	m.MotorDirectionSet(0b1010)	#"0b1010" defines the output polarity, "10" means the M+ is "positive" while the M- is "negtive"
	time.sleep(2)

	#BACK
	print("Back")
	m.MotorSpeedSetAB(100,100)
	m.MotorDirectionSet(0b0101)	#0b0101  Rotating in the opposite direction
	time.sleep(2)

	#STOP
	print("Stop")
示例#5
0
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import grove_i2c_motor_driver
import time

try:
    # You can initialize with a different address too: grove_i2c_motor_driver.motor_driver(address=0x0a)
    m = grove_i2c_motor_driver.motor_driver()

    #FORWARD
    print("Forward")
    m.MotorSpeedSetAB(100, 100)  #defines the speed of motor 1 and motor 2;
    m.MotorDirectionSet(
        0b1010
    )  #"0b1010" defines the output polarity, "10" means the M+ is "positive" while the M- is "negtive"
    time.sleep(2)

    #BACK
    print("Back")
    m.MotorSpeedSetAB(100, 100)
    m.MotorDirectionSet(0b0101)  #0b0101  Rotating in the opposite direction
    time.sleep(2)
示例#6
0
import grove_i2c_motor_driver
import time

m = grove_i2c_motor_driver.motor_driver(address=0x0e)
# controller2 = grove_i2c_motor_driver.motor_driver(address=0x0a)
try:
    # You can initialize with a different address too: grove_i2c_motor_driver.motor_driver(address=0x0a)

    #FORWARD
    print("Forward")
    m.MotorSpeedSetAB(100, 0)  #defines the speed of motor 1 and motor 2;
    m.MotorDirectionSet(
        0b1010
    )  #"0b1010" defines the output polarity, "10" means the M+ is "positive" while the$
    time.sleep(10)

except IOError:
    print(
        "Unable to find the motor driver, check the addrees and press reset on the motor driver and try again"
    )
示例#7
0
import temp
import ec
import waterlevel
import relay
import time
import json
from sensor import sensor
import grove_i2c_motor_driver
import paho.mqtt.client as mqtt
from threading import Lock, Thread

broker_address = "192.168.1.55"
MQTT_TOPIC = [("/actuators/plugs/command/#",0), ("/actuators/motors/#",0)]
motorController = grove_i2c_motor_driver.motor_driver()
lock = Lock() #thread lock


# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected to MQTT server with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe(MQTT_TOPIC)


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    #cmd = json.loads(msg.payload)
    print('on_message : ' + msg.payload)
    # print(sensorName+" "+returnState(sensorVoltage))
示例#8
0
import grove_i2c_motor_driver as motor
import time
m = motor.motor_driver()

print("Starting Motor 1")
m.MotorSpeedSetAB(0, 100)
m.MotorDirectionSet(0b1010)
time.sleep(10)

print("Stopping Motor 1")
m.MotorSpeedSetAB(0, 0)

print("Starting Motor 2")
m.MotorSpeedSetAB(100, 0)
m.MotorDirectionSet(0b1010)
time.sleep(10)

print("Stopping Motor 2")
m.MotorSpeedSetAB(0, 0)
示例#9
0
 def __init__(self):
     self.driver = grove.motor_driver()
     self.left = 0
     self.right = 0
     self.left_forward = True
     self.right_forward = True
示例#10
0
import os
import string
import paho.mqtt.client as mqtt
import time
import json
import grove_i2c_motor_driver

########################
# Main
########################
if "__main__" == __name__:

    motorController1 = grove_i2c_motor_driver.motor_driver(0x0f)
    motorController1.MotorSpeedSetAB(0, 0)
    motorController1.MotorDirectionSet(0b1010)

    #motorController2 = grove_i2c_motor_driver.motor_driver(0x0e)
    #motorController2.MotorSpeedSetAB(100,100)
    #motorController2.MotorDirectionSet(0b1010)

    quit()