article

anthony.johnson avatar image
5 Likes"
anthony.johnson posted anthony.johnson edited

Customizing AGV Speed with Jerk

I was recently asked how a user can implement jerk, i.e. a rate of acceleration change, in the AGV module. The AGV module uses FlexSim's kinematics API to define the motion of AGVs along paths. The kinematics API does not natively support jerk. However, the AGV module has included a hook to allow developers, and audacious end users :-), to customize the kinematics that drive AGVs on paths. Using this hook, you can approximate jerk by breaking what would otherwise be a single kinematic, with a single acceleration/deceleration, into multiple smaller kinematics that gradually change the acceleration/deceleration of the object as it progresses.

There are two ways to do this. The first option is to simply do it as an end user, confining your changes to your model, by customizing nodes in the tree. The second option is to do it as a module developer, using the module SDK.

Adding Jerk as a User

The AGV network uses an "AGV Customization Delegate" to allow for hooks to be placed at certain points in the AGV navigation logic. There is a default customization delegate that the AGV network uses, but you can override the logic of this default delegate by adding and configuring a special node at MODEL:/AGVNetwork>variables/customizationDelegate.

But before I tell you how to do it, I want to explain a little more about how it works. I've attached three C++ files. The main ones you'll want to look at are AGVCustomizationDelegate.h and AGVCustomizationDelegate.cpp. These show the definition of the customization delegate class. In the header file, you'll see the definition of AGVCustomizationDelegate class. This class includes several methods, but the main method relevant here is addKinematics(). This method takes several parameters defining the context. Its responsibility is to add one or more kinematics, in the positive X direction, that will move the AGV the target distance along a path.

The AGVCustomizationDelegate class is the default customization delegate used by the AGV network. The C++ files also define a subclass called UserAGVCustomizationDelegate, which overrides the methods of its parent class by delegating the logic to FlexScript code that the user can write in the model.

So, now for actually doing it in the model. We want to instantiate an instance of UserCustomizationDelegate at the node MODEL:/AGVNetwork>variables/customizationDelegate, so that we can write FlexScript code to add the kinematics.

  1. Navigate in the tree to MODEL:/AGVNetwork>variables/customizationDelegate
  2. Right click on that node, and choose Edit > Designate this Node (so)
  3. In a script window execute the script: nodeadddata(so(), DATATYPE_SIMPLE)
  4. Add a subnode to that node named sdt::attributetree and give it the text: AGV::UserAGVCustomizationDelegate.

  5. Copy the node and then paste it onto itself. This will instantiate the UserAGVCustomizationDelegate.

  6. Right-click on the addKinematics subnode and choose Build > Toggle Node as FlexScript.
  7. Right-click on the addKinematics node and choose Explore > As Code. This will allow you to edit the code for adding kinematics.
  8. The header for field should be as follows (note this is determined by the evaluate() command in AGVCustomizationDelegate.cpp at line 71).
treenode kinematics = param(1); // the kinematics node to call addkinematic()/getkinematics() on
treenode section = param(2); // the associated travel path section
double startAtTravelDist = param(3); // the agv cumulative travel distance at this point
double distance = param(4); // the distance to travel on the path section (your addkinematics() calls should add up to this distance)
double startTime = param(5); // the start time for the first addkinematic() call
double startSpeed = param(6); // the initial speed to start at
double endSpeed = param(7); // the target end speed (should be going this speed at the end)
int reason = param(8); // reason for adding the kinematic (see AGVCustomizationDelegate.h)
treenode endSpeedOut = param(9); // if target end speed cannot be reached, update this node's value with the actual end speed
double peakSpeed = param(10);
double acc = param(11);
double dec = param(12);
TaskExecuter agv = ownerobject(tonode(get(kinematics.up))); // the agv

At this point you can customize how kinematics are added to the kinematics node in this code. To approximate jerk you would break it up into small addkinematic() commands that each change the acceleration/deceleration. Please refer to the kinematics api for more information on how to manipulate kinematics. Note that you should only use the addkinematic() and getkinematics() commands in this field (not initkinematics() or updatekinematics()), and the addkinematic() command should only tell the AGV to move forward in the X direction. Y and Z directions are ignored by the AGV travel logic. In other words, from a kinematics perspective, the AGV network "flattens" an AGV's path into movement in a straight line along the x axis.

When you're finished adding kinematics, you should return the end time of the last added kinematic. This will be the same as the return value of the last called addkinematic() command.

Adding Jerk as a Module Developer

To implement jerk as a module developer, you would first create a module using the module SDK. Then you would include AGVClasses.h and AGVCustomizationDelegate.h in your project (do not include AGVCustomizationDelegate.cpp as it won't compile properly. I'm including that file just to be informative in this article). Then you would subclass AGVCustomizationDelegate with your own class that overrides the appropriate methods, specifically the addKinematics() method. Once you've done that, you would replace MODEL:/AGVNetwork>variables/customizationDelegate with an instance of your customized class, using the same steps described above, but using your own class name instead of AGV::UserAGVCustomizationDelegate. If you need more header files so you can access more information, i.e. the definition of TravelPathSection, the let us know and we can get them to you.

agvheaderfiles.zip

agvmodule sdkkinematics
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Article

Contributors

anthony.johnson contributed to this article

Related Articles