Beispiel #1
0
def main(settings):

    # Establish a serial connection to the dynamixel network.
    # This usually requires a USB2Dynamixel
    serial = dynamixel.SerialStream(port=settings['port'],
                                    baudrate=settings['baudRate'],
                                    timeout=1)
    # Instantiate our network object
    net = dynamixel.DynamixelNetwork(serial)

    # Populate our network with dynamixel objects
    for servoId in settings['servoIds']:
        newDynamixel = dynamixel.Dynamixel(servoId, net)
        net._dynamixel_map[servoId] = newDynamixel

    if not net.get_dynamixels():
        print 'No Dynamixels Found!'
        sys.exit(0)
    else:
        print "...Done"

    # Prompt the user to move servos.
    answer = int(raw_input("Input an integer between 0 and 1024: "))
    if (0 < answer < 1024):

        # Set up the servos
        for actuator in net.get_dynamixels():
            actuator.moving_speed = 500
            actuator.torque_enable = True
            actuator.torque_limit = 800
            actuator.max_torque = 800
            actuator.goal_position = answer

        # Send all the commands to the servos.
        net.synchronize()
Beispiel #2
0
    def __init__(self, port='/dev/ttyUSB1'):
        self.baudrate = 1000000
        self.port = port
        self.maxID = 18
        self.actuators = [None] * (self.maxID + 1)

        # Establish a serial connection to the dynamixel network.
        # This usually requires a USB2Dynamixel
        self.serial = dynamixel.SerialStream(port=self.port,
                                             baudrate=self.baudrate,
                                             timeout=1)
        # Instantiate our network object
        self.net = dynamixel.DynamixelNetwork(self.serial)

        # Populate our network with dynamixel objects
        for servoId in xrange(1, self.maxID + 1):
            newDynamixel = dynamixel.Dynamixel(servoId, self.net)
            self.net._dynamixel_map[servoId] = newDynamixel
            self.actuators[servoId] = newDynamixel

        # Verify Initialization
        if not self.net.get_dynamixels():
            print 'No Dynamixels Found!'

            # TODO: Throw exception instead
            sys.exit(0)
        else:
            print "Dynamixels connected."

        # Initialize servos
        for servoId in xrange(1, self.maxID + 1):
            dyn = self.actuators[servoId]
            dyn.torque_enable = True
            dyn.goal_position = dyn.current_position
Beispiel #3
0
def changeId(oldid, newid):
    #Make sure to only have 1 dynamixel connected!!
    newDynamixel = dynamixel.Dynamixel(oldid, net)
    net._dynamixel_map[oldid] = newDynamixel
    newDynamixel._set_id(newid)
    #servoId2 = newDynamixel._get_id()
    print 'Success'
Beispiel #4
0
def addDynamixel(servoid, initial_position=512):
    newDynamixel = dynamixel.Dynamixel(servoid, net)
    net._dynamixel_map[servoid] = newDynamixel
    newDynamixel._set_synchronized(False)
    newDynamixel.moving_speed = 200
    newDynamixel.torque_enable = True
    newDynamixel.torque_limit = 600
    newDynamixel.max_torque = 1023
    newDynamixel.goal_position = initial_position
Beispiel #5
0
    def __init__(self, trim, name='raider'):

        # Configuration
        self._name = name
        self._trim = trim
        self.dxl = dynamixel.Dynamixel()
        self.joint_position = np.full(25, 512)

        self.osc = []
        for i in range(25):
            self.osc.append(octosnake.Oscillator())
