
(* 5x2 flyways 9 xbots (y axis feedback must be enabled) - StreamModeCtrl,WriteStream,ConfigFBStream,read feedback *)
FUNCTION_BLOCK Example22_stream
	IF Execute = FALSE THEN
		(*reset streaming positions*)
		y_pos := 0;
		FOR xindex := 1 TO 10 DO
			PMC_WriteStream1(PM_Controller := PM_Controller,Enable := TRUE,StmID := xindex,AxisID := 1,Pos := 0);
			PMC_WriteStream1(PM_Controller := PM_Controller,Enable := TRUE,StmID := xindex,AxisID := 2,Pos := 0);
			PMC_WriteStream1(PM_Controller := PM_Controller,Enable := TRUE,StmID := xindex,AxisID := 3,Pos := 0);
			PMC_WriteStream1(PM_Controller := PM_Controller,Enable := TRUE,StmID := xindex,AxisID := 4,Pos := 0);
			PMC_WriteStream1(PM_Controller := PM_Controller,Enable := TRUE,StmID := xindex,AxisID := 5,Pos := 0);
			PMC_WriteStream1(PM_Controller := PM_Controller,Enable := TRUE,StmID := xindex,AxisID := 6,Pos := 0);
		END_FOR;
	END_IF;

	(*Stop all xbots*)
	PMC_StopXbots1(PM_Controller := PM_Controller,Execute := Execute,XbotID := 0);

	(*move all xbots to bottom of flyways*)
	xbotID_array78[0] := 1; xbotID_array78[1] := 2; xbotID_array78[2] := 3; xbotID_array78[3] := 4; xbotID_array78[4] := 5; xbotID_array78[5] := 6; xbotID_array78[6] := 7; xbotID_array78[7] := 8; xbotID_array78[8] := 9;
	posx_array78[0] := 0.06;posx_array78[1] := 0.18;posx_array78[2] := 0.30;posx_array78[3] := 0.42;posx_array78[4] := 0.54;posx_array78[5] := 0.66;posx_array78[6] := 0.78;posx_array78[7] := 0.90;posx_array78[8] := 1.02;
	posy_array78[0] := 0.06;posy_array78[1] := 0.06;posy_array78[2] := 0.06;posy_array78[3] := 0.06;posy_array78[4] := 0.06;posy_array78[5] := 0.06;posy_array78[6] := 0.06;posy_array78[7] := 0.06;posy_array78[8] := 0.06;
	PMC_AutoDrivingMotion1(PM_Controller := PM_Controller,Execute := PMC_StopXbots1.Done,nXbots := 9,RoutingType := 0,ZoneID := 0,XbotID := xbotID_array78,PosX := posx_array78,PosY := posy_array78);

	(*config feedback stream of xbot 1*)
	StmID_array8[0] := 1;
	XbotID_array8[0] := 1;
	FBmode_array8[0] := 0;
	PMC_ConfigFBStream1(PM_Controller := PM_Controller,Execute := PMC_AutoDrivingMotion1.Done,nStm := 1,StmID := StmID_array8,XbotID := XbotID_array8,FBMode := FBmode_array8);

	(*config streaming control for all 9 xbot's y axis*)
	xbotID_array9[0] := 1;xbotID_array9[1] := 2;xbotID_array9[2] := 3;xbotID_array9[3] := 4;xbotID_array9[4] := 5;xbotID_array9[5] := 6;xbotID_array9[6] := 7;xbotID_array9[7] := 8;xbotID_array9[8] := 9;
	stmID_array9[0] := 1; stmID_array9[1] := 2; stmID_array9[2] := 3; stmID_array9[3] := 4; stmID_array9[4] := 5; stmID_array9[5] := 6; stmID_array9[6] := 7; stmID_array9[7] := 8; stmID_array9[8] := 9; 
	stmAxis_array9[0] :=2;stmAxis_array9[1] :=2;stmAxis_array9[2] :=2;stmAxis_array9[3] :=2;stmAxis_array9[4] :=2;stmAxis_array9[5] :=2;stmAxis_array9[6] :=2;stmAxis_array9[7] :=2;stmAxis_array9[8] :=2;
	PMC_StreamModeCtrl1(PM_Controller := PM_Controller,Execute := PMC_ConfigFBStream1.Done,Level := 1,nXbots := 9,XbotID := xbotID_array9,StmID := stmID_array9,StmAxis := stmAxis_array9);

	(*slowly move all xbots to top of flyways *)
	IF(PMC_StreamModeCtrl1.Done = TRUE AND y_pos < 0.36)THEN
		PMC_ReadStreamFeedback1(PM_Controller := PM_Controller,Enable := TRUE,StreamChannelID := 1,XBotAxisID := 2);
		read_y_pos := PMC_ReadStreamFeedback1.FeedbackValue;
		y_pos := y_pos + 0.00001;
		FOR xindex := 1 TO 10 DO
			PMC_WriteStream1(PM_Controller := PM_Controller,Enable := TRUE,StmID := xindex,AxisID := 2,Pos := y_pos);
		END_FOR; 
	END_IF;
	
	(*stop streaming on all xbots*)
	PMC_StreamModeCtrl2(PM_Controller := PM_Controller,Execute := PMC_StreamModeCtrl1.Done = TRUE AND y_pos >= 0.36,Level := 0,nXbots := 10,XbotID := xbotID_array9,StmID := stmID_array9,StmAxis := stmAxis_array9);

	Done := PMC_StreamModeCtrl2.Done;
END_FUNCTION_BLOCK
