Activity 3 Conveyor Belt with Sensor If Statements, Loops and Counters 1 OBJECTIVES: In addition to previous concepts given in previous activities, such as picking and placing an object and recording various robot positions, in this activity the student will be introduced to the following new concepts: Use the conveyor belt and the related sensor. Program the robot to work with the conveyor belt. To pick the object from the conveyor belt and place it in the correct location basing on its size. Use a counter in programming, to place the object in new locations, automatically. 2 ACTIVITY: Initially, the student will learn how to move the conveyor belt manually in both directions at different speeds. On the conveyor three object are placed on different locations. When an abject passes in front of the photoelectric sensor the student will observe that the led at the rear edge of the sensor turns on, indicating that this object is in the detection range of the sensor. Also, as this sensor is connected, virtually in the simulation or actually in the real robot, to the control unit to a given digital input location. The student will notice that the corresponding digital input led turns on, indicating that an input signal/command is being received. After this introduction to the conveyor belt and the sensor, the student will be introduced to the related commands used in the program. Such as moving the conveyor belt, using the if statement in a loop that, when the sensor detects an object, breaks and the program continues with the rest of commands that includes: stopping the conveyor belt, moving the robot to pick the detected object and to place it in a predefined location, and 1 returning it to the initial location waiting for the next object detection in a similar way. In order to repeat the previous procedure for all the objects on the conveyor belt a global loop (jump to command) is used. Also in order to place the next object on the top of the previous one automatically the student will learn how to use a variable (counter), that represents the dynamic location of the new object, that changes its value in each global loop. Note that in the previous procedure the conveyor can be started only just after that robot returns to its initial position after placing the object in its location. The mention if-statement inside the loop programmed to stop the conveyor when the sensor detects an object cannot be activated unless the robot has been stopped. As a result, the conveyor cannot be started unless the robot has been stopped. This represents a deficiency in the program, time is being wasted, as simultaneous activation of the conveyor and the robot cannot be achieved. To solve this time deficiency of the program the student will use input interrupt related commands that enable the activation of both the robot and the conveyor belt simultaneously. In addition, at the end of this activity the student will be requested to program the robot to do picking several objects from the conveyor and placing them in two different locations basing on its size. This task will be explained in more detail at the end of this report. 3 EXPERIMENTAL PROCEDURE: 3.1 Running RoboCell and Opening the Demo 3D model File 1. Turn on the computer. 2. Run RoboCell by doing one of the following: Click Start | Programs | RoboCell for ER 4u | RoboCell for ER 4u. 2 Click on the RoboCell for ER 4u icon. The opening screen appears. Figure (1). RoboCell for ER 4u program window. 3. Open a new project, doing one of the followings: Select File | New Project. Click on the New Project icon. Press [Ctrl] + N. The RoboCell screen now appears as shown Figure (2). 3 Figure (2). RoboCell window after opening a new project. 4. You now need to open a 3D image model for this project. Select File | Import 3D Model. The Import 3D Model dialog box opens. Open the cell RobotWithConveyorAndSensor.3DC (the cell may be any other as provided by yours instructor). A 3D image opens, displaying the SCORBOT-ER 4u robot on a table with 3 cubes placed on a conveyor belt. At the end of the conveyor a photoelectric sensor is mounted. 4 Objects Sensor Conveyor Belt Figure (3). 3D cell model that contains robot, conveyor belt and sensor. You now need to arrange the windows in positions optimal for viewing the 3D Image and teaching/recording positions. Select Window | Simulation & Teach to arrange the windows. 3.2 Conveyor and sensor manual movement 1. Observe that axis # 7 in the Manual Movement window, which corresponds to conveyor axis control. See the next Figure: Conveyor belt axis control Figure (4). Axis #7 (conveyor belt) control buttons. 2. Also open the dialog input dialog bar from View | Dialog Bars | Digital Inputs. 5 3. Move the conveyor right/left by clicking on 7/U, shown in Figure (6), manually. When an object reaches the sensor the rear led illuminates and also does the corresponding digital input. See the figure: Figure (5). The sensor detects an object, hence input #1 turns on. 3.3 Conveyor and sensor related program commands 3.3.1 Conveyor belt commands: The main programming commands related to the conveyor belt are the following: 1. Starting and Stopping the conveyor: In the Workspace | Commands window go to AXIS CONTROL | StartConveyor... or StopConveyor... These commands open the following windows, respectively: 6 In both figures the axis represents to which control axis in the control unit the conveyor belt is connected. Note that two axes in the control unit are available: axis #7 and axis #8. Here, in this experiment the conveyor is connected through axis #7. Also, as appears in the figure on the left, the student can select the direction and the speed at which the conveyor moves. After clicking OK on any of the previous figures, the following commands appear in the program window 2. Using the sensor signal/input in the program: a. Using simple if statement inside a loop, as done in the previous activity (Activity #2) with inputs from the I/O table. When the sensor is activated (an object is detected by the sensor) the if statement jumps the execution to a given label out of the loop. This can be summarized by the following sequence of commands: Here, in this activity, the sensor is connected to input #1. 7 b. Using Input Interrupt commands. This method can be applied without the need of a loop. Note that in the previous method the program is waiting the termination of the loop, i.e. one cannot apply any other command, like moving the robot, while it is checking the signal from the sensor. While in this method, the program continues with the rest of commands, and when the sensor detects an object the conveyor stops, without affecting other commands that are being executed at this instant. The related commands are the following: - EnableInterrupt#_... & DisableInterrupt#_...: this command enables the receive of signals/input command from the corresponding sensor, when is double-clicked: Note that (1) is the input # of the control unit to which the sensor is connected, see Figure (5). 8 3.3.2 Using a counter in the program The objective of a counter in this activity is to place the object in a new location different than the previous location automatically. Like, appending cubes one on the top of the other, automatically. 3.4 Recording Positions 3. Move the robot to the positions shown in Figure (6) and record them. 1 2 4 3 6 8 7 9 5 Figure (6). 3D cell model after rearranging program windows. 4. Make sure that positions (2, 4, 6& 8) are on the same level (z-axis), do the same for positions (7 & 9) and (3 & 5). 5. For more information about recording positions, refer to Activity 1 document. 3.5 The I/O experimental table environment 1. Open the Digital Inputs/ Digital Outputs from: View | Dialog Bars | Digital Inputs View | Dialog Bars | Digital Outputs 9 Figure (7). Digital Inputs/Digital Outputs Window opening. The following windows appear on the bottom of the program: 3.6 (Outputs of the I/O table): 1. Move the cube to position 7 or 9 Digital Input number 2 or 1 will be on respectively. This indicates that the corresponding sensor has been activated. 10 2. In the Workspace | Commands window go to INPUTS & OUTPUTS | TurnOnOutput#_... and double click on it. The following window appears: 11 Output Number to be activated Activate == on Deactivate == off In this Cell, Output number 1 is connected to the Light. And Output number 2 is connected to the buzzer. 3. After selecting the desired output the following command will be added to the program file: 3.7 Use input signals from the I/O tables 1. The principal command used to determine the state of a given sensor (on/off) is the IfInput#_OnJump in Workspace | Commands window go to INPUTS & OUTPUTS | IfInput#_OnJump 12 2. Double-click this command the following window opens: 3. Select the number of the input desired to be measured and in the Jump to Label write the label that corresponds to the commands related to the activity of this sensor. Refer to Activity 1 form more information about how to create a label. 4. After inserting the previous command it appears in the program window as follow: 3.8 Using if statement and loop to wait for signal from a given sensor: 13 1. In order to wait for a sensor to be activated a loop must be constructed using the JumpTo… command from Workspace | Commands window | PROGRAM FLOW | IfJump as introduced in Activity 1. 2. In the loop it is recommended to use the Wait… command in order to lower the number of times this loop is being executed. This affects the CPU usage. 3. See the previous Figure for the final contents of the if statement and the loop. After this introduction the student should be able to program the task assigned by his instructor. 14