pyzenbo.modules.line_follower module

class pyzenbo.modules.line_follower.LineFollowerConfig

Bases: object

COLOR = {'BLACK': 0, 'BLUE': 5, 'GREEN': 4, 'RED': 2, 'UNKNOWN': -1, 'WHITE': 1, 'YELLOW': 3}
BEHAVIOR = {'CROSSROAD_LEFT': 5, 'CROSSROAD_RIGHT': 6, 'CURVE': 9, 'FORKED_LEFT': 3, 'FORKED_RIGHT': 4, 'NOTHING': 0, 'ROTATION': 8, 'SPEED_LEVEL': 7, 'TERMINATE': 1, 'UNKNOWN': -1, 'U_TURN': 2}
SPEED = {'L1': 1, 'L2': 2, 'L3': 3}
add_rule(color, behavior, *args)

Change the configuration of line following.

Parameters
  • color – COLOR.BLACK can only support the settings of BEHAVIOR.SPEED_LEVEL

  • behavior – The default settings of the configuration is BEHAVIOR.NOTHING. Can’t change the setting of BEHAVIOR.UNKNOWN

  • args – The settings of BEHAVIOR.SPEED_LEVEL and BEHAVIOR.ROTATION require third parameter, BEHAVIOR.SPEED_LEVEL require SPEED. The settings of BEHAVIOR.ROTATION require inputting rotational angle (in degree)

Returns

Return error_code.NO_ERROR if successfully change the settings. Otherwise, it will return a certain error code.

remove_rule(color)

Remove the settings of specific color.

Parameters

color – specific color

get_rule(color)

Return the settings of specific color.

Parameters

color – specific color

Returns

Return color rule for specific color. Otherwise, it will return None if the color doesn’t have any settings.

get_rule_list()

Get the configuration list.

Returns

Return a new configuration list, which is a shallow copy of the old one

build()

Returns a string that representing the configuration.

:return:a JSON string that representing the configuration

class pyzenbo.modules.line_follower.LineFollower(inter_comm)

Bases: object

calibrate(reset=False, sync=True, timeout=None)

Run calibration for line sensor.

Parameters
  • reset – True for reset to default RGB value

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

demo(sync=False, timeout=None)

Start line following with default configuration patterns. Default pattern config as bellow: G-R-G: stop, B-R-B: turn left, B-G-B: turn right, G-B-G: turn around, R-G-R: go straight, R-B-R: speed up, G-R-B: slow down, B-R-G: normal speed

Parameters
  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

get_color(sync=True, timeout=None)

Return RGB values in order to get which color it is (Black, White, Red, Green, Blue, Yellow) RGB values will be returned as JSON string of onResult() with the bundle key of “Color_Result”.

Parameters
  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

follow_line(json_string=None, sync=True, timeout=None)

Start line following by using customize configuration. If line color or pattern is changed, result will be returned in JSON string of with the bundle key Color_Result” and “Pattern_Result”.

Parameters
  • json_string – configuration in JSON string type, can build by LineFollowerConfig

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

update_config(serial, json_string, sync=True, timeout=None)

Update configuration during line following.

Parameters
  • serial – The serial number during line following

  • json_string – configuration in JSON string type, can build by LineFollowerConfig

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code

set_behavior(serial, behavior, arg=None, sync=True, timeout=None)

Set behavior immediately during line following.

Parameters
  • serial – The serial number during line following

  • behavior – The default settings of the configuration is BEHAVIOR.NOTHING, Can’t change the setting of BEHAVIOR.UNKNOWN

  • arg – The settings of BEHAVIOR.SPEED_LEVEL and BEHAVIOR.ROTATION The settings of BEHAVIOR.SPEED_LEVEL require third parameter SPEED and the settings of BEHAVIOR.ROTATION requires inputting rotational angle (in degree).

  • sync – True if this command is blocking

  • timeout – maximum blocking time in second, None means infinity

Returns

serial number of the command, if command is blocking also return a dict, it include two key, ‘state’ indicate execute result and ‘error’ will contain error code