# SoftBank Robotics documentation What's new in NAOqi 2.8?

# Stiffness control API

NAOqi Motion - Overview | API

## Method list

class `ALMotionProxy`

- `ALMotionProxy::wakeUp`
- `ALMotionProxy::rest`
- `ALMotionProxy::robotIsWakeUp`
- `ALMotionProxy::stiffnessInterpolation`
- `ALMotionProxy::setStiffnesses`
- `ALMotionProxy::getStiffnesses`

## Event list

- `robotIsWakeUp()`
- `ALMotion/Stiffness/wakeUpStarted()`
- `ALMotion/Stiffness/wakeUpFinished()`
- `ALMotion/Protection/DisabledDevicesChanged()`

## Methods

bool `ALMotionProxy::``wakeUp`()

  Returns: | True if the call succeeded, False otherwise.

  The robot wakes up: sets Motor on and, if needed, goes to initial position. If the robot is already stiffened, the call returns True immediately.

  `almotion_wakeUp.py`

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use wakeUp Method"""

      import qi
      import argparse
      import sys
      import time

      def main(session):
          """
          This example uses the wakeUp method.
          """
          # Get the service ALMotion.

          motion_service  = session.service("ALMotion")

          motion_service.wakeUp()

          # print motion state
          print motion_service.getSummary()
          time.sleep(4.0)

          # Go to rest position
          motion_service.rest()

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

void `ALMotionProxy::``rest`()

  The robot rests: goes to a relaxed and safe position and sets Motor off. For example, H25 or H21 goes to the Crouch posture and sets the Stiffness off.

  `almotion_rest.py`

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use rest Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the rest method.
          """
          # Get the services ALMotion & ALRobotPosture.

          motion_service  = session.service("ALMotion")
          posture_service = session.service("ALRobotPosture")

          # Wake up robot
          motion_service.wakeUp()

          # Send robot to Pose Init
          posture_service.goToPosture("StandInit", 0.5)

          # Go to rest position
          motion_service.rest()

          # print motion state
          print motion_service.getSummary()

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

bool `ALMotionProxy::``robotIsWakeUp`()

  Returns: | True if the robot is awake.

void `ALMotionProxy::``stiffnessInterpolation`(const AL::ALValue& names, const AL::ALValue& stiffnessLists, const AL::ALValue& timeLists)

  Interpolates one or multiple joints to a targeted stiffness or along timed trajectories of stiffness. This is a blocking call.

  Parameters: | names – Name or names of joints, chains, “Body”, “JointActuators”, “Joints” or “Actuators”. stiffnessLists – An stiffness, list of stiffnesses or list of list of stiffnesses timeLists – A time, list of times or list of list of times.

  `almotion_stiffnessInterpolation.py`

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use stiffnessInterpolation Method"""

      import qi
      import argparse
      import sys
      import time

      def main(session):
          """
          This example uses the stiffnessInterpolation method.
          """
          # Get the service ALMotion.

          motion_service  = session.service("ALMotion")
          motion_service.wakeUp()

          # Example showing how to interpolate to minimum stiffness in 1 second
          names  = 'LArm'
          stiffnessLists  = 0.0
          timeLists  = 1.0
          motion_service.stiffnessInterpolation(names, stiffnessLists, timeLists)

          time.sleep(1.0)

          # Example showing a stiffness trajectory for a single joint
          names  = ['LWristYaw']
          stiffnessLists  = [0.25, 0.5, 1.0, 0.0]
          timeLists  = [1.0, 2.0, 3.0, 4.0]
          motion_service.stiffnessInterpolation(names, stiffnessLists, timeLists)

          motion_service.rest()

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

void `ALMotionProxy::``setStiffnesses`(const AL::ALValue& names, const AL::ALValue& stiffnesses)

  Sets the stiffness of one or more joints. This is a non-blocking call.

  Parameters: | names – Names of joints, chains, “Body”, “JointActuators”, “Joints” or “Actuators”. stiffnesses – One or more stiffnesses between zero and one.

  `almotion_setstiffnesses.cpp`

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

      int main(int argc, char **argv)
      {
        std::string robotIp = "127.0.0.1";

        if (argc < 2) {
          std::cerr << "Usage: almotion_setstiffnesses robotIp "
                    << "(optional default \"127.0.0.1\")."<< std::endl;
        }
        else {
          robotIp = argv[1];
        }

        AL::ALMotionProxy motion(robotIp);

        // Example showing how to set the stiffness to 1.0.
        // Beware, doing this could be dangerous, it is safer to use the
        // stiffnessInterpolation method which takes a duration parameter.
        std::string names  = "Body";
        // If only one parameter is received, this is applied to all joints
        float stiffnesses  = 1.0f;
        motion.setStiffnesses(names, stiffnesses);

        return 0;
      }

  `almotion_setStiffnesses.py`

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use setStiffnesses Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the setStiffnesses method.
          """
          # Get the service ALMotion.

          motion_service  = session.service("ALMotion")

          # Example showing how to set the stiffness to 1.0.
          # Beware, doing this could be dangerous, it is safer to use the
          #   stiffnessInterpolation method which takes a duration parameter.
          names  = 'Head'
          # If only one parameter is received, this is applied to all joints
          stiffnesses  = 1.0
          motion_service.setStiffnesses(names, stiffnesses)

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

