def set_position(self, layer_id, cmd_pos, vel): ''' ''' layer = Layer(layer_id) layer.cmd_pos = cmd_pos layer.velocity = vel layer.cur_pos = self.client.get_motor_cur_pos(layer.name) steps = cmd_pos - layer.cur_pos if steps > 0: layer.direction = 'END_POSITION' else: layer.direction = 'INIT_POSITION' steps = abs(steps) layer.steps = steps layer.cur_pos = self.layer_move_skip_sensor(layer_id)
def set_to_zero(self, name, direction, velocity, steps, cur_pos, cmd_pos): motor = Layer(name) motor.steps = 0 motor.direction = direction motor.velocity = velocity dir_pin = 0 motor.cur_pos = 0 motor.cmd_pos = 0 #print "SET ALL TO ZERO" #print "name %s" % motor.name #print "direction %s" % motor.direction #print "velocity %d" % motor.velocity #print "steps %d" % motor.steps #print "cur_pos %d" % motor.cur_pos #print "cmd_pos %d" % motor.cmd_pos return 0
def motor_move_skip_sensor(self, name, direction, velocity, steps, cur_pos, cmd_pos): #print "name %s" % name #print "direction %s" % direction #print "velocity %d" % velocity #print "steps %d" % steps #print "cur_pos %d" % cur_pos #print "cmd_pos %d" % cmd_pos motor = Layer(name) motor.steps = steps motor.direction = direction motor.velocity = velocity dir_pin = 0 if('INIT_POSITION' in direction): dir_pin = 1 - motor.pos_dir else: dir_pin = motor.pos_dir # if(dir_pin): #print 'pin on' # else: #print 'pin off' if(dir_pin): self.turn_on_gpio(motor.pin_dir) else: self.turn_off_gpio(motor.pin_dir) self.turn_on_gpio(motor.pin_sleep) s = c_driver.move_motor(steps, motor.pin_step) self.turn_off_gpio(motor.pin_sleep) #print sys._getframe().f_code.co_name, #print ": %s -> %1.2f " % (name, s) motor.cur_pos = cmd_pos motor.cmd_pos = cmd_pos #print "\n\n" return motor.cur_pos