forked from SofaDefrost/prefab.MobileTrunk
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from AlessandriniAntoine/coupling_trunk_and_sum…
…mit_xl Coupling trunk and summit xl
- Loading branch information
Showing
8 changed files
with
132 additions
and
328 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,55 @@ | ||
import Sofa | ||
|
||
import math | ||
|
||
class CableController(Sofa.Core.Controller): | ||
""" | ||
Controller to control the cables in forward kinematics | ||
Parameters : | ||
mechanicalObject : the mechanicalObject to control | ||
cables : list of the cables (constraint object) | ||
name : the name of the component | ||
""" | ||
|
||
def __init__(self, mechanicalObject : Sofa.Core.Node, name : str = "CableController"): | ||
def __init__(self, cables : list, name : str = "CableController"): | ||
Sofa.Core.Controller.__init__(self, name = name) | ||
|
||
self.Cables = mechanicalObject | ||
|
||
self.cables = cables | ||
self.index =0 | ||
# action at beginning frame | ||
def onAnimateBeginEvent(self, eventType): | ||
pass | ||
|
||
#action when key press | ||
def onKeypressedEvent(self, c): | ||
key = c['key'] | ||
##### Section 1 ###### | ||
|
||
# Cable 1 | ||
if (key == "1"): | ||
displacement = self.Cables.Section1Cable1.value.value+1 | ||
if displacement[0] <= 20 : | ||
self.Cables.Section1Cable1.value.value = [displacement] | ||
print("length Section 1 Cable 1 : "+str(displacement[0])) | ||
|
||
|
||
if (key == "4"): | ||
displacement = self.Cables.Section1Cable1.value.value-1 | ||
if displacement[0] >= -20 : | ||
self.Cables.Section1Cable1.value.value = [displacement] | ||
print("length Section 1 Cable 1 : "+str(displacement[0])) | ||
|
||
# Cable 2 | ||
if (key == "2"): | ||
displacement = self.Cables.Section1Cable2.value.value+1 | ||
if displacement[0] <= 20 : | ||
self.Cables.Section1Cable2.value.value = [displacement] | ||
print("length Section 1 Cable 2 : "+str(displacement[0])) | ||
|
||
if (key == "5"): | ||
displacement = self.Cables.Section1Cable2.value.value-1 | ||
if displacement[0] >= -20 : | ||
self.Cables.Section1Cable2.value.value = [displacement] | ||
print("length Section 1 Cable 2 : "+str(displacement[0])) | ||
|
||
# cable 3 | ||
if (key == "3"): | ||
displacement = self.Cables.Section1Cable3.value.value+1 | ||
if displacement[0] <= 20 : | ||
self.Cables.Section1Cable3.value.value = [displacement] | ||
print("length Section 1 Cable 3 : "+str(displacement[0])) | ||
|
||
if (key == "6"): | ||
displacement = self.Cables.Section1Cable3.value.value-1 | ||
if displacement[0] >= -20 : | ||
self.Cables.Section1Cable3.value.value = [displacement] | ||
print("length Section 1 Cable 3 : "+str(displacement[0])) | ||
|
||
|
||
# ##### Section 2 ###### | ||
|
||
# # Cable 1 | ||
# if (key == "A"): | ||
# displacement = self.Cables.Section2Cable1.value.value+1 | ||
# if displacement[0] <= 20 : | ||
# self.Cables.Section2Cable1.value.value = [displacement] | ||
# print("length Section 2 Cable 1 : "+str(displacement[0])) | ||
|
||
|
||
# if (key == "B"): | ||
# displacement = self.Cables.Section2Cable1.value.value-1 | ||
# if displacement[0] >= -20 : | ||
# self.Cables.Section2Cable1.value.value = [displacement] | ||
# print("length Section 2 Cable 1 : "+str(displacement[0])) | ||
|
||
# # Cable 2 | ||
# if (key == "C"): | ||
# displacement = self.Cables.Section2Cable2.value.value+1 | ||
# if displacement[0] <= 20 : | ||
# self.Cables.Section2Cable2.value.value = [displacement] | ||
# print("length Section 2 Cable 2 : "+str(displacement[0])) | ||
key = c['key'] | ||
displacement = [math.inf] | ||
|
||
# if (key == "D"): | ||
# displacement = self.Cables.Section2Cable2.value.value-1 | ||
# if displacement[0] >= -20 : | ||
# self.Cables.Section2Cable2.value.value = [displacement] | ||
# print("length Section 2 Cable 2 : "+str(displacement[0])) | ||
|
||
# # cable 3 | ||
# if (key == "E"): | ||
# displacement = self.Cables.Section2Cable3.value.value+1 | ||
# if displacement[0] <= 20 : | ||
# self.Cables.Section2Cable3.value.value = [displacement] | ||
# print("length Section 2 Cable 3 : "+str(displacement[0])) | ||
|
||
# if (key == "F"): | ||
# displacement = self.Cables.Section2Cable3.value.value-1 | ||
# if displacement[0] >= -20 : | ||
# self.Cables.Section2Cable3.value.value = [displacement] | ||
# print("length Section 2 Cable 3 : "+str(displacement[0])) | ||
|
||
# ##### Section 3 ###### | ||
|
||
# # Cable 1 | ||
# if (key == "G"): | ||
# displacement = self.Cables.Section3Cable1.value.value+1 | ||
# if displacement[0] <= 20 : | ||
# self.Cables.Section3Cable1.value.value = [displacement] | ||
# print("length Section 3 Cable 1 : "+str(displacement[0])) | ||
|
||
|
||
# if (key == "H"): | ||
# displacement = self.Cables.Section3Cable1.value.value-1 | ||
# if displacement[0] >= -20 : | ||
# self.Cables.Section3Cable1.value.value = [displacement] | ||
# print("length Section 3 Cable 1 : "+str(displacement[0])) | ||
|
||
# # Cable 2 | ||
# if (key == "I"): | ||
# displacement = self.Cables.Section3Cable2.value.value+1 | ||
# if displacement[0] <= 20 : | ||
# self.Cables.Section3Cable2.value.value = [displacement] | ||
# print("length Section 3 Cable 2 : "+str(displacement[0])) | ||
|
||
# if (key == "J"): | ||
# displacement = self.Cables.Section3Cable2.value.value-1 | ||
# if displacement[0] >= -20 : | ||
# self.Cables.Section3Cable2.value.value = [displacement] | ||
# print("length Section 3 Cable 2 : "+str(displacement[0])) | ||
|
||
# # cable 3 | ||
# if (key == "K"): | ||
# displacement = self.Cables.Section3Cable3.value.value+1 | ||
# if displacement[0] <= 20 : | ||
# self.Cables.Section3Cable3.value.value = [displacement] | ||
# print("length Section 3 Cable 3 : "+str(displacement[0])) | ||
|
||
# if (key == "L"): | ||
# displacement = self.Cables.Section3Cable3.value.value-1 | ||
# if displacement[0] >= -20 : | ||
# self.Cables.Section3Cable3.value.value = [displacement] | ||
# print("length Section 3 Cable 3 : "+str(displacement[0])) | ||
|
||
# action at end frame | ||
def onAnimateEndEvent(self, eventType): | ||
pass | ||
##### cables number ###### | ||
if (key == "1"): | ||
self.index = 0 | ||
elif (key == "2"): | ||
self.index = 1 | ||
elif (key == "3"): | ||
self.index = 2 | ||
elif (key == "4"): | ||
self.index = 3 | ||
elif (key == "5"): | ||
self.index = 4 | ||
elif (key == "6"): | ||
self.index = 5 | ||
elif (key == "7"): | ||
self.index = 6 | ||
elif (key == "8"): | ||
self.index = 7 | ||
elif (key == "9"): | ||
self.index = 8 | ||
|
||
##### add or substract ###### | ||
if key == '+': | ||
displacement = self.cables[self.index].value.value+1 | ||
self.cables[self.index].value.value = [displacement] | ||
print(f'Cables {self.index} displacement = {displacement[0]}') | ||
|
||
elif key == '-': | ||
displacement = self.cables[self.index].value.value-1 | ||
self.cables[self.index].value.value = [displacement] | ||
print(f'Cables {self.index} displacement = {displacement[0]}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.