std::vector<float> `ALMotionProxy::``getStiffnesses`(const AL::ALValue& jointName)

  Gets stiffness of a joint or group of joints

  Parameters: | jointName – Name of the joints, chains, “Body”, “JointActuators”, “Joints” or “Actuators”.
  Returns: | One or more stiffnesses. 1.0 indicates maximum stiffness. 0.0 indicated minimum stiffness

  `almotion_getstiffnesses.cpp`

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

      int main(int argc, char **argv)
      {
        std::string robotIp = "127.0.0.1";

        if (argc < 2) {
          std::cerr << "Usage: almotion_getstiffnesses robotIp "
                    << "(optional default \"127.0.0.1\")."<< std::endl;
        }
        else {
          robotIp = argv[1];
        }

        AL::ALMotionProxy motion(robotIp);

        // Example showing how to get the Body stiffnesses
        std::string jointName = "Body";
        std::vector<float> stiffnesses = motion.getStiffnesses(jointName);

        std::cout << jointName << "stiffnesses: " << stiffnesses << std::endl;

        return 0;
      }

  `almotion_getStiffnesses.py`

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use getStiffnesses Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the getStiffnesses method.
          """
          # Get the service ALMotion.

          motion_service  = session.service("ALMotion")

          # Example showing how to get the Body stiffnesses
          jointName   = "Body"
          stiffnesses = motion_service.getStiffnesses(jointName)
          print "Body Stiffnesses:"
          print stiffnesses

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

## Events

Event: `"robotIsWakeUp"`
callback(std::string eventName, bool val, std::string subscriberIdentifier)

  Raised when the awake status of the robot changes.

  Parameters: | eventName (std::string) – “robotIsWakeUp” val – True if the robot is awake. False if the robot is not awake. subscriberIdentifier (std::string) –

Event: `"ALMotion/Stiffness/wakeUpStarted"`
callback(std::string eventName, bool val, std::string subscriberIdentifier)

  Raised at `ALMotionProxy::wakeUp` start.

  Parameters: | eventName (std::string) – “ALMotion/Stiffness/wakeUpStarted” val – always True. subscriberIdentifier (std::string) –

Event: `"ALMotion/Stiffness/wakeUpFinished"`
callback(std::string eventName, bool val, std::string subscriberIdentifier)

  Raised at `ALMotionProxy::wakeUp` finish.

  Parameters: | eventName (std::string) – “ALMotion/Stiffness/wakeUpFinished” val – always True. subscriberIdentifier (std::string) –

Event: `"ALMotion/Protection/DisabledDevicesChanged"`
callback(std::string eventName, AL::ALValue val, std::string subscriberIdentifier)

  Raised when devices availability changed. When a device is not available the stiffness and movement on this device are prohibited.

  The ALValue format is: [[std::string deviceName, bool disabled],...] deviceName could be a chainName or “Body”. In “Body” case ( [[“Body”, true]] ) `ALMotionProxy::wakeUp` is prohibited.

  Parameters: | eventName (std::string) – “ALMotion/Protection/DisabledDevicesChanged” val – An ALValue with the actual disabled devices status. Example: [[“LArm”, true]], [“Head”, false]] subscriberIdentifier (std::string) –

Glossary Site map Index Support Contact Legal Notices