## For instruction on writing tutorials
## http://www.ros.org/wiki/WritingTutorials
####################################
##FILL ME IN
####################################
## for a custom note with links:
## note =
## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links 
## note.0= Writing a Stiffness Controller [[ee_cart_imped/Tutorials/Writing a Stiffness Controller (C++)|(c++)]],[[ee_cart_imped/Tutorials/Writing a Stiffness Controller (Python)|(python)]] 
## descriptive title for the tutorial
## title = Running the Controller
## multi-line description to be displayed in search 
## description = Explains how to how to run a force controlled trajectory.
## the next tutorial description (optional)
## next = 
## links to next tutorial (optional)
## next.0.link= Writing a Force Controller [[ee_cart_imped/Tutorials/Writing a Force Controller (C++)|(c++)]]
## next.1.link=[[ee_cart_imped/Tutorials/Writing a Force Controller (Python)|(python)]]
## what level user is this tutorial for 
## level= BeginnerCategory
## keywords = force, compliance, impedance, stiffness, controller, pr2 arms
####################################

<<IncludeCSTemplate(TutorialCSHeaderTemplate)>>

<<TableOfContents(4)>>

If you have not already, you must first [[ee_cart_imped#Downloading|download the ee_cart_imped stack]].

=== Updating the Controller and Action Files ===
Since the controller and action are not kept within the ROS stacks, you may want to update them manually to ensure you have the most recent version:
{{{
roscd ee_cart_imped
svn update
}}}

=== Compiling ===

If you have not yet done so, rosmake the controller:
{{{
rosmake ee_cart_imped_control
}}}

Now rosmake the package you made in the previous tutorial (if using the electric release, the package has no direct dependency on ee_cart_imped_control which is why they must be made separately):
{{{
rosmake ee_cart_imped_tutorial
}}}
This will compile the [[ee_cart_imped_msgs]], and [[ee_cart_imped_action]] packages.  If you went through the [[ee_cart_imped/Tutorials/Writing a Stiffness Controller (C++)|previous tutorial in C++]], this will compile the code you wrote in that tutorial as well.  

=== Starting the Controller and Action Server ===

'''You must wait for the controller build to complete before starting the robot or simulator!'''

Once the build is complete, if you are working in simulation, open a new shell and run
{{{
roslaunch pr2_gazebo pr2_empty_world.launch
}}}

If you are working on the PR2, restart the robot so that it will recognize the new controller:
{{{
robot start
}}}
(If running cturtle, you need to use the -e option.)  Note that the first time the [[ee_cart_imped_control]] package is built, you must re-start the robot or simulator after the build completes.  If you have already built the controller, however, and made no changes since the time of the build, it is not necessary to re-start the robot or simulator.  In general use, you will compile the [[ee_cart_imped_control]] package once on download, at which time the robot or simulator must be re-started.  After that, you need not re-start the robot or simulator when running the controller.

Once the simulator is up or the robot is restarted, in a new shell type
{{{
roslaunch ee_cart_imped_action r_arm_cart_imped_action.launch
}}}
This stops the usual controller for the right arm and starts the ee_cart_imped controller and action server for the right arm.  To use the controller for the left arm, look at the [[ee_cart_imped_action]]/launch/l_arm_cart_imped.launch file.  To launch the controller for both arms, you can use the [[ee_cart_imped_launch]]/launch/ee_cart_imped_action.launch file.  If you got the error
{{{
ERROR: cannot launch node of type [ee_cart_imped_action/ee_cart_imped_action]: can't locate node [ee_cart_imped_action] in package [ee_cart_imped_action]
}}}
or the robot halted when you launched it, you likely did not wait for the build to complete before starting the robot.  Try re-starting the robot and launching again.  If the trouble persists, see the [[ee_cart_imped/Troubleshooting|troubleshooting page]] for common errors that could lead to the problem. 

The ee_cart_imped controller is now running in the right arm.  At present, the controller is attempting to hold the end effector at a constant Cartesian point.  If you are working with the PR2, you can test if the new controller is indeed controlling the right arm by manipulating the arm joints without moving the end effector.  Unlike under the standard controller (which should still be running on the left arm for comparison), so long as the end effector does not move, there should not be much resistance to moving the other joints:

<<Youtube(Oywmanwnlrc)>>

=== Running the Trajectory ===

Now you can try running the example we created.  Pull up a new terminal.  If you did the [[ee_cart_imped/Tutorials/Writing a Stiffness Controller (C++)|previous tutorial in C++]], type:
{{{
rosrun ee_cart_imped_tutorial stiffness_control
}}}
If you did the [[ee_cart_imped/Tutorials/Writing a Stiffness Controller (Python)|previous tutorial in python]], type:
{{{
rosrun ee_cart_imped_tutorial stiffness_control.py
}}}
You should see the trajectory execute.

With this controller, the last point will be held with the desired force or stiffness.  In this case, this means that there will still be a light stiffness in the ''x'' direction.  This should be very noticeable if you attempt to move the PR2 gripper.  It will be easy to move it in the ''x'' direction (towards or away from the robot), but hard to move in any other direction or to turn.

<<Youtube(AfRUwsIOvqo)>>

=== Force Control ===
Now that we have written and run a stiffness controller, we can use the [[ee_cart_imped]] stack to also run a force-controlled trajectory [[ee_cart_imped/Tutorials/Writing a Force Controller (C++)|(c++)]], [[ee_cart_imped/Tutorials/Writing a Force Controller (Python)|(python)]].

## AUTOGENERATED DO NOT DELETE 
## TutorialCategory
## FILL IN THE STACK TUTORIAL CATEGORY HERE