University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Locking channels | General SmartBody Discussion | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Locking channels
March 9, 2016
10:18 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Hello.

I'm working with beaviohrsetreaching.py file and i want to create a new skeleton like  common.sk with certain constraints. For example, in the file common.sk how can i block a knee when Brad is triyng to pick-up a pawn?

I tried:

joint l_knee
{ offset 0 7.782680 0
channel XPos 0 lim 0.00 0.01
channel YPos 0 lim 0.00 0.01
channel ZPos 0 lim 0.00 0.01
channel Quat

and: 

joint l_knee
{ offset 0 0 0
channel XPos 0 lim 0.00 0.01
channel YPos 0 lim 0.00 0.01
channel ZPos 0 lim 0.00 0.01
channel Quat

and and a bunch of stuf, but nothing has change.

Thank you.

March 9, 2016
10:24 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

I just checked the code; there is no limit description for 'Quat' joints.

I suppose you could put in a controller (in Python) that enforces the limits, something like:

 

1. decompose the Quaternion into XYZ Euler angles

2. compare Euler angles to Euler angle limits

3. if limit is exceeded, restrict to limit 

 

Perhaps this should be native SmartBody functionality.

March 9, 2016
10:39 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Ok..

And can you give a clue to how to decompose the Quaternion into Euler angles?

Thanks for the help.

March 9, 2016
11:42 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

I don't have the Python function but some C++ code is here: (first convert the quaternion to a matrix):

 

 

inline euler_t eulerFrom3x3( const vector_t col[3] )

{
register gw_float ex_rad, ey_rad, ez_rad;

gw_float s = -col[2].y();
ex_rad = safe_asin( s );
if( ( 1.0 - fabs( s ) ) > epsilon6() ) {
ey_rad = atan2( col[2].x(), col[2].z() );
ez_rad = atan2( col[0].y(), col[1].y() );
}
else {
ey_rad = atan2( -col[0].z(), col[0].x() );
ez_rad = 0.0;
}
return( euler_t( DEG( ex_rad ), DEG( ey_rad ), DEG( ez_rad ) ) );
}

March 9, 2016
12:11 pm
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Thanks a lot. 🙂
Just one more question. I'm still a little bit confused about the herarchy of classes. So where can I put this code in order that when i call the reach engine it works in the common.sk skeleton?
I should create another class?

March 9, 2016
12:26 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

The least invasive way to do this is to create a Python-based controller something like this:

 

class MyController (PythonController):

   def init(self, pawn):
      print "Init..."

   def evaluate(self):

      # every time step, make sure that the joint adheres to limits

      # ......

myc = MyController()
# get the character
character = scene.getCharacter('char0')
# run this controller in position 17
character.addController(17, myc)

 

where the number '17' represents the order of evaluation of the controllers (thus, you could place it after the reach controller).

 

Ari

March 10, 2016
2:31 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Thank you for the help.

But unfortuly it is not working..

What is epsilon6() in your c++ code?

March 10, 2016
2:39 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

This was my attemp:

 

character = scene.getCharacter('ChrBrad0')
jointName1 = "l_knee"
joint1 = character.getSkeleton().getJointByName(jointName1)
x1 = joint1.getMatrixGlobal().getData(3,0)
y1 = joint1.getMatrixGlobal().getData(3,1)
z1 = joint1.getMatrixGlobal().getData(3,2)

euler_t = []
leng(euler_t) = 3
ex_rad = 0
ey_rad = 0
ez_rad = 0

from math import fabs

class MyController (PythonController):
def init(self, pawn):
def evaluate(self):
global ex_rad, ey_rad, ez_rad
s = -euler_t[2].y1
ex_rad = safe_asin(s)
if ((1.0-fabs(s)>epsilon6()):
ey_rad = atan2(euler_t[2].x1, euler_t[2].z1))
ez_rad = atan2(euler_t[2].y1), euler_t[2][1].y1)
ey_rad = atan2(-euler_t[0].z1, euler_t[0].x1)
return (euler_t(degrees(ex_rad), degrees(ey_rad), degrees(ez_rad)));

myc = MyController()
# get the character
character = scene.getCharacter('ChrBrad0')
# run this controller in position 17
character.addController(17, myc)

March 10, 2016
9:39 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

mbarros said
Thank you for the help.

But unfortuly it is not working..

What is epsilon6() in your c++ code?

Thats epsilon to 6 decimal places: .000001

March 10, 2016
9:51 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

This is what i've got.. And still not working. :/

 

character = scene.getCharacter('ChrBrad0')
jointName1 = "l_knee"
joint1 = character.getSkeleton().getJointByName(jointName1)
x1 = joint1.getMatrixGlobal().getData(3,0)
y1 = joint1.getMatrixGlobal().getData(3,1)
z1 = joint1.getMatrixGlobal().getData(3,2)

class MyController (PythonController):
def init(self, euler_t):
euler_t = [0.00, 0.00, 0.00]
ex_rad = 0
ey_rad = 0
ez_rad = 0
s = -euler_t[2].y1
s1 = 1.0 - fabs(s)
e = sys.float_info.epsilon
ex_rad = safe_asinh(s)
if s1 > e:
ey_rad = atan2(euler_t[2].x1, euler_t[2].z1)
ez_rad = atan2(euler_t[2].y1, euler_t[2][1].y1)
ey_rad = atan2(-euler_t[0].z1, euler_t[0].x1)
euler_t = [degrees(ex_rad), degrees(ey_rad), degrees(ez_rad)]

myc = MyController()
# get the character
character = scene.getCharacter('ChrBrad0')
# run this controller in position 17
character.addController(17, myc)

March 10, 2016
4:57 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Try something like this:

 

import math

def degrees(rad):
return rad * 180.0 * 3.14159

class MyController (PythonController):
def evaluate(self):
character = scene.getCharacter('ChrBrad')
jointName1 = "l_knee"
joint1 = character.getSkeleton().getJointByName(jointName1)
mat = joint1.getMatrixGlobal()
col1 = SrVec()
col1.setData(0, mat.getData(0,0))
col1.setData(1, mat.getData(0,1))
col1.setData(2, mat.getData(0,2))

col2 = SrVec()
col2.setData(0, mat.getData(1,0))
col2.setData(1, mat.getData(1,1))
col2.setData(2, mat.getData(1,2))

col3 = SrVec()
col3.setData(0, mat.getData(2,0))
col3.setData(1, mat.getData(2,1))
col3.setData(2, mat.getData(2,2))

euler_t = [0.00, 0.00, 0.00]
ex_rad = 0
ey_rad = 0
ez_rad = 0
s = -col3.getData(1)
s1 = 1.0 - math.fabs(s)
e = sys.float_info.epsilon
ex_rad = math.asinh(s)
if s1 > e:
ey_rad = math.atan2(col3.getData(0), col3.getData(2))
ez_rad = math.atan2(col3.getData(1), col2.getData(1))
else:
ey_rad = math.atan2(-col1.getData(2), col1.getData(0))
euler_t = [degrees(ex_rad), degrees(ey_rad), degrees(ez_rad)]
print euler_t

myc = MyController()
# get the character
character = scene.getCharacter('ChrBrad')
# run this controller in position 17
character.addController(17, myc)

character.removeController(myc)

March 11, 2016
8:43 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Thanks one more time. 🙂

That gives me no error.

But when i try to see the values of euler_t, it says that euler_t it is not defined.

March 11, 2016
5:46 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Sorry, don't add the last line:

 

character.removeController(myc)

 

The tabs are missing on the code that I sent you which might be giving you the wrong results. Make sure your code looks something like this:

class MyController (PythonController):
   def evaluate(self):
      character = scene.getCharacter('ChrBrad')
      jointName1 = "l_knee"
      joint1 = character.getSkeleton().getJointByName(jointName1)
      mat = joint1.getMatrixGlobal()
      col1 = SrVec()
      col1.setData(0, mat.getData(0,0))
      col1.setData(1, mat.getData(0,1))
      col1.setData(2, mat.getData(0,2))
 
      col2 = SrVec()
      col2.setData(0, mat.getData(1,0))
      col2.setData(1, mat.getData(1,1))
      col2.setData(2, mat.getData(1,2)) 

      col3 = SrVec()
      col3.setData(0, mat.getData(2,0))
      col3.setData(1, mat.getData(2,1))
      col3.setData(2, mat.getData(2,2)) 
 
      euler_t = [0.00, 0.00, 0.00]
      ex_rad = 0
      ey_rad = 0
      ez_rad = 0
      s = -col3.getData(1)
      s1 = 1.0 - math.fabs(s)
      e = sys.float_info.epsilon
      ex_rad = math.asinh(s)
      if s1 > e:
         ey_rad = math.atan2(col3.getData(0), col3.getData(2))
         ez_rad = math.atan2(col3.getData(1), col2.getData(1))
      else:
         ey_rad = math.atan2(-col1.getData(2), col1.getData(0))
      euler_t = [degrees(ex_rad), degrees(ey_rad), degrees(ez_rad)]
      print euler_t 

March 12, 2016
4:31 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Thank you for you patience.

I have the code just like you. 

I don't know what is wrong.. 

March 14, 2016
3:31 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Now, it's always printing values of euler_t.

March 14, 2016
5:57 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Sorry I don't have time to work on this for you right now;

the idea is to extract the Euler angles, clamp to the limits, then reconstruct a quaternion and set that back on the character.

March 15, 2016
2:22 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Ok. Thank you for your time.

March 15, 2016
4:51 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Can you answer me one more question?
What really does joint.setOff(SrVec(...)))?
It puts new angles in the joint?
If not. What can I use for that?

