Hello, I am relatively new to Visual Components and currently on a project.
I am using Mobile Robots of Visual Components. I receive coordinate values through OPC UA and then I move the vehicle by triggering the move_to()
, charge by triggering execute_charging()
function blocks present in the Resource script of Mobile Robots. Now I want to pick an object, there’s an execute_pick_action()
block in the Resource script which I want to trigger. But I am not sure how to do this, it takes vcAction()
as an argument, can someone please guide me how I can trigger this execute_pick_action()
function block?
Following is the code for the function block
def execute_pick_action(manager, task_action):
# type: (ActionManager, vcAction) -> None
speed = comp.MoveSpeedLoaded if config.cont.ComponentCount else comp.MoveSpeed
# debug('*** Executing ({}) action with properties {}'.format(task_action.Name, [(p.Name, p.Value) for p in task_action.Properties]), simtime=True)
tool_comp = task_action.ToolComponent
if current_tool and (task_action.TransportLink.Tool == 'No Tool' or task_action.TransportLink.Tool != 'Use Current' and tool_comp != current_tool or manager.assistance in (ActionManager.LOAD_ASSISTANT, ActionManager.UNLOAD_ASSISTANT)):
return_tool()
if not current_tool and tool_comp and manager.assistance not in (ActionManager.LOAD_ASSISTANT, ActionManager.UNLOAD_ASSISTANT):
collect_tool(tool_comp, speed)
component = task_action.Component
source_node = task_action.SourceNode
source_node, transport_target = get_transport_data(component, source_node, source=True)
offset_vec_p = task_action.TransportLink.getProperty('ResourcePickOffset')
offset_vec = offset_vec_p.Value if offset_vec_p else vcVector.new()
approach_vec_p = task_action.TransportLink.getProperty('PickApproach')
approach_vec = approach_vec_p.Value if approach_vec_p else vcVector.new()
approach_distance = approach_vec.length()
move_target = transport_target.ResourcePosition # type: vcMatrix
move_target.translateRel(offset_vec.X, offset_vec.Y, offset_vec.Z)
travel_target = vcMatrix.new(move_target)
travel_target.translateRel(approach_vec.X, approach_vec.Y, approach_vec.Z)
assisted = False
assistant = False
if manager.assistance == ActionManager.LOAD_ASSISTANT:
# pick from process
# print comp.Name, 'assist: pick from process'
assistant = True
assist_frame = source_node.Component.getFeature('AssistLocation')
if assist_frame:
move_target = source_node.Component.WorldPositionMatrix*assist_frame.NodePositionMatrix
travel_target = move_target
else:
use_resourceloc_p = task_action.AssistComponent.getProperty('Assist::UseResourceLocation')
if not use_resourceloc_p or not use_resourceloc_p.Value:
component.update()
move_target = assist_resolve_move_target(transport_target.ResourcePosition, component.WorldPositionMatrix)
travel_target = move_target
elif manager.assistance == ActionManager.UNLOAD_ASSISTANT:
# pick from assisted resource
# print comp.Name, 'assist: pick from assisted resource'
assistant = True
destination_node, transport_target = get_transport_data(component, source_node, source=False)
move_target = transport_target.ResourcePosition # type: vcMatrix
offset_vec_p = task_action.TransportLink.getProperty('ResourcePlaceOffset')
offset_vec = offset_vec_p.Value if offset_vec_p else vcVector.new()
move_target.translateRel(offset_vec.X, offset_vec.Y, offset_vec.Z)
use_resourceloc_p = task_action.AssistComponent.getProperty('Assist::UseResourceLocation')
if not use_resourceloc_p or not use_resourceloc_p.Value:
move_target = assist_resolve_move_target(transport_target.ProductPosition, move_target)
travel_target = move_target
elif manager.assistance == ActionManager.LOAD_ASSISTED:
assisted = True
assist_requested = assist_request_assistance(task_action, load=True, to_mounted=False)
if assistant:
fasten_only_p = task_action.AssistComponent.getProperty('Assist::FastenOnly')
assist_fasten_only = fasten_only_p.Value if fasten_only_p else False
else:
assist_fasten_only = False
comp_wpm = travel_controller.interpolate(sim.SimTime)
travel_threshold = approach_distance if approach_distance > 0.0 else 200.0
distance_to_target = (comp_wpm.P - move_target.P).length()
# travel only if not already at the target or closer to the target (ResourcePosition) than approach target
if distance_to_target > 1.0 or comp_wpm.WPR.Z != move_target.WPR.Z:
stats_manager.set_state('Transporting' if config.cont.ComponentCount > 0 else 'Moving')
if distance_to_target > (travel_threshold + EPSILON):
travel_to(travel_target, speed, comp.TurnSpeed, align_to_target=True) # travel to approach loc
if actuator_control and actuator_control.conf_load_extend == ActuatorControl.CONF_AT_APPROACH:
actuator_control.extend(component.WorldPositionMatrix)
move_to(move_target, comp.MoveSpeedApproach, comp.TurnSpeed, align_to_target=True) # travel to target
traffic_service.occupy_position(move_target.P, move_target.N)
if actuator_control and actuator_control.conf_load_extend == ActuatorControl.CONF_AT_TARGET:
actuator_control.extend(component.WorldPositionMatrix)
if manager.assistance == ActionManager.UNLOAD_ASSISTANT:
# pick from assisted resource
assist_wait_for_ready(task_action.AssistComponent)
for pname in ('PickTime', 'GraspTime'):
pick_time_p = task_action.TransportLink.getProperty(pname)
if pick_time_p:
break
pick_time = pick_time_p.Value if pick_time_p else 0.0
stats_manager.set_state('Picking')
if assisted and not assist_requested:
assist_request_assistance(task_action, load=True, to_mounted=True)
if human_control and human_control.active and not current_tool:
human_control.animate(component.Product.ProductType.Name + '_Pick', 'Default_Pick', lock=True)
block_p = task_action.TransportLink.getProperty('BlockProcessPicking')
if not assist_fasten_only:
pick(component, pick_time, assisted, block_p.Value if block_p else False)
if human_control:
human_control.lock = False
# schedule pending move to reverse
if not travel_controller.at_position(travel_target) and not travel_controller.pending_move_target:
travel_controller.pending_move_target = travel_target
travel_controller.pending_move_state = 'Picking'