def pwm_off (channel) : global board if (board == -1) : return gb.set_mode(board,channel,gb.MODE_OFF)
def pwm_init (channel) : # Set channel for brushed and start motor global inited global board if (board == -1) : return if inited == 0 : gb.open_uart(0) version = gb.get_version(board) print("Board version {}".format(version)) inited = 1 gb.set_mode(board,channel,gb.MODE_BRUSH) gb.move_brushed(board,channel,gb.MOVE_B)
def __init__(self): gb.open_uart(0) # Setup the channels for brushed motors gb.set_mode(BOARD, FRONT_LEFT, gb.MODE_BRUSH) gb.set_mode(BOARD, FRONT_RIGHT, gb.MODE_BRUSH) gb.set_mode(BOARD, BACK_LEFT, gb.MODE_BRUSH) gb.set_mode(BOARD, BACK_RIGHT, gb.MODE_BRUSH) # set a ramp-up speed in case motors are big gb.set_brush_ramps(BOARD, FRONT_LEFT, RAMP, RAMP, 0) gb.set_brush_ramps(BOARD, FRONT_RIGHT, RAMP, RAMP, 0) gb.set_brush_ramps(BOARD, BACK_LEFT, RAMP, RAMP, 0) gb.set_brush_ramps(BOARD, BACK_RIGHT, RAMP, RAMP, 0)
BOARD_A = 3 BOARD_B = 0 BRS_A = 0 RAMP = gb.RAMP_050 # ramp speed=0.5 seconds FORWD = gb.MOVE_A BACKW = gb.MOVE_B STOP = gb.MOVE_STOP STEPPER_A = 2 STEPPER_B = 0 STEPPER_C = 2 MODE = 24 FREQ = 400.0 gb.open_uart(0) gb.set_mode(BOARD_A, BRS_A, gb.MODE_BRUSH) gb.set_brush_ramps(BOARD_A, BRS_A, RAMP, RAMP, 0) gb.set_mode(BOARD_A, STEPPER_A, MODE) gb.freq_stepper(BOARD_A, STEPPER_A, FREQ) gb.set_mode(BOARD_B, STEPPER_B, MODE) gb.freq_stepper(BOARD_B, STEPPER_B, FREQ) gb.set_mode(BOARD_B, STEPPER_C, MODE) gb.freq_stepper(BOARD_B, STEPPER_C, FREQ) gb.set_endstop(BOARD_A, BRS_A, 2, 2) gb.set_endstop(BOARD_A, STEPPER_A, 2, 2) #gb.set_endstop(BOARD_B, STEPPER_B, 2, 2) #gb.set_endstop(BOARD_B, STEPPER_C, 2, 2) ard.write(str(3).encode()) # rainbow cycle
dxax_old = 0 dyax_old = 0 BOARD = 3 BRS_A = 0 RAMP = gb.RAMP_050 # ramp speed=0.5 seconds FORWD = gb.MOVE_A BACKW = gb.MOVE_B STOP = gb.MOVE_STOP STEPPER_B = 2 MODE = 24 FREQ = 400.0 gb.open_uart(0) gb.set_mode(BOARD, BRS_A, gb.MODE_BRUSH) gb.set_brush_ramps(BOARD, BRS_A, RAMP, RAMP, 0) gb.set_mode(BOARD, STEPPER_B, MODE) gb.freq_stepper(BOARD, STEPPER_B, FREQ) while True: dlen = binascii.b2a_hex(ser.read()).decode('utf-8') if dlen == '08' or dlen == '05' or dlen == '04': dsep = binascii.b2a_hex(ser.read()).decode('utf-8') if dsep == 'a1': dtyp = binascii.b2a_hex(ser.read()).decode('utf-8') if dtyp == '07': for i in range(len(btn)): btn[i] = 0 for i in range(len(btn)):
# ||||| ||||||| ||||||||| # ||||| ||||||| +++++++++--------< Left, right, stop # ||||| +++++++------------------< Which motor on board 0,1,2,3 # +++++--------------------------< which board 0,1,2,3 # Main program # Get the curses screen screen = curses.initscr() # Open serial port to talk to Gertbot gb.open_uart(0) # Setup the channels for brushed motors gb.set_mode(BOARD,LEFT,gb.MODE_BRUSH) gb.set_mode(BOARD,RIGHT,gb.MODE_BRUSH) # set a ramp-up speed in case motors are big gb.set_brush_ramps(BOARD,LEFT, RAMP,RAMP,0); gb.set_brush_ramps(BOARD,RIGHT,RAMP,RAMP,0); # Tell user what to expect # in curses print does not work anymore. use addstr screen.addstr("Gertbot example program for Python\n") screen.addstr("Use numeric keypad keys control\n") screen.addstr("Left Both Right\n") screen.addstr(" Forward \n") screen.addstr(" 7 8 9 \n") screen.addstr(" \n") screen.addstr(" 4 Stop 6 \n") screen.addstr(" \n")
def pwm_off (channel) : gb.set_mode(board,channel,gb.MODE_OFF)
def pwm_init (channel) : # Set channel for brushed and start motor gb.set_mode(board,channel,gb.MODE_BRUSH) gb.move_brushed(board,channel,gb.MOVE_B)
f14=False, f15=False, f16=False, f17=False, f18=False, f19=False, f20=False): ret1 = 0xDE ret2 = (f20 << 7) | (f19 << 6) | (f18 << 5) | (f17 << 4) | (f16 << 3) | ( f15 << 2) | (f14 << 1) | (f13) return [address, ret1, ret2] gb.open_uart(0) #gb.set_mode(board, channel, mode) gb.set_mode(board, 0, gb.MODE_DCC) gb.send_dcc_mess(board, 0xF, loco_speed(address=47)) gb.send_dcc_mess(board, 0xF, loco_functions_1(address=47, lights=True, f1=True)) time.sleep(15) gb.send_dcc_mess(board, 0xF, loco_functions_1(address=47, lights=True, f1=True, f2=True)) gb.send_dcc_mess(board, 0xF, loco_functions_1(address=47, lights=True, f1=True)) time.sleep(5) for i in range(0, 9): gb.send_dcc_mess(board, 0xF, loco_speed(address=47, speed=i, lights=True)) time.sleep(1) time.sleep(5) for i in range(0, 9):