Ejemplo n.º 1
0
def move_a_bit(a):
    stepper = Stepper(a, 2000, 1000)

    df = pd.DataFrame(index=np.arange(0, 1500 * 2),
                      columns=('v', 's', 'd', 't'))

    t = 0.0
    s = 0
    try:
        stepper.target_pos = 1500
        while True:
            d = stepper.step()
            m = 1 << stepper.micro
            if d == 0 or stepper.pos / m >= 300:
                stepper.set_target_speed(6000)
                break
            t += d
            df.loc[s] = [1e6 / d / m, stepper.pos / m, d / 1e6, t / 1e6]
            s += 1
        while True:
            d = stepper.step()
            m = 1 << stepper.micro
            if d == 0:
                break
            if 1e6 / d / m < 200:
                i = 1
            df.loc[s] = [1e6 / d / m, stepper.pos / m, d / 1e6, t / 1e6]
            t += d
            s += 1
    except:
        print("FAIL")
    return df.dropna()
Ejemplo n.º 2
0
def stepper_test():
    #stepper variables
    # [stepPin, directionPin, enablePin]

    testStepper = Stepper([24, 22, 23])

    #test stepper
    testStepper.step(20000, "CW"); #steps, dir, speed, stayOn

    sleep(2)
    # test stepper
    testStepper.step(64000, "CCW");  # steps, dir, speed, stayOn

    return {"Stepper test": "done"}
Ejemplo n.º 3
0
def stepper_move(steps,dir,speed):
    #stepper variables
    # [stepPin, directionPin, enablePin]
    #print steps
    testStepper = Stepper([24, 22, 23])
    if dir in VALID_MOVE_DIR:
        #test stepper
        testStepper.step(steps, dir,speed) #steps, dir, speed, stayOn
        data={"Stepper move": "done",
         "dir": dir,
         "steps": steps,
         "speed": speed
         }
    else:
        data={'Move': 'ERROR',
            'error': 'Invalid direction.'}

    return data
Ejemplo n.º 4
0
def accel_2_integer(steps, a):

    stepper = Stepper(a, 10000, 700)
    stepper.target_pos = steps

    df = pd.DataFrame(index=np.arange(0, steps * 16),
                      columns=('v', 's', 'd', 't', 'adj_d', 'micro', 'shift'))

    t = 0
    s = 0
    while True:
        d = stepper.step()
        if d == 0 or s > steps * 16:
            break

        m = 1 << stepper.micro
        v = 1e6 / d / m
        p = stepper.pos / m
        ad = d * m
        t += d
        df.loc[s] = [v, p, d, t / 1e6, ad, m, stepper.shift]
        s += 1
    return df.dropna()
Ejemplo n.º 5
0
class PokemonGoBot(object):

    def __init__(self, config):
        self.config = config
        self.pokemon_list=json.load(open('pokemon.json'))
        self.item_list=json.load(open('items.json'))

    def start(self):
        self._setup_logging()
        self._setup_api()
        self.stepper = Stepper(self)

    def take_step(self):
        self.stepper.set_position()
        self.stepper.get_cells()
        self.catch_pokemon()

        if self.config.spinstop:
            self.goto_pokestop()
        else:
            self.stepper.step()

    def catch_pokemon(self):
        self.stepper.get_cells()
        surrounding_pokemon = ['catchable_pokemons', 'wild_pokemons']
        print "seaching for pokemon"
        for pokemon_type in surrounding_pokemon:
            for cell in self.stepper.cells:
                if pokemon_type in cell:
                    for pokemon in cell[pokemon_type]:
                       worker = PokemonCatchWorker(pokemon, self)
                       worker.work()

    def goto_pokestop(self):
        for cell in self.stepper.cells:
            if 'forts' in cell:
                for fort in cell['forts']:
                    if 'type' in fort:
                        worker = SeenFortWorker(cell, fort, self)
                        hack_chain = worker.work()
                        if hack_chain > 10:
                            print('need a rest')
                            break

    def _setup_logging(self):
        self.log = logging.getLogger(__name__)
        logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(module)10s] [%(levelname)5s] %(message)s')
        logging.getLogger("requests").setLevel(logging.WARNING)
        logging.getLogger("pgoapi").setLevel(logging.INFO)
        logging.getLogger("rpc_api").setLevel(logging.INFO)

    def _setup_api(self):
        self.api = PGoApi()
        self._set_starting_position()

        if not self.api.login(self.config.auth_service, self.config.username, self.config.password):
            return

        # chain subrequests (methods) into one RPC call

        # get player profile call
        # ----------------------
        self.api.get_player()

        response_dict = self.api.call()
        #print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2)))
        currency_1="0"
        currency_2="0"
        try:
            if 'amount' in response_dict['responses']['GET_PLAYER']['profile']['currency'][0]:
                currency_1=response_dict['responses']['GET_PLAYER']['profile']['currency'][0]['amount']
            if 'amount' in response_dict['responses']['GET_PLAYER']['profile']['currency'][1]:
                currency_2=response_dict['responses']['GET_PLAYER']['profile']['currency'][1]['amount']
            print 'Profile:'
            print '    Username: '******'responses']['GET_PLAYER']['profile']['username'])
            print '    Bag size: ' + str(response_dict['responses']['GET_PLAYER']['profile']['item_storage'])
            print '    Pokemon Storage Size: ' + str(response_dict['responses']['GET_PLAYER']['profile']['poke_storage'])
            print '    Account Creation: ' + str(response_dict['responses']['GET_PLAYER']['profile']['creation_time'])
            print '    Currency: '
            print '        ' + str(response_dict['responses']['GET_PLAYER']['profile']['currency'][0]['type']) + ': ' + str(currency_1)
            print '        ' + str(response_dict['responses']['GET_PLAYER']['profile']['currency'][1]['type']) + ': ' + str(currency_2)
        except:
            print('Exception during print player profile')

    def _set_starting_position(self):
        self.position = self._get_pos_by_name(self.config.location)
        self.api.set_position(*self.position)
        print(self.position)
        if self.config.test:
            return

    def _get_pos_by_name(self, location_name):
        geolocator = GoogleV3(api_key=self.config.gmapkey)
        loc = geolocator.geocode(location_name)

        self.log.info('Your given location: %s', loc.address.encode('utf-8'))
        self.log.info('lat/long/alt: %s %s %s', loc.latitude, loc.longitude, loc.altitude)

        return (loc.latitude, loc.longitude, loc.altitude)
Ejemplo n.º 6
0
from stepper import Stepper

#stepper variables
#[stepPin, directionPin, enablePin]
testStepper = Stepper([23, 24, 22])

#test stepper
testStepper.step(1600, "right"); #steps, dir, speed, stayOn