天天看點

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

  The geometric constraint solver is slower and less precise at solving kinematic problems, but might be easier and more intuitive to use. Moreover, it allows interacting with a mechanism in a more flexible way than the inverse kinematics calculation module. Following figures illustrate the geometric constraint solver applied to a complicated mechanism:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[Geometric constraint solver handling a complicated mechanism:  (1) initial situation, (2) during simulation, (3) interaction with the mechanism]

  V-REP\'s geometric constraint solver functionality operates in a similar way as the kinematics calculation module, with the difference that the solver will try to automatically identify kinematic chains, and handle them in an appropriate way (automatic constraint adjustments, loop closures, etc.). Typically, the user has to tell the solver:

  • which objects (dummies) should coincide (in order to close a loop for instance)
  • what mechanism has to be handled by the geometric constraint solver
  • which additional constraints should be applied to the mechanism

 Specifying closure constraints 

  Closure constraints can be seen as constraints that require two object\'s configurations (position and orientation) to be identical. The idea is illustrated in following figures:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[The geometric constraint solver closure constraint]

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[Closing action of the geometric constraint solver (1) intermediate situation, (2) final situation]

  GCS會試圖将closure pair的位置以及姿态重合,是以機構要有足夠的自由度。對于平面機構(如鉸鍊四杆機構)來說使用GCS保持機構閉合就不合适,可以考慮用IK,tip-target來構成閉環。The geometric constraint solver will try to overlap the position and orientation of the two objects while trying to keep the mechanism coherent (i.e. by only adjusting the joints in IK mode in the mechanism to reach that overlap situation). The objects that the geometric constraint solver uses to specify closure constraints are dummies. To this end, two dummies need to be marked as closure pair. This can be adjusted in the dummy properties by selecting the opposite dummy as Linked dummy and specifying GCS, overlap constraint for the Link type. Following figure illustrates two linked dummies specifying a geometric constraint solver closure constraint:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[Two linked dummies specifying a closure constraint]

 Specifying the mechanism to be solved 

  All objects that can be reached from a given object by following a path that can go will be considered as the same mechanism: 

  1. from one object to its parent object.
  2. from one object to its child objects.
  3. from one dummy to its linked dummy (however only links of type GCS, overlap constraint)

  即按照上面3種方式從運動鍊(elements)上某一點開始探索,能夠到達的節點都屬于同一個機構。如果兩個運動鍊沒有公共的節點,但是由類型為GCS,overlap constraint的dummy相連,則這兩個運動鍊仍屬于同一個機構。Two object trees that don\'t share any common parent objects (referred hereafter as elements), can also be part of the same mechanism if two linked dummies join them. This is illustrated in following figure:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[One mechanism composed by 3 elements (object trees)]

  The last parent object of the object that is chosen as the starting point of the mechanism exploration (path exploration) is referred to as the base object of the mechanism. When the geometric constraint solver tries to solve a mechanism, it will try to do so by keeping the base object of the mechanism in place(求解幾何限制時選作base的object會固定住不動). This is important to remember. To specify a mechanism to be solved, select an object parented with the base object of the mechanism and in the geometric constraint solver dialog click insert new object. One same mechanism can only be registered once for solving. Mechanisms that do not include at least one joint in IK mode will not be handled by the solver.

 Specifying additional constraints 

  Additional positional constraints can be specified for a mechanism. This can be done with two linked dummies that form a tip-target pair (specify GCS, tip/GCS, target as Link type in the dummy properties). Following figures illustrate two linked dummies, where one is marked as target:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[The geometric constraint solver position constraint]

  注意GCS, tip/GCS, target與GCS, overlap constraint的差別是:GCS, target不會被當做機構的一部分,解算時target不動tip移動到與target重合;而GCS, overlap constraint類型的dummy則屬于同一個機構,解算時會同時移動直到重合。The dummy marked as target is not considered as part of the mechanism and therefore will not move during geometric constraint resolution, while the other dummy will try to reach the same position as the dummy marked as target.

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[Position constraint action of the geometric constraint solver (1) intermediate situation, (2) final situation]

  使用GCS(幾何限制求解器),可以用滑鼠拖動場景中的物體進行直覺地控制。During simulation, a mechanism that was previously registered to be solved with the geometric constraint solver can be manipulated in a flexible way with the mouse, when the mechanism navigation mode is selected. That mode can be enabled via following API call: simSetNavigationMode. Simply click and drag any shape object that is part of the mechanism, and the solver will try to take into account that additional position constraint.

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[Mechanism with two additional position constraints]

  It is good practice to build your mechanism as a tree structure (i.e. where all objects in the mechanism have at least one common parent object) and have linked dummies be in charge of closing certain tree branches. By doing so you reduce the mechanism\'s complexity, you simplify the mechanism\'s scene hierarchy representation, and you will be able to handle the mechanism as a model. 

  下面是一個簡單的例子,用滑鼠選中門并按住左鍵拖動,可以看到門能跟着滑鼠運動。修改Model browser/Models/infrastructure/doors/manual door中的場景和代碼,添加一個控制球和一組Dummy(類型分别設定為GCS, tip/GCS, target),然後在Calculation Modules的Geometric Constraint Solver選項頁中将根節點door設為機構的base 。最後将旋轉關節設為Inverse kinematics模式,進行仿真:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)
