Examples : Conveyor Belt

This document shows how to use Ned’s Conveyor Belt.

If you want to see more about Ned’s Conveyor Belt functions, you can look at the conveyor functions

Danger

If you are using the real robot, make sure the environment around it is clear.

Simple Conveyor control

This short example shows how to connect a conveyor and launch its motor (control it by setting its speed and direction):

 1from pyniryo import NiryoRobot, ConveyorDirection
 2
 3# Connecting to robot
 4robot = NiryoRobot('<robot_ip_address>')
 5
 6# Activating connexion with Conveyor Belt
 7conveyor_id = robot.set_conveyor()
 8
 9# Running the Conveyor Belt at 50% of its maximum speed, in forward direction
10robot.run_conveyor(conveyor_id, speed=50, direction=ConveyorDirection.FORWARD)
11
12# Waiting 3 seconds
13robot.wait(3)
14
15# Stopping robot's motor
16robot.stop_conveyor(conveyor_id)
17
18# Deactivating connexion with the Conveyor Belt
19robot.unset_conveyor(conveyor_id)

Advanced Conveyor Belt control

This example shows how to do a certain amount of pick & place by using the Conveyor Belt with the infrared sensor:

 1from pyniryo import NiryoRobot, PoseObject, PinID, PinState
 2
 3# -- Setting variables
 4sensor_pin_id = PinID.GPIO_1A
 5
 6catch_nb = 5
 7
 8# The pick pose
 9pick_pose = PoseObject(0.25, -0.01, 0.15, 3.14, -0.01, -0.06)
10# The Place pose
11place_pose = PoseObject(0.02, -0.25, 0.1, 3.14, -0.01, -1.47)
12
13# -- MAIN PROGRAM
14
15# Connecting to the robot
16robot = NiryoRobot('<robot_ip_address>')
17
18# Activating connexion with the Conveyor Belt
19conveyor_id = robot.set_conveyor()
20
21for i in range(catch_nb):
22    robot.run_conveyor(conveyor_id)
23    while robot.digital_read(sensor_pin_id) == PinState.LOW:
24        robot.wait(0.1)
25
26    # Stopping robot's motor
27    robot.stop_conveyor(conveyor_id)
28    # Making a pick & place
29    robot.pick_and_place(pick_pose, place_pose)
30
31# Deactivating connexion with the Conveyor Belt
32robot.unset_conveyor(conveyor_id)