Beispiel #6
0
    def __init__(self):
        # Establish a serial connection to the dynamixel network.
        # This usually requires a USB2Dynamixel
        serial = dynamixel.SerialStream(port=config.port,
                                        baudrate=config.baudRate,
                                        timeout=1)

        # Instantiate our network object
        self.net = dynamixel.DynamixelNetwork(serial)

        # Populate our network with dynamixel objects
        for servoId in config.wheels[0] + config.wheels[1] + config.joints:
            newDynamixel = dynamixel.Dynamixel(servoId, self.net)
            self.net._dynamixel_map[servoId] = newDynamixel

        # Initial read in
        for actuator in self.net.get_dynamixels():
            print 'Currently on motor %d' % actuator.id
            actuator.read_all()
            if actuator.id in config.wheels[0]:
                print '    Left wheel'
                actuator.cw_angle_limit = 0
                actuator.ccw_angle_limit = 0
                # actuator.moving_speed = 200
            elif actuator.id in config.wheels[1]:
                print '    Right wheel'
                actuator.cw_angle_limit = 0
                actuator.ccw_angle_limit = 0
                # actuator.moving_speed = 1223
            elif actuator.id in config.joints:
                print '    Joint'
                actuator.cw_angle_limit = 0
                actuator.ccw_angle_limit = 1023
                # actuator.moving_speed = 100
                actuator.torque_enable = True
                actuator.torque_limit = 800 
                actuator.max_torque = 800
                # actuator.goal_position = 512
            else:
                print '    Something is wrong'

        # Some state information of the Mantis robot
        self.moveVelocity = 0
        self.skidVelocity = 0
        self.currentAngle = self.net[config.joints[0]].current_position
        self.turnStopped = False
        self.liftStopped = False

        # Start the scheduled synchronize every 0.2 seconds
        self.synchronize(0.2)
Beispiel #7
0
    def __init__(self, settings, errorlog):
        try:
            self.name = settings['name']
        except:
            self.name = "RULS_DEFAULT"
        self.clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connected = False
        self.configurations = {}
        self.configuration_ids = []

        # Establish a serial connection to the dynamixel network.
        # This usually requires a USB2Dynamixel
        try:
            self.serial = dynamixel.SerialStream(port=settings['port'],
                                                 baudrate=settings['baudRate'],
                                                 timeout=1)
        except:
            errorlog.write("ERROR: No Dynamixels Found!\n")
            printdt("No Dynamixels Found!")
            device_controller.restart_program()

        # Instantiate our network object
        self.net = dynamixel.DynamixelNetwork(self.serial)

        # Populate our network with dynamixel objects
        for servoId in settings['servoIds']:
            newDynamixel = dynamixel.Dynamixel(servoId, self.net)
            self.net._dynamixel_map[servoId] = newDynamixel

        # Get all the dynamixels in the network
        if not self.net.get_dynamixels():
            errorlog.write("ERROR: No Dynamixels Found!\n")
            printdt("No Dynamixels Found!")
            device_controller.restart_program()
        else:
            printdt("Dynamixels found, network initialized")

        for actuator in self.net.get_dynamixels():
            actuator._set_to_wheel_mode()
            actuator.moving_speed = 1024
            actuator.torque_enable = False
            actuator.torque_limit = 1023
            actuator.max_torque = 1023
            actuator.goal_position = 512

        self.net.synchronize()
Beispiel #8
0
    def scan(self, start_id, end_id):
        """
        Scan the network to discover the Dynamixels present.

        start_id - the id for the start of the search
        end_id - the id for the end of the search

        Note:
        function builds an internal list of Dynamixels present on the network.
        Typically call this function only once per DynamixelNetwork instance
        it will rebuild the list and create new Dynamixel instances to fill it,
        any previously retrieved Dynamixels.
        for all possible IDs (0 thru 254) can be time consuming.
        So if the range can be constrained to predetermined values it can 
        speed up the process.
        """
        self._dynamixel_map = {}
        ids = self.scan_ids(start_id, end_id)
        for ident in ids:
            self._dynamixel_map[ident] = dynamixel.Dynamixel(ident, self)