V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

   代碼如下:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)
if (sim_call_type==sim_childscriptcall_initialization) then 

    jointHandle=simGetObjectHandle(\'_doorJoint\')
    sphereHandle=simGetObjectHandle(\'manipulationSphere\')

    -- Retrieves the navigation and selection mode for the mouse
    initialMode=simGetNavigationMode() 

    -- Sets the navigation and selection mode for the mouse. 
    simSetNavigationMode(sim_navigation_objectshift+
                            sim_navigation_clickselection+
                            sim_navigation_ctrlselection+
                            sim_navigation_shiftselection+
                            sim_navigation_camerazoomwheel+
                            sim_navigation_camerarotaterightbutton)

    tipDummyHandle=simGetObjectHandle(\'tip\')

    -- sim_intparam_prox_sensor_select_down: Allows to enable message or callback generation when a shape 
    -- was clicked (down-click) in the scene. The click is a "geometric" click. This value is set to zero 
    -- at simulation start and simulation stop.
    -- (-1: enabled for all visible shapes in the scene)
    simSetInt32Parameter(sim_intparam_prox_sensor_select_down, -1)  

    simDisplayDialog("info","You can click and drag the door",sim_dlgstyle_ok,false)

end 



if (sim_call_type==sim_childscriptcall_sensing) then

    -- auxiliaryData[1]: objectID
    -- auxiliaryData2[1] ~ auxiliaryData2[3]: coordinates of clicked point
    local message,data,data2 = simGetSimulatorMessage()

    while message>-1 do  -- (-1 if no message is available or in case of an error)
        if message == sim_message_prox_sensor_select_down then

            -- move manipulation sphere according the position of clicked point
            simSetObjectPosition(sphereHandle,-1,{data2[1],data2[2],data2[3]}) 

            simSetObjectPosition(tipDummyHandle,-1,{data2[1],data2[2],data2[3]})
            simSetObjectParent(tipDummyHandle, data[1], true)

            -- select the manipulation sphere to move
            simRemoveObjectFromSelection(sim_handle_all)
            simAddObjectToSelection(sim_handle_single,sphereHandle)
        end
        message,data,data2 = simGetSimulatorMessage()
    end
end



if (sim_call_type==sim_childscriptcall_cleanup) then 
    simRemoveObjectFromSelection(sim_handle_all) -- removes all objects from the selection
    simSetInt32Parameter(sim_intparam_prox_sensor_select_down, 0) -- 0: disabled
    simSetNavigationMode(initialMode)
end       

View Code

   下面是一個修改自V-REP_PRO_EDU\scenes\constraintSolverExample.ttt的例子,用滑鼠選中機構上任意杆件進行拖拽,可以看到機構能跟着一起運動而不散開:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

 Geometric constraint solver operation 

  When building a mechanism that will be solved by the geometric constraint solver, make sure that the mechanism is coherent and that constraints are not impossible (i.e. that there are enough degrees of freedom for the mechanism to work). Following figures show an example of a mechanism and its resolution:

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[(1) Mechanism containing 3 elements before and (2) during simulation]

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[Same mechanism, but different base object (1) before and (2) during simulation]

V-rep學習筆記:Geometric Constraint Solver(幾何限制求解)

[(1) Mechanism containing 2 elements before and (2) during simulation]

參考:

Using the geometric constraint solver

Solving IK and FK for any type of mechanism

Good example of GCS?

control the model using mouse in simulation mode

V-rep學習筆記:曲柄搖杆機構

V-rep學習筆記:并聯機構正逆運動學