.. |br| raw:: html
|br| .. note:: Before following the following instructions, make sure **the Conveyor Belt and the IR sensor are connected as detailed** in the corresponding section (see :doc:`/source/setup`). With Niryo Studio ------------------------------------------- You can have all the details about the application in `Niryo Studio's documentation. `_ Niryo Studio - The Conveyor Belt ############################################ In Niryo Studio, open the Conveyor Belt 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 to Niryo Studio. **To use a single Conveyor Belt**, connect the product to Ned and toggle the button of the “Conveyor Belt 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 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 ID” section of Niryo Studio, select “Conveyor Belt 2” and click “Update”. Now, connect your second Conveyor Belt to Ned, which will be considered as “Conveyor Belt 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 ############################################ In Niryo Studio, in the “Digital I/O panel”, make the following change: - **If you connected the Sensor on the A** connection in the previous section, change the mode of “1A” to “INPUT”. - **If you connected the Sensor on the B** connection in the previous section, change the mode of “2A” to “INPUT”. 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 Belt. These blocks keep Ned's Ecosystem easy to use with Niryo Studio. .. list-table:: :header-rows: 1 :widths: 40 60 :align: center :class: blockly-table * - Images - Description * - .. image:: ../images/Blockly_conveyor_1.png :align: center - Allows the user to choose the Conveyor ID * - .. image:: ../images/Blockly_conveyor_2.png :align: center - Allows the Conveyor Belt to be controlled via Ned * - .. image:: ../images/Blockly_conveyor_3.png :align: center - This block will control the Conveyor Belt: - With the ID (1 or 2), - With the speed (from 0 to 100%), - With the direction (FORWARD and BACKWARD) * - .. image:: ../images/Blockly_conveyor_4.png :align: center - This block stops the Conveyor Belt With the Control Box ------------------------------------------- .. raw:: html .. list-table:: :widths: auto :align: center :class: rotary-table * - .. image:: ../images/potentiometer.png :width: 150px :align: center :class: left-image-float - The rotary potentiometer allows you to control the speed and the direction of the Conveyor Belt. When the potentiometer is at its origin, centered, the Conveyor Belt is stopped. The more you turn the potentiometer clockwise, the fastest the Conveyor Belt will move forward. Conversely, the more you turn the potentiometer counterclockwise, the fastest the Conveyor Belt will move backward. With PyNiryo ------------------------------------------- Here are provided two scripts for the Conveyor Belt 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 and launch its motor: .. code:: python #!/usr/bin/env python from pyniryo import * # Connecting to robot robot = NiryoRobot() # Activating connexion with Conveyor Belt conveyor_id = robot.set_conveyor() # Running the Conveyor Belt 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 accordingly as follows. Please note that, in this example, the sensor is connected to the GPIO_1A. .. code:: python #!/usr/bin/env python from pyniryo import * # Connecting to the robot robot = NiryoRobot() # 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 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 through a Modbus TCP Client: .. code:: python #!/usr/bin/env python from pymodbus.client.sync import ModbusTcpClient import time # Connect to the robot client = ModbusTcpClient('', 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: .. code:: python #!/usr/bin/env python from pymodbus.client.sync import ModbusTcpClient # Connect to the robot client = ModbusTcpClient('', 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 can be found `our ROS wrapper documentation. `_ .. important:: If you are **using Ned in real** 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 :ref:`source/how_to_use:With PyNiryo` section. Python ROS Wrapper - The Conveyor Belt ############################################ Here is a code example on how to control the Conveyor through a the Python ROS Wrapper: .. code:: python #!/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 accordingly as follows. Here, the Conveyor Belt is connected to the GPIO_1A. .. code:: python #!/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)