Note
Before following these instructions, make sure the Conveyor Belt (v2) and the IR sensor are connected as detailed in the corresponding section (see Electrical interface).
With Niryo Studio
You can have all the details about the application in Niryo Studio’s documentation.
Niryo Studio - The Conveyor Belt (v2) (v2)
In Niryo Studio, open the Conveyor Belt (v2) tab in the left menu. The interface will let you control up to two Conveyors directly. You can enable them and control their speed and direction.
Hint
Click on Scan to detect and add the connected Conveyor Belt (v2) to Niryo Studio.
To use a single Conveyor Belt, connect the product to Ned and toggle the button of the “Conveyor Belt (v2) 1” in Niryo Studio. You can now adjust the speed by using the slider or entering the percentage value and choosing if the Conveyor Belt (v2) has to move forward or backward.
To use two Conveyor Belts, follow the steps detailed in the previous paragraph, then, on the “Set Conveyor Belt (v2) ID” section of Niryo Studio, select “Conveyor Belt (v2) 2” and click “Update”. Now, connect your second Conveyor Belt (v2) to Ned, which will be considered as “Conveyor Belt (v2) 1”. Please note that the ID are saved until you disconnect the Conveyors. These steps are required each time you reconnect two Conveyors.
Niryo Studio - IR sensor
Connect your sensor on IR-Sensor connector on the back panel of the robot. In Niryo Studio, in the “Digital I/O panel”, you can read the IR-Sensor state in DI5 pin:
When the distance measured is smaller than the adjusted distance, the “INPUT” is “LOW”, it means an obstacle is detected.
When the distance measured is higher than the adjusted distance, the “INPUT” is “HIGH”, it means that there is no obstacle.
Blockly
Special blocks have been designed to be used with the Conveyor (v2). These blocks keep Ned’s Ecosystem easy to use with Niryo Studio.
Images |
Description |
---|---|
Allows the user to choose the Conveyor’s ID |
|
Allows the Conveyor Belt (v2) (v2) to be controlled via Ned |
|
This block will control the Conveyor Belt (v2) (v2):
|
|
This block stops the Conveyor Belt |
With the Control Box
With PyNiryo
Here are provided two scripts for the Conveyor Belt (v2) and the IR sensor. You can find more details in PyNiryo’s Documentation.
PyNiryo - The Conveyor Belt
Here is a code example showing how to scan the connected Conveyor Belt (v2) and launch its motor:
#!/usr/bin/env python
from pyniryo import *
# Connecting to robot
robot = NiryoRobot(<robot_ip_address>)
# Activating connexion with Conveyor Belt
conveyor_id = robot.set_conveyor()
# Running the Conveyor Belt (v2) at 50% of its maximum speed, in forward direction
robot.run_conveyor(conveyor_id, speed=50, direction=ConveyorDirection.FORWARD)
# Waiting 3 seconds
robot.wait(3)
# Stopping conveyor's motor
robot.stop_conveyor(conveyor_id)
# Deactivating connexion with the Conveyor Belt
robot.unset_conveyor(conveyor_id)
PyNiryo - IR sensor
You can get the IR sensor state and control the Conveyor Belt (v2) accordingly as follows. Please note that, in this example, the sensor is connected to the GPIO_1A.
#!/usr/bin/env python
from pyniryo import *
# Connecting to the robot
robot = NiryoRobot(<robot_ip_address>)
# Activating connexion with the Conveyor Belt
conveyor_id = robot.set_conveyor()
# -- Setting variables
sensor_pin_id = PinID.GPIO_1A
# Run conveyor and wait until the IR sensor detects an object
robot.run_conveyor(conveyor_id)
while robot.digital_read(sensor_pin_id) == PinState.LOW:
robot.wait(0.1)
# Stopping conveyor's motor
robot.stop_conveyor(conveyor_id)
# Deactivating connexion with the Conveyor Belt
robot.unset_conveyor(conveyor_id)
With Modbus
More details about how to use Modbus with Ned and the Conveyor Belt (v2) can be found in our Modbus documentation.
Modbus - The Conveyor Belt
Here is a python code example that shows how to control the Conveyor Belt (v2) through a Modbus TCP Client:
#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient
import time
# Connect to the robot
client = ModbusTcpClient('<robot_ip_address>', port=5020)
client.connect()
# Enable Conveyor 1
client.write_register(520, 1)
time.sleep(1)
# Set direction to forward
client.write_register(523, 1)
time.sleep(1)
# Set speed to 50%
client.write_register(524, 50)
time.sleep(1)
# Start conveyor 1
client.write_register(522, 1)
time.sleep(10)
# Stop conveyor 1
client.write_register(526, 1)
# Close connection to modbus server
client.close()
Modbus - IR sensor
Here is how you can set the digital IO connected to the IR sensor to Input mode and get its state:
#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient
# Connect to the robot
client = ModbusTcpClient('<robot_ip_address>', port=5020)
client.connect()
# Set digital IO mode - input on GPIO_1A
client.write_coil(0, True)
# Read digital IO state. 1 = High, 0 = Low
ir_state = client.read_discrete_inputs(100, count = 1)
print 'IR sensor state is :', ir_state.bits
# Close connection to modbus server
client.close()
With Python ROS Wrapper
More details about how to use the Python ROS Wrapper with Ned and the Convevor Belt (v2) can be found our ROS wrapper documentation.
Important
If you are using a physical Ned and you don’t want to write the following code directly on the robot, you will need to setup a multi-machines environment, following this tutorial. On the other hand, you can directly use PyNiryo following the With PyNiryo section.
Python ROS Wrapper - The Conveyor Belt
Here is a code example on how to control the Conveyor through the Python ROS Wrapper:
#!/usr/bin/env python
# Imports
from niryo_robot_python_ros_wrapper import *
import rospy
niryo_robot = NiryoRosWrapper()
# Activating connexion with conveyor and storing ID
conveyor_id = niryo_robot.set_conveyor()
# Running conveyor at 50% of its maximum speed, in Forward direction
niryo_robot.control_conveyor(conveyor_id, True, 100, ConveyorDirection.FORWARD)
# Stopping conveyor's motor
niryo_robot.control_conveyor(conveyor_id, True, 0, ConveyorDirection.FORWARD)
# Deactivating connexion with conveyor
niryo_robot.unset_conveyor(conveyor_id)
Python ROS Wrapper - IR sensor
You can get the IR sensor state and control the Conveyor Belt (v2) accordingly as follows. Here, the Conveyor Belt (v2) is connected to the GPIO_1A.
#!/usr/bin/env python
# Imports
from niryo_robot_python_ros_wrapper import *
import rospy
def run_conveyor(robot, conveyor):
robot.control_conveyor(conveyor, bool_control_on=True,
speed=50, direction=ConveyorDirection.FORWARD)
# -- Setting variables
sensor_pin_id = PinID.GPIO_1A
niryo_robot = NiryoRosWrapper()
# Activating connexion with conveyor
conveyor_id = niryo_robot.set_conveyor()
# Run conveyor and wait until the IR sensor detects an object
run_conveyor(niryo_robot, conveyor_id)
while niryo_robot.digital_read(sensor_pin_id) == PinState.LOW:
niryo_robot.wait(0.1)
# Stopping conveyor's motor
niryo_robot.control_conveyor(conveyor_id, True, 0, ConveyorDirection.FORWARD)
# Deactivating connexion with conveyor
niryo_robot.unset_conveyor(conveyor_id)