Servo motion with python

How does one access the servo motion controls through python? When I setLinearVelocity() for a motion actuator it does so only for simple motion even though I have the logic bricks set to servo motion. setMotionType() was my best guess but it doesn’t actually exist. None of the documentation I can find explains how to switch the motion type to servo motion in python.

Are you even looking at the API?

.linV works:
http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_ObjectActuator-class.html#linV

Hi,
your question is a good one and being able to set the linear velocity through python is not enough to simulate servo motions.
I have asked the same thing in another thread : obj.pid, obj.ForceLimitX, obj.reference : can we have it?.

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

Quick answer

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

The quick answer is : with the actual API, there is no way to access servo motions through python without actuator.

cyborg_ar
that kind of things would be better implemented using python subclassing in 2.5, i don’t really see the need to bloat KX_GameObject with a servo controller.
(…)
It’s not hard to do the way you suggest, but the code doesn’t work like that, the servo controller is extra code that forms part of the Servo actuator class (KX_ObjectActuator), setLinearVelocity() is a call to KX_IPhysicsController::SetLinearVelocity() and every KX_GameObject already include an KX_IPhysicsController as the memeber m_pPhysicsController1, so adding the function was just about exposing the call. To make the servo be part of KX_GameObject would mean to relocate or… eww… copypaste the code to KX_GameObject or KX_IPhysicsController, and the interface you suggest is confusing and would allow only ONE servo per object. for thins kind of aditional stuff i’d prefer a “plug-in” architecture, something logic bricks do reasonably well, or using a class like the one i implemented in python. Or maybe just remove the servo option from the motion actuator and make it a physics constraint implemented in bullet.

After I took time to explain what I was looking for and why my question was not completely idiot, I got help from theSambassador and cyborg_ar who provided useful methods.

Here is the one I use, created “for me” by cyborg_ar :

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

Temporary solution

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

PIDServo(own, [0,0,1], True, [0, 0, 50])

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

Documentation

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

CLASS PIDServo

Constructor PIDServo(owner, target, local, pid, min_=[None,None,None], max_=[None,None,None])

Parameters:

  • owner (KX_GameObject): Object the servo class will be moving.
  • target ([X, Y, Z] List): Target speed for the servo
  • local (Boolean): Use local coordinates
  • pid ([P, I, D] List): Gains for the Proportional Integral and Derivative components
  • min_ ([X, Y, Z] List): Minimum bound for the action force, set a certain axis to None to turn it off (eg: [None, None, 1.54] would only limit the Z axis)
  • max_ ([X, Y, Z] List): Maximum bound for the action force, set a certain axis to None to turn it off (eg: [None, None, 1.54] would only limit the Z axis)

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

# Example blend

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

servo.blend

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

Note : still need to be done

# ‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
the ability to add a reference object is still missing.
And this is an important feature.
I have asked cyborg_ar and he said he would do it in his spare time. I don’t want to bother him by sending a reminder though.

Am I understanding this wrong or are you going through all this trouble only because you don’t wanna use a motion actuator attached to your object?

If my understanding is good, the answer is as easy as “why do we use python instead of xxx actuators?”
Because we can control more than one object from a central object.
Because we don’t need to add and set xxx acuators on xxx objects.

Using obj.setLinearVelocity() makes sense when we can control a lot of objects, right?
Then adding the servo control to that method is just logical and useful.
Also, I’m using the class mentioned above and it’s very far from being “such a trouble”.
This is just one line of Python.

At least, that’s why I asked in my previous thread.
I don’t know if the situation is the same for mike though.