Kangaroo 2 GH component with custom goal integration

@DavidRutten @dale @stevebaer @DanielPiker @scottd
To whom it may concern:

I am making GH components in c# dotnet smoothly. Recently started with Kangaroo custom goals. Some work fine.
Here I tried to implement angleclamp from Daniel Piker’s goals available in Github.
I want to run custom goal integrated with KangarooSolver.PhysicalSystem in same component, as I have some calculation at later stage while KangarooSolver.PhysicalSystem is running. I want to implement Rod and AngleClamp.

It shows in debugging KangarooSolver.PhysicalSystem is null hence, in AngleClamp Calculate method PIndex[0] is becoming null.
I have attached the code, one GH definition, gh component and 3dm file.

Please some one help me with this. Angle clamp and Rod need to work to go for next step.

I had a quick look through the code and can’t immediately see the problem, but I’ll take a deeper look.

Have you managed to get any definitions or components working using PhysicalSystem?

Dear Daniel,
Many thanks for the reply ! Yes, I did few components in c# with PhysicalSystem. It works with custom spring goal.
I have separated angleclamp bit in the code. If you see, it works without AngleClamp.

Ah, I think I see now where the problem lies.

You create your instances of your custom goal by setting the positions PPos[], and the indexing PIndex[] is not getting assigned.

When the solver runs it uses the PIndex to identify which particles to apply each goal to.

One way you can set your PIndex values is when you first create the goal (as you are doing with the other goals, such as the anchors). For this you need to also include a constructor which takes integer inputs, like this one:


This means that when you then create instances of that goal you need to know the indices of the particles you are applying it to.

Alternatively, you can keep using the constructor by position, which just sets PPos, but before you call Step in the solver, you need to run the AssignPIndex function, which looks at the positions of PPos, compares them to the existing particles in the system and assigns the PIndex values accordingly.
You can see an example of this here:
https://github.com/Dan-Piker/Kangaroo-examples/blob/master/scripting/CustomIteration.gh

Thanks Daniel ! I am looking into it.

Dear Danial,
It works now with AssignPIndex. But result is quite funny. I am looking into code, I think I did something wrong . At list now it can find the particle index and running. Many thanks ! If I am not able to solve the imperfection, I will write you back.
I have another question regarding custom spring, which is running but it need to be more improved. after solving this, I will ask you again.
Thanks again !

Dear Daniel,
It works, but angles are getting funny and giving trail of points when moving particles. That never happened before. So, I am deleting the point list output. I gave angle 1.5 degree and 0.5, strength 1.
It gives 8 or 9 degree angular deviation, at list. Not sure if the angle is in radian in angleclamp.
Code and compiled component inside bin folder. definition and 3dm file is also included in zip folder.

Are you adding these angleclamp goals after the particles have started moving?

The default behaviour for AssignPIndex is to compare the positions of the points in the PPos of the goal to the initial positions of the particles in the system.
It sounds like what is happening is that new particles keep getting created because the goals are being created at new locations in space, resulting in the trails you are seeing.

If instead you want to do the indexing comparing the points in the goal to the current positions of the particles, you can use this method:

AssignPIndex(IGoal Goal, double Tolerance, bool ByCurrent)

with ByCurrent set to True.

All angles used in Kangaroo are in radians.

Many thanks Daniel. OK. I think you caught it very right. I am sure this will solve the problem. speak again soon.

Dear Daniel, It looks working now. I have converted degree to radian. Minimum and maximum value for angle looks much bigger that 1.5 degree. If I increase strength in angle clamp it become even more deviated. But yes, at list it looks quite smooth, even though not following exact min and max angle 1.5 and 0.5 degree.
I gave angleclamp strength to 100.