<repo_name>ipa-jfh/robot_recorder_tutorials<file_sep>/record_trajectory/scripts/record
#!/usr/bin/env python

import rospy
from recordit.client import Recorder
from record_trajectory.move_trajectory import Manipulator


def main():
    rospy.init_node("recorder_example", anonymous=False)
    robot = Manipulator()
    robot.move_to_start()
    with Recorder():
        robot.move_trajectory()
        robot.move_to_start()


if __name__ == "__main__":
    main()

<file_sep>/README.md
# Tutorials for RecordIt

[![Build Status](https://travis-ci.org/ipa-jfh/robot_recorder_tutorials.svg?branch=master)](https://travis-ci.org/ipa-jfh/robot_recorder_tutorials)


## Related packages
- RecordIt: https://github.com/ipa-jfh/robot_recorder
- urdf-loader: https://github.com/gkjohnson/urdf-loaders
- urdf-animation: https://github.com/ipa-jfh/urdf-animation
- get_urdf_deps: https://github.com/ipa-jfh/get_urdf_deps

## 1. record_trajectory
### Result
<a href="https://ipa-jfh.github.io/urdf-animation/manipulator_ur5/result/">
    <img src="https://user-images.githubusercontent.com/17281534/46701301-8f98ac00-cc1f-11e8-8ee1-af82548453d2.gif" width="249" height="211" >
</a>

[>> See 3D animation](https://ipa-jfh.github.io/urdf-animation/manipulator_ur5/result/)

### How to

1. __Install example__

    ```bash
    # Optionally create a new ROS workspace
    mkdir -p ~/record_ws/src && cd ~/record_ws/src

    # Download repositories
    git clone https://github.com/ipa-jfh/robot_recorder_tutorial.git
    wstool init .
    wstool merge ~/record_ws/src/robot_recorder_tutorial/.rosinstall
    wstool up

    # Build workspace
    source /opt/ros/kinetic/setup.bash
    rosdep update && rosdep install --from-paths ~/record_ws/src --ignore-src
    cd ~/record_ws && catkin build
    source ~/record_ws/devel/setup.bash
    ```
2. __Record example__

    `(auto)`
    ```bash
    roslaunch record_trajectory record_auto.launch
    ```
    or
    `(manual - with RViz plugin)`
    TODO

    Files are saved to  `~/.ros/test_animation/`


3. __Create 3d web animation__

    Make sure to download/install nodejs/npm from https://nodejs.org/en/

    ```bash
    cd ~/.ros/test_animation/
    npm install # install all deps of the npm project
    cp -r ./node_modules/urdf-animation/template/* .
    npm start
    ```

4. __Create GIF__

    In the webpage press _Record recording_ at the control-box in upper right corner.
    Set _quality_ (lower is better) and _speed_ and then press _record()_.
    Done.

5. __Publish interactive web animation__

    To publish the web animation you have to bundle the js files first:

    ```bash
    cd ~/.ros/test_animation/
    npm run build # Might show errors which should be fine
    firefox ~/.ros/test_animation/result/index.html # test
    ```

    The folder `./result` has the self-contained webpage, which you can host e.g. on [gh-pages](https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/).



<file_sep>/record_trajectory/scripts/execute
#!/usr/bin/env python

import rospy
from record_trajectory.move_trajectory import Manipulator


def main():
    rospy.init_node("recorder_example", anonymous=False)
    robot = Manipulator()

    while not rospy.is_shutdown():
        robot.move_trajectory()


if __name__ == "__main__":
    main()

<file_sep>/record_trajectory/CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(record_trajectory)

find_package(catkin REQUIRED)
catkin_package()
catkin_python_setup()

catkin_install_python(PROGRAMS scripts/execute
    DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

install(DIRECTORY launch urdf
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})<file_sep>/record_trajectory/src/record_trajectory/move_trajectory.py
#!/usr/bin/env python

# This is script is solely for simulation!
# Robot and RecordIt has to be launched prior to this script.

import sys
import rospy
import moveit_commander
from moveit_msgs.msg import MoveGroupAction
from actionlib import SimpleActionClient


class ManipulatorBase:
    def __init__(self, move_group):
        moveit_commander.roscpp_initialize(sys.argv)
        robot = moveit_commander.RobotCommander()
        self.group = moveit_commander.MoveGroupCommander(move_group)
        self.waypoints = []
        self.wait = 0.0

    def move_to(self, joint_goal):
        self.group.go(joint_goal, wait=True)

    def move_to_start(self):
        self.move_to(self.waypoints[0])

    def move_trajectory(self):
        for wp in self.waypoints:
            if rospy.is_shutdown():
                break
            self.move_to(wp)
            rospy.sleep(self.wait)


class Manipulator(ManipulatorBase):
    def __init__(self):
        move_group = rospy.get_param("~move_group", "manipulator")

        ManipulatorBase.__init__(self, move_group)
        self.wait = rospy.get_param("~wait", 0.1)
        self.waypoints = rospy.get_param(
            "~waypoints",
            [
                [-5.1, -1.1, 0.8, -1.0, 1.5, -6.0],
                [-5.2, -1.0, 2.1, -2.5, 1.9, -5.5],
                [-4.9, -0.7, 0.8, -1.7, 1.6, -5.9],
            ],
        )
