Camera Self Driving
Instance declaration
When you add a Camera Self Driving block to the workspace, the following instance declaration is automatically inserted into the Python code:
python
self_driving = SelfDriving(0)
# When there are multiple instances
self_driving_1 = SelfDriving(1)Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| index | Dropdown option | Instance number (starting from 0) | Integer 0 or greater | 0 |
Select the camera device
Sets the camera to use for camera self driving.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Camera device name | System camera label | - |
Python
python
self_driving = SelfDriving(0)
self_driving.device('')Set the lane colors
Sets the color of the left and right lanes.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| left | Dropdown option | Left lane color | red, green, blue | - |
| right | Dropdown option | Right lane color | red, green, blue | - |
Python
python
self_driving = SelfDriving(0)
self_driving.set_lane('green', 'blue')Detect once
Finds the selected colors/lanes on the screen and marks their regions just once.

Parameters
(none)
Python
python
self_driving = SelfDriving(0)
self_driving.detect_once()Start / stop continuous detection
Keeps following the screen for the selected colors/lanes and marks their regions on the screen.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Action | start, stop | - |
Python
python
self_driving = SelfDriving(0)
# unit = "start"
self_driving.detect_continuous()
# unit = "stop"
self_driving.stop()Show the detection result
Decides whether or not to show the color/lane detection result on the camera screen.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| on | Dropdown option | Display ON / OFF | show (on=True), hide (off=False) | TRUE |
Python
python
self_driving = SelfDriving(0)
self_driving.display(True)
self_driving.display(False)Lane data
Returns the position or distance value of the specified lane.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| lane | Dropdown option | Lane | left, right | - |
| unit | Dropdown option | Kind of measurement | x, distance | - |
Python
python
self_driving = SelfDriving(0)
self_driving.lane('left', 'x')
self_driving.lane('right', 'distance')Color data
Returns the position/size values of the specified color.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| color | Dropdown option | Color name | red, green, blue | - |
| unit | Dropdown option | Kind of coordinate/size | x, y, min_x, max_x, min_y, max_y, width, height, area | - |
Python
python
self_driving = SelfDriving(0)
self_driving.color('red', 'x')
self_driving.color('green', 'y')
self_driving.color('blue', 'area')Distance between two colors
Returns the distance between two colors.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit1 | Dropdown option | First color | red, green, blue | - |
| unit2 | Dropdown option | Second color | red, green, blue | - |
| type | Dropdown option | Kind of distance | distance (omitted or None), horizontal distance (horizontal), vertical distance (vertical) | None |
Python
python
self_driving = SelfDriving(0)
self_driving.get_distance('red', 'blue') # distance
self_driving.get_distance('green', 'blue', 'horizontal') # horizontal distanceWhether a lane was detected
Whether a particular lane was found

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| lane | Dropdown option | Lane | left, right, both, any | any |
Python
python
self_driving = SelfDriving(0)
self_driving.lane_detected('left')Whether a color was detected
Whether a particular color region was found

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| color | Dropdown option | Color name | red, green, blue, any | any |
Python
python
self_driving = SelfDriving(0)
self_driving.color_detected('red')