simplecode

Conveyor Control

2 posts in this topic

Hi everyone, I'm newbie at here.I need to help.Can you share your experience to me?
the scheme is as at picture.

https://imgyukle.com/i/R4JDWM

the robot is palletizing at conveyor 1 and then send to me palletcompletedbit. After, ı must move this pallet to conveyor 2 with plc code.Also my customer want to run conveyors manually via buttons.

My code is :
 

timer_conv2empty(in:=,pt:=t#20s);

	CASE MachineMode OF
	Man:
	StateAuto:=0;
	StateConv1:=0;
	StateConv2:=0;

		IF AlarmStatus THEN
		StateMan:=99;
		END_IF
		IF StateMan=0 AND bttnMode_RTRIG.Q THEN
		MachineMode:=Auto;
		END_IF

		CASE StateMan OF
		0: (*Manual control*)
			IF bttnConveyor1 THEN
				IF NOT in_Sensor1 THEN
				out_Conveyor1:=TRUE;
				ELSE
				out_Conveyor1:=FALSE;
				END_IF
			END_IF

			IF bttnConveyor2 THEN
				IF NOT in_Sensor2 THEN
				out_Conveyor2:=TRUE;
				ELSE
				out_Conveyor2:=FALSE;
				END_IF
			END_IF
			
			IF bttnConveyorTransfer THEN
				IF NOT in_Sensor2 THEN
				out_Conveyor1:=TRUE;
				out_Conveyor2:=TRUE;
				ELSE
				out_Conveyor1:=FALSE;
				out_Conveyor2:=FALSE;
				END_IF
			END_IF
			
			IF NOT bttnConveyor1 AND NOT bttnConveyorTransfer THEN
			out_Conveyor1:=FALSE;
			END_IF

			IF NOT bttnConveyor2 AND NOT bttnConveyorTransfer THEN
			out_Conveyor2:=FALSE;
			END_IF
		99: (*Alarm*)
		out_Conveyor1:=FALSE;
		out_Conveyor2:=FALSE;
			IF NOT AlarmStatus THEN
			StateMan:=0;
			END_IF
		END_IF	
		END_CASE;
	Auto:
	StateMan:=0;

		IF AlarmStatus THEN
		StateMan:=99;
		END_IF
		IF (StateAuto=0 OR StateAuto=99) AND bttnMode_RTRIG.Q THEN
		MachineMode:=Man;
		END_IF

		CASE StateAuto OF
		0: (*Stop*)
		out_Conveyor1:=FALSE;
		out_Conveyor2:=FALSE;
			IF in_StartButton_RTRIG.Q THEN
			StateAuto:=1;
			END_IF
		1: (*Running*)
			IF in_StopButton_RTRIG.Q THEN
			StateAuto:=0;
			END_IF
			
				CASE StateConv1 OF 
				0: (*initial*)
				out_Conveyor1:=FALSE;
					IF NOT in_Sensor1 THEN
					StateConv1:=1;
					ELSE
					StateConv1:=2;
					END_IF
				1: (*conveyor empty*)
				  IF palletcompletedbit THEN
				  out_Conveyor1:=TRUE;
				  ELSE
				  out_Conveyor1:=FALSE;
			          END_IF
				
				  IF out_Conveyor1 AND in_Sensor1 THEN
				  StateConv1:=2;
				  END_IF
				2: (*conveyor loaded*)
				  IF StateConv2=1 THEN
				  out_Conveyor1:=TRUE;
				  ELSE
				  out_Conveyor1:=FALSE;
			          END_IF
			
				   IF NOT in_Sensor1 AND in_Sensor2 THEN
				   StateConv1:=1;
				   END_IF
				END_CASE;

				CASE StateConv2 OF 
				0: (*initial*)
				out_Conveyor2:=FALSE;
					IF NOT in_Sensor2 THEN
					StateConv2:=1;
					ELSE
					StateConv2:=2;
					END_IF
				1: (*conveyor empty*)
				  IF StateConv2=2 THEN
				  out_Conveyor2:=TRUE;
				  ELSE
				  out_Conveyor2:=FALSE;
			          END_IF
				
				  IF out_Conveyor2 AND in_Sensor2 THEN
				  StateConv2:=2;
				  END_IF
				2: (*conveyor loaded*)
				  timer_conv2empty.IN:=NOT in_Sensor2 ;
				  IF timer_conv2empty.Q THEN
				  StateConv2:=1;
				  END_IF
				END_CASE;

			
		99: (*Alarm*)
		out_Conveyor1:=FALSE;
		out_Conveyor2:=FALSE;
			IF NOT AlarmStatus THEN
			StateAuto:=0;
			END_IF
		END_CASE;
	END_CASE;

What should I do if the pallet stays between the sensors?
What should I do if the sensors are triggered incorrectly?

thank you for reply

Share this post


Link to post
Share on other sites
On 5/21/2022 at 1:45 PM, simplecode said:

What should I do if the pallet stays between the sensors?
What should I do if the sensors are triggered incorrectly?
 

 

actually that is something you or our client should define. we do not know how your system is supposed to operate. 

btw i do not see any conditioning of the inputs so button press would yield random outcome depending on duration of the press. to make things work the way you want, you need to create one shot logic for each of the buttons.

for example consider this part:

            IF bttnConveyor1 THEN
                IF NOT in_Sensor1 THEN
                out_Conveyor1:=TRUE;
                ELSE
                out_Conveyor1:=FALSE;
                END_IF
            END_IF

or just

            IF bttnConveyor1 THEN
               // do something
            END_IF

consider what happens when "do something" is executed without control. for example replace it with variable increment

            IF bttnConveyor1 THEN
              myCounter := myCounter + 1; // do something
            END_IF

this should probably be rewritten into something like this:

            IF bttnConveyor1 THEN
                IF NOT bttnConveyor1_was_pressed THEN
                    myCounter:=myCounter+1;  // do something
                END_IF
            END_IF
            bttnConveyor1_was_pressed := bttnConveyor1; 

the additional static variable ("bttnConveyor1_was_pressed") was simply used to keep record of the past button state and sense the signal edge. in this example rising edge of button press was sensed and used to perform some action ONCE per button press.

 

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now