How to use the motor.Motor function in motor

To help you get started, we’ve selected a few motor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 1zlab / 1ZLAB_PyEspCar / src / esp32 / test_encoder_with_motor.py View on Github external
global left_encoder
    global right_encoder

    left_motor.deinit()
    right_motor.deinit()
    left_encoder.deinit()
    right_encoder.deinit()
    button.deinit()

# 左侧电机
left_motor = Motor(0)
# 左侧编码器
left_encoder = Encoder(0, is_quad_freq=False, motor=left_motor)

# 右侧电机
right_motor = Motor(1)
# 右侧编码器
right_encoder = Encoder(1, is_quad_freq=False, motor=right_motor)

button = Button(0, callback=callback)
github 1zlab / 1ZLAB_PyEspCar / src / test_motor.py View on Github external
'''
电机测试
-----------------
左右轮设定特定的转速
'''
from car_config import gpio_dict, car_property
from motor import Motor
import time

# 左侧电机
lmotor = Motor(gpio_dict['LEFT_MOTOR_A'], gpio_dict['LEFT_MOTOR_B'], 
        motor_install_dir=car_property['LEFT_MOTOR_INSTALL_DIR'])
lmotor.pwm(300)

# 右侧电机
rmotor = Motor(gpio_dict['RIGHT_MOTOR_A'], gpio_dict['RIGHT_MOTOR_B'], 
        motor_install_dir=car_property['RIGHT_MOTOR_INSTALL_DIR'])
rmotor.pwm(300)

try:
    while True:
        pass
except:
    lmotor.deinit()
    rmotor.deinit()
github 1zlab / 1ZLAB_PyEspCar / src / test_left_msc.py View on Github external
from  machine import Pin,Timer
import utime

from car_config import gpio_dict, car_property

from user_button import UserButton
from motor import Motor
from encoder import Encoder
from pid_motor import MotorSpeedControl


# 设定紧急意外缓冲区的大小为100
micropython.alloc_emergency_exception_buf(100)

# 左侧电机
left_motor = Motor(gpio_dict['LEFT_MOTOR_A'], gpio_dict['LEFT_MOTOR_B'], 
        motor_install_dir=car_property['LEFT_MOTOR_INSTALL_DIR'])
left_motor.stop()

# 右侧电机
right_motor = Motor(
    gpio_dict['RIGHT_MOTOR_A'], 
    gpio_dict['RIGHT_MOTOR_B'], 
    motor_install_dir=car_property['RIGHT_MOTOR_INSTALL_DIR'])
right_motor.stop()

# 左侧编码器
left_pin_a = Pin(gpio_dict['LEFT_ENCODER_A'], Pin.IN)
left_pin_b = Pin(gpio_dict['LEFT_ENCODER_B'], Pin.IN)
left_encoder = Encoder(left_pin_a, left_pin_b,
    reverse=car_property['LEFT_ENCODER_IS_REVERSE'], 
    scale=car_property['LEFT_ENCODER_ANGLE_SCALE'])