Beispiel #9
0
def main(settings):
    
    # Establish a serial connection to the dynamixel network.
    # This usually requires a USB2Dynamixel
    serial = dynamixel.SerialStream(port=settings['port'],
                                    baudrate=settings['baudRate'],
                                    timeout=1)
    # Instantiate our network object
    net = dynamixel.DynamixelNetwork(serial)

    # Populate our network with dynamixel objects
    for servoId in settings['servoIds']:
        newDynamixel = dynamixel.Dynamixel(servoId, net)
        net._dynamixel_map[servoId] = newDynamixel
    
    if not net.get_dynamixels():
      print 'No Dynamixels Found!'
      sys.exit(0)
    else:
      print "...Done"
    
    # Prompt the user to move servos.
    answer = raw_input("Would you like to move all the servos to the home position?"
                   "\nWARNING: If servos are obstructed this could damage them "
                   "\nor things in their path. [y/N] ")
    if answer in ['y', 'Y', 'yes', 'Yes', 'YES']:

        # Set up the servos
        for actuator in net.get_dynamixels():
            actuator._set_to_joint_mode()
            actuator.moving_speed = 50
            actuator.torque_enable = True
            actuator.torque_limit = 800 
            actuator.max_torque = 800
            actuator.goal_position = 512

        # Send all the commands to the servos.
        net.synchronize()

        print("Congratulations! Read the code to find out how that happened!")
Beispiel #10
0
def mainSetup(settings):
    global robot
    # Establish a serial connection to the dynamixel network.
    # This usually requires a USB2Dynamixel
    serial = dynamixel.SerialStream(port=settings['port'],
                                    baudrate=settings['baudRate'],
                                    timeout=0.02)
    # Instantiate our network object
    net = dynamixel.DynamixelNetwork(serial)

    # Populate our network with dynamixel objects
    for servoId in settings['servoIds']:
        newDynamixel = dynamixel.Dynamixel(servoId, net)
        net._dynamixel_map[servoId] = newDynamixel

    if not net.get_dynamixels():
        print 'No Dynamixels Found!'
        sys.exit(0)
    else:
        print "...Done"

    robot = net
Beispiel #11
0

def translate_to_dynamixel(value):
    k = translate(value, -150, 150, 0, 1023)
    return int(k)


# Establish a serial connection to the dynamixel network.
# This usually requires a USB2Dynamixel
serial = dynamixel.SerialStream(port='/dev/ttyUSB0',
                                baudrate='1000000',
                                timeout=2)
# Instantiate our network object
net = dynamixel.DynamixelNetwork(serial)

Dynamixel1 = dynamixel.Dynamixel(1, net)
Dynamixel2 = dynamixel.Dynamixel(2, net)
Dynamixel3 = dynamixel.Dynamixel(3, net)
Dynamixel4 = dynamixel.Dynamixel(4, net)
Dynamixel5 = dynamixel.Dynamixel(5, net)

net._dynamixel_map[1] = Dynamixel1
net._dynamixel_map[2] = Dynamixel2
net._dynamixel_map[3] = Dynamixel3
net._dynamixel_map[4] = Dynamixel4
net._dynamixel_map[5] = Dynamixel5
# Populate our network with dynamixel objects

# Set up the servos
actuator1 = Dynamixel1
actuator2 = Dynamixel2
net.scan(1,highestServoId)
settings['servoIds']=[]
print 'found the following dynamixels IDs:'
for dyn in net.get_dynamixels():
	print dyn.id
	settings['servoIds'].append(dyn.id)
if not settings['servoIds']:
	print 'No Dynamixels Found!'
	sys.exit(0)
	

####################################START POSITION####################################        
net = dynamixel.DynamixelNetwork(serial)

for servoId in settings['servoIds']:
	newDynamixel = dynamixel.Dynamixel(servoId, net)
	net._dynamixel_map[servoId] = newDynamixel

if not net.get_dynamixels():
	print 'No Dynamixels'
else:
	print "setup done, test can begin"

for actuator in net.get_dynamixels():
	actuator.moving_speed = 55
	actuator.torque_enable = True
	actuator.torque_limit = 800
	actuator.max_torque = 800
net.synchronize()
S1 = net.get_dynamixels()[2]
S2 = net.get_dynamixels()[0]
Beispiel #13
0
import dynamixel
import sys
import time

serial = dynamixel.SerialStream(port=sys.argv[1], baudrate=1000000, timeout=1)
net = dynamixel.DynamixelNetwork(serial)

pan = dynamixel.Dynamixel(1, net)
net._dynamixel_map[1] = pan

tilt = dynamixel.Dynamixel(2, net)
net._dynamixel_map[2] = tilt

pan.torque_enable = True
tilt.torque_enable = True

pan.moving_speed = 100
tilt.moving_speed = 100

pan.goal_position = 512
tilt.goal_position = 512

