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)
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 opendrain_set(d,on) : global d0 global d1 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 if d == 0 : d0 = on elif d == 1 : d1 = on gb.activate_opendrain(board,d0,d1);
dyax_old = 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)
# gb.move_brushed(board,channel,direction) # ^^^^^ ^^^^^^^ ^^^^^^^^^ # ||||| ||||||| ||||||||| # ||||| ||||||| ||||||||| # ||||| ||||||| +++++++++--------< 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")