Thanks for the attencion.

March 15, 2016
6:16 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

It sets the offset from the parent joint, mostly used during construction of the joint hierarchy.

March 16, 2016
11:38 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Ok. And what about setquat()?
Does it changes the angles of the joint?
If so, how can i use it? I tried some things and nothing.

March 18, 2016
3:36 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

One of the best ways to set the values on a joint is to use the call: self.setChannelQuat() or self.setChannelQuatGlobal() within the controller.

 

Ari

March 23, 2016
2:19 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Right.
Can you give an example of usage of self.setChannelQuat() ?

Thank you.

March 24, 2016
5:45 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Within a controller you can do something like:

 

class MyController (PythonController):

   def evaluate(self):

      bodyRot = SrQuat() # identity quat
      axis = rot.getAxis()
      angle = rot.getAngle()
      angle = angle * .1
      bodyRot.setData(0, rot.getData(0) * .2)
      bodyRot.setAxisAngle(axis, angle)
      self.setChannelQuatLocal('base', bodyRot)

 

myc = MyController()
character = scene.getCharacter('char0')
character.addController(17, myc)

March 28, 2016
1:40 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Ok.

But, what is rot?

March 28, 2016
3:52 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

I tried this:

bodyRot = SrQuat()
axis = bodyRot.getAxis() #Gets the axis of the quaternation.
angle = bodyRot.getAngle() #Gets the angle of the quaternion.
angle = angle * .1
bodyRot.setData(0, bodyRot.getData(0) * .2)
bodyRot.setAxisAngle(axis, angle)
self.setChannelQuatLocal('base', bodyRot)

