Nirtec Studio Forum

General Category => Machines Simulator => Topic started by: pablo.martinez garcia on January 17, 2023, 07:50:12 PM

Title: Custom Workpart
Post by: pablo.martinez garcia on January 17, 2023, 07:50:12 PM
Hi!
I have been programming with the default workparts for several days, I would be very interested in being able to create my own objects to move them.
I created a cage but it doesn't interact with conveyors.

Regards! ;D
Title: Re: Custom Workpart
Post by: EasyPLC_Master on January 17, 2023, 08:18:56 PM
You can customize the WorkParts in several ways:
-Modify the scale, shape, texture and model

or you can create a User Defined Component with complex shapes and use it as a WorkPart in the WorkPartCreator. In this case you must use Dynamic Components in order to be affected by the gravity and physics forces.
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 18, 2023, 05:53:37 PM
So, then i can create a custom model and import as a model of workpart? have u any tutorial how to use dynamic components? Thanks!
Title: Re: Custom Workpart
Post by: EasyPLC_Master on January 18, 2023, 06:03:23 PM
Yes, of course! all the components that have the model property can be assigned to a custom model imported in .obj format and copied on the (Installation folder) \Machines Simulator 3\ms3bin_Data\StreamingAssets\ path.

This is explained in the Machines Simulator Instruction Guide.pdf (Appendix section).

Here you can see an example: https://youtu.be/05byHkSB8M8 (https://youtu.be/05byHkSB8M8)

The dynamic components are very easy to use, they are like a Static Component but it is affected for the gravity and forces.
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 19, 2023, 04:18:44 PM
Alright, I might have expressed myself poorly. I have read the manual and I have several questions since I am new to this.
Regarding the WorkParts, for example, I have created a UCD of a cage, and that is what I would like to be a Workpart, not so much importing a 3D model. Basically, I would like it to move on conveyors.

The second question has to do with the movement from a PLC signal properly in a UCD. I am creating a magnetic plate from zero with the components that brings Machines simulator. (when I finish it, I will upload it for others to enjoy) and I need to move it right/left or up/down until I see for example a detector, not so much with axis absolute positions. I have tried to do it with the Graph code but I only move it to one position.

If I update the position,  I must turn off and turn on the bool signal that gives it the action movement. My question is, how could I send movement in the X axis for example continuously while a PLC signal is active? My intention is to program it in TIA Portal so maybe the Graph is not the most convenient.

Greetings and thanks for your time ;)
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 19, 2023, 04:28:31 PM
I don't know why it wouldn't let me upload images, but here is the plate.

(https://i.gyazo.com/b0aa3356e6a0f21fa42f0acdb75f3c7a.png)
Title: Re: Custom Workpart
Post by: EasyPLC_Master on January 19, 2023, 05:56:42 PM
If you want to move up/down or left/right ot forward/backward one component (static, model) you can do it using the Movemet node in graph code or the AnimationMove function in sctip code.
For instance using this graph code the Static Component will mobe to the left while the PLC Ouput 0 will be on and will stop when off (until reach the maximun postion X = 10)
Also if you want you can send me your udc file and I will try to help you better.
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 19, 2023, 06:32:09 PM
Sure I am sending it to you now. Thanks!
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 22, 2023, 11:46:55 AM
I have a couple of questions, one regarding the hook system and the other about the graph. In regards to the hook, I would like to know if I have to make 1 hook for each item I want to hook or if I can make a wide area that catches multiple items at once.

And regarding the graph, the plate stops when I'm going up according to the up detector condition, and down when I'm going down. But when it's detecting security up, it doesn't go down, and the signal to go down should only take into account the bottom detector.

I can't seem to see the problem. Greetings.
(https://i.gyazo.com/5bb9e571065e1992563134423be8061e.png)
Title: Re: Custom Workpart
Post by: EasyPLC_Master on January 22, 2023, 01:40:00 PM
Hi Pablo!

The hook component can only grab one WorkPart at a time, if there is more than one that collides with it, it will grab the last one that has collided. So, effectively you need a hook for each item you want to grab.

Regarding the graph code, take into account that the BreakMovement node prevails over the Movement node, then if is activated, the Movement node has not effect.
You may need to insert a trigger type node (at BreakMovement Action port) so that the component stops only on the rising edge of the signal instead of continuously.
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 22, 2023, 10:51:21 PM
I understand. What I need is that whenever I see the top detector , I cannot go up, and vice versa for down. But if it is top, I should be able to go down.
In my Graph (which I am not sure is correct) what I am trying to do is that if it is going up, it makes a break with the top detector . But it  should ignore the break to go down. The other break is that it cuts off movement if I am not going up or down.
I have tried with the trigger but it doesn't work well for me either. I will continue investigating. ;)
Title: Re: Custom Workpart
Post by: EasyPLC_Master on January 23, 2023, 12:26:34 PM
OK, perhaps could be better to use the script code, due for complex movements or operations is powerfull.
Here I attach you an example how to make it what you pretend:

-> PLC Output 0 moves the component up until it detects Inductive sensor 1
-> PLC Output 1 moves the component down until it detects Inductive sensor 2

Here is the script and machine example file attached , hope it helps!

bool flag1 = false;
bool flag2 = false;

public void Init()
{
   IOManager.SetOutputDesc(0, "Mover Arriba");
   IOManager.SetOutputDesc(1, "Mover Abajo");
}

public void Main()
{
   if(IOManager.GetOutput(0))
   {      
      if(!flag1 && !IOManager.GetInput(0))
      {
         S0.AnimationMove("Y", 1, 3);
         flag1 = true;
      }
      
      if(IOManager.GetInput(0))
      {
         S0.BreakMovement();
      }      
   }   
   else if(IOManager.GetOutput(1))
   {
      if(!flag2 && !IOManager.GetInput(1))
      {
         S0.AnimationMove("Y", 1, 0);
         flag2 = true;
      }
      
      if(IOManager.GetInput(1))
      {
         S0.BreakMovement();
      }
   }
   else
   {
      S0.BreakMovement();
      flag1 = flag2 = false;
   }
   
   
}

public void Physics()
{

}

public void Finish()
{

}
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 23, 2023, 05:00:06 PM
Indeed, it was the next thing I was going to try.
Surely with code it would be simpler. I have adapted a bit of what you sent me and it works perfectly.
Now that we have removed the Graph, I have not tested the Acceleration in the movement function. I will also try to do it in code. Greetings! :D
Title: Re: Custom Workpart
Post by: pablo.martinez garcia on January 24, 2023, 05:33:16 PM
Hey! Its possible to set a speed less than 1? Thanks!
Title: Re: Custom Workpart
Post by: EasyPLC_Master on January 24, 2023, 06:37:27 PM
of course! you can set any value < 1
For instance: 0.1f, 0.5f, 0.02f,...