github 1zlab / 1ZLAB_PyEspCar / src / esp32 / test_max_speed.py View on Github external
最大速度, 测试得到1.25m/s
'''
from motor import Motor
from car_config import car_property, gpio_dict
from button import Button
import utime

# 左侧电机
left_motor = Motor(
    gpio_dict['LEFT_MOTOR_A'],
    gpio_dict['LEFT_MOTOR_B'], 
    motor_install_dir=car_property['LEFT_MOTOR_INSTALL_DIR'])
left_motor.stop() # 左侧电机停止
        
# 右侧电机
right_motor = Motor(
    gpio_dict['RIGHT_MOTOR_A'], 
    gpio_dict['RIGHT_MOTOR_B'], 
    motor_install_dir=car_property['RIGHT_MOTOR_INSTALL_DIR'])
right_motor.stop() # 右侧电机停止



def callback(pin, pwm=1023, delay_ms=2000):
    global left_motor
    global right_motor

    left_motor.pwm(pwm)
    right_motor.pwm(pwm)

    utime.sleep_ms(delay_ms)
github nikivanov / watney / motorcontroller.py View on Github external
def __init__(self, config):
        driverConfig = config["DRIVER"]
        leftMotorConfig = config["LEFTMOTOR"]
        rightMotorConfig = config["RIGHTMOTOR"]

        leftMotor = Motor(int(leftMotorConfig["PWMPin"]),
                          int(leftMotorConfig["ForwardPin"]),
                          int(leftMotorConfig["ReversePin"]),
                          float(leftMotorConfig["Trim"]))

        rightMotor = Motor(int(rightMotorConfig["PWMPin"]),
                           int(rightMotorConfig["ForwardPin"]),
                           int(rightMotorConfig["ReversePin"]),
                           float(rightMotorConfig["Trim"]))

        self.leftMotor = leftMotor
        self.rightMotor = rightMotor
        self.halfTurnSpeed = float(driverConfig["HalfTurnSpeed"])
github manningt / aws-iot-GET-POST-loop / shade_controller.py View on Github external
def _activate_motor(self, duration, direction, pins):
        """Instantiates a motor and turns on the motor driver for the duration (expressed in milliseconds)
           self.current_sensor should have been instantiated before calling
            """
        from motor import Motor
        import machine, utime
        
        elapsed_time = 0
        self.average_current_threshold = self._shadow_state['state']['desired']['threshold'] * self.MOTOR_AVERAGING_SAMPLES
        
        #invert direction if reverse bit is set
        motor_direction = direction ^ (self._shadow_state['state']['desired']['reverse'] & 1)
        # self.motor = Motor(self.PIN_MOTOR_ENABLE1, self.PIN_MOTOR_ENABLE2)
        self.motor = Motor(pins)

        #enable 12V and disable charging
        if self.ppin_power_enable is None:
            self.ppin_power_enable = machine.Pin(self.PIN_POWER_ENABLE, machine.Pin.OUT, value=1)
        else:
            self.ppin_power_enable.value(1)
        
        if self.ppin_charging_disable is None:
            self.ppin_charging_disable = machine.Pin(self.PIN_CHARGING_DISABLE, machine.Pin.OUT, value=0)
        else:
            self.ppin_charging_disable.value(0)
        utime.sleep_ms(50) # wait for power to stabilize

        self.current_sensor.start()
        start_ticks = utime.ticks_ms()
        self.motor.start(direction=motor_direction, speed=self.MOTOR_START_SPEED)
github RightHandRobotics / reflex-ros-pkg / reflex / src / reflex / reflex_takktile_motor.py View on Github external
# limitations under the License.
#############################################################################

__author__ = 'Eric Schneider'
__copyright__ = 'Copyright (c) 2015 RightHand Robotics'
__license__ = 'Apache License 2.0'
__maintainer__ = 'RightHand Robotics'
__email__ = 'reflex-support@righthandrobotics.com'


import rospy

from motor import Motor


class ReflexTakktileMotor(Motor):
    def __init__(self, name):
        super(ReflexTakktileMotor, self).__init__(name)
        self.motor_cmd = 0.0
        self.speed = 0.0
        self.finger = None
        self.tactile_stops_enabled = False
        self.position_update_occurred = False
        self.speed_update_occurred = False
        self.reset_motor_speed()

    def get_commanded_position(self):
        return self.motor_cmd

    def get_commanded_speed(self):
        return self.speed
github TrampolineRTOS / trampoline / viper2 / config.py View on Github external
Network(network_master, "NET0", 0),
      BP("BPFaster", 5, position = [100, 400], text="/\\" ),
      BP("BPSlower", 6, position = [100, 480], text="\\/"),
      BP("BPLeft", 7, position = [0, 480], text="<" ),
      BP("BPRight", 8, position = [200, 480], text=">" ),
      Power("POWER", 9),
    ]
  ),
  Ecu(
    "../examples/viper2/App-Robot1/trampoline",
    scheduler,
    [
      Network(network_master, "NET1_1", 0),
      Timer("TIMER0", 1, type = timer.AUTO, delay = 100),
      DisplayServer("LCD1", 2, display_server),      
      Motor("MOTOR1_1",3),
      Motor("MOTOR1_2",4),
      Network(network_slave, "NET1_2", 5),
      Power("POWER", 9),
    ]
  ),
  Ecu(
    "../examples/viper2/App-Robot2/trampoline",
    scheduler,
    [
      Network(network_slave, "NET2", 0),
      Timer("TIMER0", 1, type = timer.AUTO, delay = 100),
      DisplayServer("LCD2", 2, display_server),      
      Motor("MOTOR2_1",3),
      Motor("MOTOR2_2",4),
      Power("POWER", 9),
    ]
github TrampolineRTOS / trampoline / viper2 / config.py View on Github external
BP("BPFaster", 5, position = [100, 400], text="/\\" ),
      BP("BPSlower", 6, position = [100, 480], text="\\/"),
      BP("BPLeft", 7, position = [0, 480], text="<" ),
      BP("BPRight", 8, position = [200, 480], text=">" ),
      Power("POWER", 9),
    ]
  ),
  Ecu(
    "../examples/viper2/App-Robot1/trampoline",
    scheduler,
    [
      Network(network_master, "NET1_1", 0),
      Timer("TIMER0", 1, type = timer.AUTO, delay = 100),
      DisplayServer("LCD1", 2, display_server),      
      Motor("MOTOR1_1",3),
      Motor("MOTOR1_2",4),
      Network(network_slave, "NET1_2", 5),
      Power("POWER", 9),
    ]
  ),
  Ecu(
    "../examples/viper2/App-Robot2/trampoline",
    scheduler,
    [
      Network(network_slave, "NET2", 0),
      Timer("TIMER0", 1, type = timer.AUTO, delay = 100),
      DisplayServer("LCD2", 2, display_server),      
      Motor("MOTOR2_1",3),
      Motor("MOTOR2_2",4),
      Power("POWER", 9),
    ]
  ),
github nikivanov / watney / motorcontroller.py View on Github external
def __init__(self, config):
        driverConfig = config["DRIVER"]
        leftMotorConfig = config["LEFTMOTOR"]
        rightMotorConfig = config["RIGHTMOTOR"]

        leftMotor = Motor(int(leftMotorConfig["PWMPin"]),
                          int(leftMotorConfig["ForwardPin"]),
                          int(leftMotorConfig["ReversePin"]),
                          float(leftMotorConfig["Trim"]))

        rightMotor = Motor(int(rightMotorConfig["PWMPin"]),
                           int(rightMotorConfig["ForwardPin"]),
                           int(rightMotorConfig["ReversePin"]),
                           float(rightMotorConfig["Trim"]))

        self.leftMotor = leftMotor
        self.rightMotor = rightMotor
        self.halfTurnSpeed = float(driverConfig["HalfTurnSpeed"])