And it says:

'MyController' object has no attribute 'setChannelQuatLocal'

April 2, 2016
9:26 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Which version are you using? 

The latest code is in the source code repository. Perhaps the version you are using doesn't include that function.

 

Ari

April 4, 2016
3:29 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

The r6140 version. Is the latest version, right? It seems to have that function.

Well, i'm going to other options. Can you tell me where are the definitions of bml, like walking, gazing, etc?

 

Thank you for your time.

April 4, 2016
10:06 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

My mistake; there is a setChannelQuat() and setChannelQuatGlobal(). The first one sets the local space quaternion.

 

The options for BML should be in the SmartBody manual (pdf at the top level of the SmartBody source tree).

Ari

April 4, 2016
10:27 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

I don't want the options. I want definitions. How do you define locomotion, gaze and etc.

Where is the code that is all the BML defined?
For instance, where can i find imlemented the function gaze?

bml.execBML('ChrBrad','<gaze target="obj1"/>')

April 4, 2016
11:32 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

The implementations are generally done via controllers; there is a controllers/ folder you can peruse.

April 4, 2016
11:50 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Ok thank you.

And if i want to add a new function, for example a different type of locomotion.. All i have to do is to create another controller in that folder?

April 4, 2016
12:05 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Yes, and then you should add it to the list of standard controllers in this function:

 

void SbmCharacter::createStandardControllers()

April 7, 2016
9:43 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Hi.
After I created a new type of locomotion, how could i compile the code and see that was working?

Thank you.

April 8, 2016
9:56 am
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

You'll need to be able to build the source code using Visual Studio (or linux or osx) and then add the file to the controllers/ folder, add the controller to the ::createStandardControllers() function, and you should then be able to see the results.

 

Ari

April 11, 2016
10:46 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Hi.
I'm continuing with the rotations of joints.
I'm still not understand some aspects..

Can you tell me why i get the value : 6,..... when i do this?
Where can i see the value of the rotation? In this case 90 degrees..

character = scene.getCharacter('ChrBrad0')
targetJoint = character.getSkeleton().getJointByName('skullbase')

targetJoint.setPrerotation(SrQuat(SrVec(1,0,0),3.1415/2))
quat = targetJoint.getQuat()
angle = quat.getAngle()
print angle

April 14, 2016
12:21 pm
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

Hi,

