Whole Body control API

Overview | API | Tutorial

See also


Method list

class ALMotionProxy
void ALMotionProxy::wbEnable(const bool& isEnabled)

User friendly Whole Body API: enables Whole Body Balancer. It’s a Generalized Inverse Kinematics which deals with cartesian control, balance, redundancy and task priority. The main goal is to generate and stabilized consistent motions without precomputed trajectories and adapt nao’s behaviour to the situation. The generalized inverse kinematic problem takes in account equality constraints (keep foot fix), inequality constraints (joint limits, balance, ...) and quadratic minimization (cartesian / articular desired trajectories). We solve each step a quadratic programming on the robot.

Parameters:
  • isEnabled – Active / Disactive Whole Body Balancer.

almotion_wbenable.cpp

#include <iostream>
#include <alproxies/almotionproxy.h>

int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cerr << "Usage: motion_wbenable pIp"
              << std::endl;
    return 1;
  }
  const std::string pIp = argv[1];

  AL::ALMotionProxy motion(pIp);

  // Example showing how to active Whole Body Balancer.
  bool isEnabled = true;
  motion.wbEnable(isEnabled);
  std::cout << "Whole body enabled." << std::endl;

  isEnabled = false;
  motion.wbEnable(isEnabled);
  std::cout << "Whole body disabled." << std::endl;

  return 0;
}

almotion_wbenable.py

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_wbenable.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)

proxy.setStiffnesses("Body", 1.0)
proxy.walkInit()
proxy.wbEnable(True)

# Example showing how to enable Whole Body Balancer.
isEnabled = True
proxy.wbEnable(isEnabled)

# Example showing how to disable Whole Body Balancer.
isEnabled = False
proxy.wbEnable(isEnabled)
void ALMotionProxy::wbFootState(const std::string& stateName, const std::string& supportLeg)

UserFriendly Whole Body API: set the foot state: fixed foot, constrained in a plane or free.

Parameters:
  • stateName – Name of the foot state. “Fixed” set the foot fixed. “Plane” constrained the Foot in the plane. “Free” set the foot free.
  • supportLeg – Name of the foot. “LLeg”, “RLeg” or “Legs”.

almotion_wbfootstate.cpp

#include <iostream>
#include <alproxies/almotionproxy.h>

int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cerr << "Usage: motion_wbfootstate pIp"
              << std::endl;
    return 1;
  }
  const std::string pIp = argv[1];

  AL::ALMotionProxy motion(pIp);

  std::vector<float> stiffnesses = motion.getStiffnesses("Body");
  if (stiffnesses[0] < 0.5f) {
    std::cerr << "Warning: this example will have no effect. "
              << "Robot must be stiff and standing." << std::endl;
    return 1;
  }

  bool isEnabled = true;
  motion.wbEnable(isEnabled);

  // Example showing how to fix the feet.
  std::string stateName = "Fixed";
  std::string supportLeg = "Legs";
  motion.wbFootState(stateName, supportLeg);
  std::cout << supportLeg << " " << stateName << std::endl;

  // Example showing how to fix the left leg and constrained in a plane the right leg.
  motion.wbFootState("Fixed", "LLeg");
  motion.wbFootState("Plane", "RLeg");
  std::cout << "LLeg Fixed, RLeg Plane" << std::endl;

  // Example showing how to fix the left leg and keep free the right leg.
  motion.wbFootState("Fixed", "LLeg");
  motion.wbFootState("Free", "RLeg");
  std::cout << "LLeg Fixed, RLeg Free" << std::endl;

  isEnabled = false;
  motion.wbEnable(isEnabled);

  return 0;
}

almotion_wbfootstate.py

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_wbfootstate.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)

proxy.setStiffnesses("Body", 1.0)
proxy.walkInit()
proxy.wbEnable(True)

# Example showing how to fix the feet.
print "Feet fixed."
stateName = "Fixed" 
supportLeg = "Legs" 
proxy.wbFootState(stateName, supportLeg)

# Example showing how to fix the left leg and constrained in a plane the right leg.
print "Left leg fixed, right leg in a plane."
proxy.wbFootState("Fixed", "LLeg") 
proxy.wbFootState("Plane", "RLeg")

# Example showing how to fix the left leg and keep free the right leg.
print "Left leg fixed, right leg free"
proxy.wbFootState("Fixed", "LLeg") 
proxy.wbFootState("Free", "RLeg")

proxy.wbEnable(False)
void ALMotionProxy::wbEnableBalanceConstraint(const bool& isEnable, const std::string& supportLeg)

UserFriendly Whole Body API: enable to keep balance in support polygon.

Parameters:
  • isEnable – Enable NAO to keep balance.
  • supportLeg – Name of the support leg: “Legs”, “LLeg”, “RLeg”.

almotion_wbenablebalanceconstraint.cpp

#include <iostream>
#include <alproxies/almotionproxy.h>

int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cerr << "Usage: motion_wbenablebalanceconstraint pIp"
              << std::endl;
    return 1;
  }
  const std::string pIp = argv[1];

  AL::ALMotionProxy motion(pIp);

  // Example showing how to Constraint Balance Motion.
  bool isEnable = true;
  std::string supportLeg  = "Legs";
  motion.wbEnableBalanceConstraint(isEnable, supportLeg);
  std::cout << "Enabled whole body balance constraint on " << supportLeg << std::endl;

  isEnable = false;
  motion.wbEnableBalanceConstraint(isEnable, supportLeg);
  std::cout << "Disabled whole body balance constraint on " << supportLeg << std::endl;

  return 0;
}

almotion_wbenablebalanceconstraint.py

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_wbenablebalanceconstraint.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)

proxy.setStiffnesses("Body", 1.0)
proxy.walkInit()
proxy.wbEnable(True)

