class Robot
¶
Example
# Import Robot class
from robot import Robot
# Create a robot(PiSloth)
robot = Robot(pin_list=[0, 1, 2, 3], name="pisloth")
robot.move_list["forward"] = [
[0, 40, 0, 15],
[-30, 40, -30, 15],
[-30, 0, -30, 0],
[0, -15, 0, -40],
[30, -15, 30, -40],
[30, 0, 30, 0],
]
robot.do_action("forward", step=3, speed=90)
API
- class robot_hat.Robot(pin_list, db='/root/.config/robot-hat/robot-hat.conf', name=None, init_angles=None, init_order=None, **kwargs)¶
Bases:
_Basic_class
Robot class
This class is for makeing a servo robot with Robot HAT
There are servo initialization, all servo move in specific speed. servo offset and stuff. make it easy to make a robot. All Pi-series robot from SunFounder use this class. Check them out for more details.
PiSloth: https://github.com/sunfounder/pisloth
PiArm: https://github.com/sunfounder/piarm
PiCrawler: https://github.com/sunfounder/picrawler
- move_list = {}¶
Preset actions
- max_dps = 428¶
Servo max Degree Per Second
- __init__(pin_list, db='/root/.config/robot-hat/robot-hat.conf', name=None, init_angles=None, init_order=None, **kwargs)¶
Initialize the robot class
- Parameters
pin_list (list) – list of pin number[0-11]
db (str) – config file path
name (str) – robot name
init_angles (list) – list of initial angles
init_order (list) – list of initialization order(Servos will init one by one in case of sudden huge current, pulling down the power supply voltage. default order is the pin list. in some cases, you need different order, use this parameter to set it.)
- new_list(default_value)¶
Create a list of servo angles with default value
- Parameters
default_value (int or float) – default value of servo angles
- Returns
list of servo angles
- Return type
list
- servo_write_raw(angle_list)¶
Set servo angles to specific raw angles
- Parameters
angle_list (list) – list of servo angles
- servo_write_all(angles)¶
Set servo angles to specific angles with original angle and offset
- Parameters
angles (list) – list of servo angles
- servo_move(targets, speed=50, bpm=None)¶
Move servo to specific angles with speed or bpm
- Parameters
targets (list) – list of servo angles
speed (int or float) – speed of servo move
bpm (int or float) – beats per minute
- do_action(motion_name, step=1, speed=50)¶
Do prefix action with motion_name and step and speed
- Parameters
motion_name (str) – motion
step (int) – step of motion
speed (int or float) – speed of motion
- set_offset(offset_list)¶
Set offset of servo angles
- Parameters
offset_list (list) – list of servo angles
- calibration()¶
Move all servos to home position
- reset()¶
Reset servo to original position