net.synchronize()
Beispiel #14
0
#!/usr/bin/env python2
# Import the dynamixel library
import dynamixel
# Import the time library for it's sleep functionality
import time

# Open a connection to the USB2Dynamixel device
serial = dynamixel.SerialStream(port="/dev/ttyUSB0",
                                baudrate=1000000,
                                timeout=1)
# Configure a DynamixelNetwork
net = dynamixel.DynamixelNetwork(serial)

# Configure the motor servo actuator
actuator = dynamixel.Dynamixel(1, net)
net._dynamixel_map[1] = actuator

# Configure the actuator such that it is in free running mode, and at a standstill
# The speed of the motor is configured in steps
# The values 0-1023 sets the motor to rotate clockwise at the given speed (1023 max)
# The values 1024-2047 sets the motor to rotate counterclockwise at the given speed - 1024
# The value 1024 represents stopped
actuator.moving_speed = 1024
# Enable torque for the motor
actuator.torque_enable = True
# Set the maximum torque to maximum
actuator.torque_limit = 1023
actuator.max_torque = 1023
# Set the goal position to 512 to enable free running mode
actuator.goal_position = 512
Beispiel #15
0
    def buscarServos(self):
        """
        busca los servos, los inicia e inicializa el electroiman
        La primera vez que se ejecuta guarda la configuracion en un archivo settins.yaml
        para futuros usos, asi no hay de volver a buscar y solo carga la ultima configuracion
        """
        self.iman = Arduino()
        parser = optparse.OptionParser()
        parser.add_option(
            "-c",
            "--clean",
            action="store_true",
            dest="clean",
            default=False,
            help=
            "Ignore the settings.yaml file if it exists and prompt for new settings."
        )
        (options, args) = parser.parse_args()
        #Busca el archivo settings.yaml
        settingsFile = 'settings.yaml'
        if not options.clean and os.path.exists(settingsFile):
            with open(settingsFile, 'r') as fh:
                self.settings = yaml.load(fh)
        #Si no lo encuentra
        else:
            self.settings = {}
            self.settings['port'] = '/dev/ttyUSB0'
            # Baud rate
            baudRate = self.validateInput(1000000, 9600, 1000000)
            self.settings['baudRate'] = baudRate
            # Servo ID
            highestServoId = None
            while not highestServoId:
                hsiTest = raw_input(
                    "Please enter the highest ID of the connected servos: ")
                highestServoId = self.validateInput(hsiTest, 1, 255)
            self.settings['highestServoId'] = highestServoId
            highestServoId = self.settings['highestServoId']
            #Establece una conexion serial con dynamixel network
            #Requiere un USB2Dynamixel
            serial = dynamixel.SerialStream(port=self.settings['port'],
                                            baudrate=self.settings['baudRate'],
                                            timeout=1)
            net = dynamixel.DynamixelNetwork(serial)
            # Ping the range of servos that are attached
            print "Scanning for Dynamixels..."
            net.scan(1, highestServoId)
            self.settings['servoIds'] = []
            print "Found the following Dynamixels IDs: "
            for dyn in net.get_dynamixels():
                print dyn.id
                self.settings['servoIds'].append(dyn.id)
            # Make sure we actually found servos
            if not self.settings['servoIds']:
                print 'No Dynamixels Found!'
                sys.exit(0)
            # Save the output settings to a yaml file
            with open(settingsFile, 'w') as fh:
                yaml.dump(self.settings, fh)
                print(
                    "Your settings have been saved to 'settings.yaml'. \nTo " +
                    "change them in the future either edit that file or run " +
                    "this example with -c.")
        # Establish a serial connection to the dynamixel network.
        # This usually requires a USB2Dynamixel
        serial = dynamixel.SerialStream(port=self.settings['port'],
                                        baudrate=self.settings['baudRate'],
                                        timeout=1)

        # Instantiate our network object
        self.net = dynamixel.DynamixelNetwork(serial)

        # Populate our network with dynamixel objects
        for servoId in self.settings['servoIds']:
            newDynamixel = dynamixel.Dynamixel(servoId, self.net)
            self.net._dynamixel_map[servoId] = newDynamixel