Examples: Conveyor Belt
This document shows how to use Ned robot’s Conveyor Belt.
Simple Conveyor Belt control
This short example shows how to setup a connected conveyor belt and how to control it:
1#!/usr/bin/env python3
2
3from niryo_robot_python_ros_wrapper import NiryoRosWrapper, ConveyorDirection
4
5# Instantiate the ROS wrapper and initialize the ROS node
6robot = NiryoRosWrapper.init_with_node()
7
8# Setup the conveyor and get its ID on the TTL bus
9conveyor_id = robot.set_conveyor()
10
11# Running conveyor at 50% of its maximum speed, in backward direction
12robot.control_conveyor(conveyor_id, bool_control_on=True, speed=50, direction=ConveyorDirection.BACKWARD)
13
14robot.wait(2.0)
15
16# Running conveyor at 50% of its maximum speed, in forward direction
17robot.control_conveyor(conveyor_id, bool_control_on=True, speed=50, direction=ConveyorDirection.FORWARD)
18
19robot.wait(2.0)
20
21# Stop the conveyor
22robot.control_conveyor(conveyor_id, bool_control_on=True, speed=0, direction=ConveyorDirection.FORWARD)
23
24# Deactivate the conveyor
25robot.unset_conveyor(conveyor_id)
Advanced Conveyor Belt control
This example shows how to pick & place an object detected by an IR sensor mounted on the conveyor belt:
1#!/usr/bin/env python3
2
3from niryo_robot_python_ros_wrapper import NiryoRosWrapper, Pose, ConveyorDirection, PinID, PinState
4
5import math
6
7# -- Setting variables
8SENSOR_PIN_ID = PinID.DI5 # Use the PinID used by your IR sensor (DI5 is the default one of the back panel)
9pick_pose = Pose(0.25, 0.14, 0.15, math.pi, 0.0, 0.0) # Change to use meaningful values for your pick and place poses
10place_pose = Pose(0.25, -0.14, 0.15, math.pi, 0.0, 0.0)
11
12if __name__ == "__main__":
13
14 # Instantiate the ROS wrapper and initialize the ROS node
15 robot = NiryoRosWrapper.init_with_node()
16
17 # Setup the conveyor and get its ID on the TTL bus
18 conveyor_id = robot.set_conveyor()
19
20 robot.control_conveyor(conveyor_id, bool_control_on=True, speed=50, direction=ConveyorDirection.FORWARD)
21
22 # Wait until an object is detected by the sensor
23 while robot.digital_read(SENSOR_PIN_ID) == PinState.HIGH:
24 robot.wait(0.1)
25
26 # Stop the conveyor
27 robot.control_conveyor(conveyor_id, True, 0, ConveyorDirection.FORWARD)
28
29 # Pick & place
30 robot.pick_and_place(pick_pose, place_pose)
31
32 # Deactivate the conveyor
33 robot.unset_conveyor(conveyor_id)