EventTable Example
This example shows you how to create an event. If you are unfamiliar with the EventManager, it might be a good idea to have a look at it in RobotStudio so you know what we are doing.
The event we are creating is to attach a box to a robot, when a digital signal is set, and to detach the box from the robot when the signal is reset.
You need to create a new station with an IRB140_5kg_0.81m robot for this example.
First, we create a box that we will attach to/detach from the robot. The attachment/detachment is controlled by a digital signal, which we then create.
After that, we define what will happen when we trigger My Digital Signal, in this case attach/detach ChildPart to/from the robot.
If you want to mount the box on the robot, instead of leaving it at its current position, just change etAttach.MountObject = false; to etAttach.MountObject = true;
Run the Add-In and open up the I/O Simulator (select Station Signals too see our signal) and the Mechanism Joint Jog window for the robot. Set My Digital Signal to 1, and jog the robot. The box will follow the robot's motions. Set the signal to 0 and jog the robot again. The box will now stay in its position.
You can see our events in the EventManager.
Example
Project.UndoContext.BeginUndoStep("EventTable");
try
{
Station station = Station.ActiveStation;
// Create a box to attach to the robot.
// See the Body CreateSolids Example for more information about creating parts and bodies.
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
box_origin.Translate(0.5, 0, 0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Part ChildPart = new Part();
ChildPart.Name = "ChildPart";
station.GraphicComponents.Add(ChildPart);
Body ChildBox = Body.CreateSolidBox(box_origin, box_size);
ChildBox.Name = "ChildBox";
ChildPart.Bodies.Add(ChildBox);
// Add a digital signal to controll the attaching/detaching.
station.IOSignals.Add(new IOSignal("MyDigitalSignal", IOSignalType.DigitalInput));
// Set the events to be activated.
EventActivationMode eam = EventActivationMode.Always;
// Define when to trigger the attach event.
EventTableTriggerIO etTriggerAttach = new EventTableTriggerIO();
// For station signals, Controller must be set to the station
etTriggerAttach.Controller = station;
etTriggerAttach.Name = "My Digital Signal";
etTriggerAttach.Value = 1;
// Define which child to attach to which parent.
EventTableActionAttach etAttach = new EventTableActionAttach();
GraphicComponent link;
if (station.GraphicComponents.TryGetGraphicComponent("IRB140_6_81_C_G_03_2", out link))
etAttach.AttachmentParent = link;
else
Logger.AddMessage(new LogMessage("Could not find 'IRB140_6_81_C_G_03_2' to attach 'ChildPart' to!"));
etAttach.AttachmentChild = ChildPart;
etAttach.MountObject = false;
// Create the attach event table entry.
EventTableEntry etEntryAttach = new EventTableEntry();
etEntryAttach.EventTableTrigger = etTriggerAttach;
etEntryAttach.EventTableActions.Add(etAttach);
etEntryAttach.EventActivationMode = eam;
// Add the attach event to the event table.
Simulator.ActiveConfiguration.EventTable.EventTableEntries.Add(etEntryAttach);
// Define when to trigger the detach event.
EventTableTriggerIO etTriggerDetach = new EventTableTriggerIO();
etTriggerDetach.Controller = station;
etTriggerDetach.Name = "My Digital Signal";
etTriggerDetach.Value = 0;
// Define which child to detach from which parent.
EventTableActionDetach etDetach = new EventTableActionDetach();
if (station.GraphicComponents.TryGetGraphicComponent("IRB140_6_81_C_G_03_2", out link))
etDetach.AttachmentParent = link;
else
Logger.AddMessage(new LogMessage("Could not find 'IRB140_6_81_C_G_03_2' to detach 'ChildPart' from!"));
etDetach.AttachmentChild = ChildPart;
// Create the detach event table entry.
EventTableEntry etEntryDetach = new EventTableEntry();
etEntryDetach.EventTableTrigger = etTriggerDetach;
etEntryDetach.EventTableActions.Add(etDetach);
etEntryDetach.EventActivationMode = eam;
// Add the detach event to the event table.
Simulator.ActiveConfiguration.EventTable.EventTableEntries.Add(etEntryDetach);
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}