# Example showing how to Constraint Balance Motion. 
isEnable   = True 
supportLeg = "Legs" 
proxy.wbEnableBalanceConstraint(isEnable, supportLeg)

proxy.wbEnable(False)
void ALMotionProxy::wbGoToBalance(const std::string& supportLeg, const float& duration)

Advanced Whole Body API: “Com” go to a desired support polygon. This is a blocking call.

Parameters:
  • supportLeg – Name of the support leg: “Legs”, “LLeg”, “RLeg”.
  • duration – Time in seconds.

almotion_wbgotobalance.cpp

#include <iostream>
#include <alproxies/almotionproxy.h>

int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cerr << "Usage: motion_wbgotobalance pIp"
              << std::endl;
    return 1;
  }
  const std::string pIp = argv[1];

  AL::ALMotionProxy motion(pIp);

  std::vector<float> stiffnesses = motion.getStiffnesses("Body");
  if (stiffnesses[0] < 0.5f) {
    std::cerr << "Warning: this example will have no effect. "
              << "Robot must be stiff and standing." << std::endl;
    return 1;
  }

  bool isEnabled = true;
  motion.wbEnable(isEnabled);

  // Example showing how to com go to LLeg.
  std::string supportLeg = "LLeg";
  float duration         = 2.0f;
  motion.wbGoToBalance(supportLeg, duration);

  isEnabled = false;
  motion.wbEnable(isEnabled);

  return 0;
}

almotion_wbgotobalance.py

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_wbgotobalance.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)

proxy.setStiffnesses("Body", 1.0)
proxy.walkInit()
proxy.wbEnable(True)

# Example showing how to com go to LLeg.
supportLeg = "LLeg"
duration   = 2.0
proxy.wbGoToBalance(supportLeg, duration)

proxy.wbEnable(False)
void ALMotionProxy::wbEnableEffectorControl(const std::string& effectorName, const bool& isEnabled)

UserFriendly Whole Body API: enable whole body cartesian control of an effector.

Parameters:
  • effectorName – Name of the effector : “Head”, “LArm” or “RArm”. NAO goes to posture init. He manages his balance and keep foot fix. “Head” is controlled in rotation. “LArm” and “RArm” are controlled in position.
  • isEnabled – Active / Disactive Effector Control.

almotion_wbenableeffectorcontrol.cpp

#include <iostream>
#include <alproxies/almotionproxy.h>

int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cerr << "Usage: motion_wbenableeffectorcontrol pIp"
              << std::endl;
    return 1;
  }
  const std::string pIp = argv[1];

  AL::ALMotionProxy motion(pIp);

  // Example showing how to active Head tracking.
  std::string effectorName = "Head";
  bool isEnabled = true;
  motion.wbEnableEffectorControl(effectorName, isEnabled);
  std::cout << "Enabled whole body effector " << effectorName << " control"
            << std::endl;

  isEnabled = false;
  motion.wbEnableEffectorControl(effectorName, isEnabled);
  std::cout << "Disabled whole body effector " << effectorName << " control"
            << std::endl;

  return 0;
}

almotion_wbenableeffectorcontrol.py

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_wbenableeffectorcontrol.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)

proxy.setStiffnesses("Body", 1.0)
proxy.wbEnable(True)

# Example showing how to active Head tracking.
effectorName = 'Head' 
isEnabled = True 
proxy.wbEnableEffectorControl(effectorName, isEnabled)
print "Enabled head effector control"

proxy.wbEnable(False)
void ALMotionProxy::wbSetEffectorControl(const std::string& effectorName, const AL::ALValue& targetCoordinate)

UserFriendly Whole Body API: set new target for controlled effector. This is a non-blocking call.

Parameters:
  • effectorName – Name of the effector : “Head”, “LArm” or “RArm”. NAO goes to posture init. He manages his balance and keep foot fix. “Head” is controlled in rotation. “LArm” and “RArm” are controlled in position.
  • targetCoordinate – “Head” is controlled in rotation (WX, WY, WZ). “LArm” and “RArm” are controlled in position (X, Y, Z). TargetCoordinate must be absolute and expressed in SPACE_NAO. If the desired position/orientation is unfeasible, target is resize to the nearest feasible motion.

almotion_wbseteffectorcontrol.cpp

#include <iostream>
#include <alproxies/almotionproxy.h>

int main(int argc, char **argv)
{
  if (argc < 2) {
    std::cerr << "Usage: motion_wbseteffectorcontrol pIp"
              << std::endl;
    return 1;
  }
  const std::string pIp = argv[1];

  AL::ALMotionProxy motion(pIp);

  std::vector<float> stiffnesses = motion.getStiffnesses("Body");
  if (stiffnesses[0] < 0.5f) {
    std::cerr << "Warning: this example will have no effect. "
              << "Robot must be stiff and standing." << std::endl;
    return 1;
  }

  bool isEnabled = true;
  motion.wbEnable(isEnabled);

  // Example showing how to set orientation target for Head tracking.
  std::string effectorName = "Head";
  AL::ALValue targetCoordinate = AL::ALValue::array(0.1f, 0.0f, 0.0f);
  motion.wbSetEffectorControl(effectorName, targetCoordinate);

  isEnabled = false;
  motion.wbEnable(isEnabled);

  return 0;
}

almotion_wbseteffectorcontrol.py

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python motion_wbseteffectorcontrol.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALMotion", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALMotion"
    print "Error was: ",e
    sys.exit(1)
    
proxy.setStiffnesses("Body", 1.0)
proxy.wbEnable(True)

# Example showing how to set orientation target for Head tracking. 
effectorName = "Head" 
targetCoordinate = [0.1, 0.0, 0.0] 
proxy.wbSetEffectorControl(effectorName, targetCoordinate)

proxy.wbEnable(False)