I tried your code with ChrBrad in rest pose. It returns 1.57313907146, which is correctly 90 degrees in radian.

Did you apply additional motions on the character ? You can provide me your setup script so I can test more clearly about your problem.

Andrew 

April 15, 2016
12:07 pm
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Thanks but I think that is solved.

Sorry to ask you again. But about the definitions of BML, I think that i miss something.
Can you tell me more specifically where is the implementation of all the attributes?
All the tags?

For example, in tag locomotion you have an attribute that is speed. Where is speed and the rest of attributes implemented?

April 15, 2016
12:23 pm
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

The attribute is defined in BMLDef.h/.cpp. It defines the names of each attributes to be parsed.

As for the actual implementation, you can usually find how it's being used by a controller in its corresponding bml_*.cpp. For example, you can check 'bml_locomotion.hpp/.cpp' for how the attributes of locomotion BML are parsed and applied in locomotion controller.

Hope this helps and let me know if you have any questions.

Andrew

April 18, 2016
1:27 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Thank you very much.
I'm working on extending the language bml.
For instance, if i want to add an attribute in locomotion like 'lenght of the step' the things that i need to do are:

Add in BMLDefs:

XMLCh* BMLDefs::ATTR_LENGHT_STEPS = NULL;

Add in bml_locomotion the code for that attribute.

And then compile in visual studio? And i'll be able to test via pyhton?

Thanks for the attention.

April 18, 2016
11:13 am
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

Hi,

You will also need to define the tag name as "ATTR_LENGHT_STEPS = XMLString::transcode("step_length");" in BMLDef.cpp. 

This would add this new "step_length" tag in BML locomotion during parsing. Thus now you can add code to handle this tag in bml_locomotion.cpp and also adjust the behvaior in locomotion controller code accordingly. 

Let me know if you have any other questions. 

Andrew

April 19, 2016
3:20 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Ok. Now, imagine this.
I want that the agent walks without moving the knee.
What do you recommend? It is best to create a new attribute or in the definition of walking, simply change the angles of the joints?

April 21, 2016
10:19 am
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

 I don't think there is an easy way to change the locomotion controller to achieve this. You can either implement a new locomotion controller that move the character without moving the knees. Or you can reuse the current example-based locomotion controller and provides a different sets of example motions that do not have knee movements.

Andrew

April 22, 2016
7:30 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

Right.
My doubt what should I change?
In which part of the code is the movement of the legs, foot contact with the ground, speed of the joints, angle of the joints, and all that stuff that makes the movement of walking..
I've been looking the code in me_ct_locomotion.cpp.. And in some parts seems that you 'the walking' with an animation, in other parts seems not.

I'm a little bit confused if i really can do what i want and how should i do it..

April 22, 2016
9:21 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

I've been looking the me_ct_locomotion_analysis.cpp and i see the there is a 'limb' part where you add a support joint..
So there is various places where you define the walking?

Did you have the time to explain me how all the process of walking really works?
Thanks for the attencion.

April 22, 2016
9:40 am
Avatar
Member
Members
Forum Posts: 28
Member Since:
February 23, 2016
sp_UserOfflineSmall Offline

In other words.. Where is this defined?

http://www.biomotionlab.ca/Dem.....alker.html

April 25, 2016
10:37 am
Avatar
Admin
Forum Posts: 52
Member Since:
August 8, 2012
sp_UserOfflineSmall Offline

Hi,

The current locomotion in SmartBody is purely data-driven and we do not apply physical or heuristic control over joint angles and speed, nor handling ground contact. What you are referring to are legacy codes of an earlier implementation, which is a semi-procedural locomotion controller which handles finer per joint control and speed procedurally. However, it is not being actively updated anymore after we switch to current data-driven model. 

The current locomotion uses parameterized animation interpolations and the interpolation parameters are controlled by the steering engine to move the character around. So all the character movements and walking/running motions are generated by adjusting the blending weights of different walking, jogging, and turning animations. 

You can find more details in the source code. You can start from "SBAnimationBlend" class for motion interpolation, and the "PRAISteeringAgent" class for steering control. 

Andrew

Forum Timezone: America/Los_Angeles

Top Posters:

jwwalker: 80

jyambao: 52

rbaral: 47

adiaz: 30

WargnierP: 29

lucky7456969: 28

mbarros: 28

avida.matt: 26

JonathanW: 24

laguerre: 23

Member Stats:

Guest Posters: 67

Members: 101752

Moderators: 3

Admins: 4

Forum Stats:

Groups: 1

Forums: 5

Topics: 462

Posts: 2407