Skip to content

Trajectory recording and playback

This page contains information on all functions present within trajectory_recording.py and aims to give a clear understanding both of what these functions do and the requirements for any data to be input into them.

These functions allow the user to record and playback specific trajectories for the arm.

Functions

trajectory_recording

Source code in actions\trajectory_recording.py
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
class trajectory_recording():

    def __init__(self, arm:XArmAPI):
        self.arm = arm

    def get_record_seconds(self):
        """
        Get record seconds

        Note:
            1. Only available if firmware_version >= 2.4.0
            2. Only valid during recording or after recording but before saving

        Returns:
            out (tuple[int, float]): tuple((code, seconds)), returned result is only corrent when code is 0.

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            seconds (float): The actual duration of the recorded trajectory
        """
        ret = self.arm.get_common_info(50, return_val=True)
        return ret

    def save_record_trajectory(self, filename, wait=True, timeout=5, **kwargs):
        """
        Save the trajectory you just recorded

        Note:
            1. This interface relies on Firmware 1.2.0 or above

        Args:
            filename: The name to save

                1. Only strings consisting of standard English characters or numbers are supported, with a maximum length of 50.

                2. The trajectory will be saved in the controller box.

                3. This action will overwrite a trajectory with the same name

                4. Empty the trajectory in memory after saving, so repeated calls will cause the recorded trajectory to be covered by an empty trajectory.

            wait: Whether to wait for saving, default is True

            timeout: Timeout waiting for saving to complete

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
        """
        return self.arm.save_record_trajectory(filename, wait=wait, timeout=timeout, **kwargs)

    def start_record_trajectory(self):
        """
        Start trajectory recording, only in teach mode, so joint teaching mode must already be set.

        Note:
            1. This interface relies on Firmware 1.2.0 or above
            2. set joint teaching mode: set_mode(2);set_state(0)

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
        """
        return self.arm.start_record_trajectory()

    def stop_record_trajectory(self, filename=None, **kwargs):
        """
        Stop trajectory recording

        Note:
            1. This interface relies on Firmware 1.2.0 or above

        Args:
            filename: The name to save

                1. Only strings consisting of standard English characters or numbers are supported, with a maximum length of 50.

                2. The trajectory will be saved in the controller box.

                3. If the filename is None stop recording and do not save, you need to manually call `save_record_trajectory` save before changing the mode. otherwise the recording will be lost

                4. This action will overwrite a trajectory with the same name

                5. Empty the trajectory in memory after saving

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
        """
        return self.arm.stop_record_trajectory(filename=filename, **kwargs)

    def load_trajectory(self, filename, wait=True, timeout=None, **kwargs):
        """
        Load a trajectory

        Note:
            1. This interface relies on Firmware 1.2.0 or above

        Args:
            filename: The name of the trajectory to load

            wait: Whether to wait for loading, default is True

            timeout: Timeout waiting for loading to complete

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
        """
        return self.arm.load_trajectory(filename, wait=wait, timeout=timeout, **kwargs)

    def playback_trajectory(self, times=1, filename=None, wait=True, double_speed=1, **kwargs):
        """
        Playback trajectory

        Note:
            1. This interface relies on Firmware 1.2.0 or above

        Args:
            times: Number of playbacks,

                1. Only valid when the current position of the arm is the end position of the trajectory, otherwise it will only be played once.

            filename: The name of the trajectory to play back

                1. If filename is None, you will need to manually call `load_trajectory` to load the trajectory.

            wait: whether to wait for the arm to complete, default is False

            double_speed: double speed, only support 1/2/4, default is 1, only available if version > 1.2.11

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
        """
        return self.arm.playback_trajectory(times=times, filename=filename, wait=wait, double_speed=double_speed, **kwargs)

    def get_trajectory_rw_status(self):
        """
        Get trajectory read/write status

        Returns:
            out (tuple[int, int]): (code, status)

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            status (int):

                0: no read/write

                1: loading

                2: load success

                3: load failed

                4: saving

                5: save success

                6: save failed
        """
        return self.arm.get_trajectory_rw_status()

    def delete_trajectory(self, name):
        """
        Delete trajectory

        Args:
            name: trajectory name

        Returns:
            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
        """
        return self.arm._studio.delete_trajectory(name)

    def get_traj_speeding(self, rate):
        """
        Obtain the joint and velocity values of joint overspeed during trajectory recording

        Args:
            rate: speed rate, only 1/2/4

        Returns:
            out (tuple[int, list]): tuple((code, speed_info)), returned result is only corrent when code is 0.

            code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

            speed_info (list): [result_code, servo_id, servo_speed]

                result_code: 0: Pass, -1: Fail, >0: abnormal(1:Trajectory not loaded or incorrect status;2:The input magnification is incorrect)

                servo_id: Effective only when result_code is -1

                servo_speed: Effective only when result_code is -1
        """
        return self.arm.get_traj_speeding(rate)

delete_trajectory(name)

Delete trajectory

Parameters:

Name Type Description Default
name

trajectory name

required

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Source code in actions\trajectory_recording.py
162
163
164
165
166
167
168
169
170
171
172
def delete_trajectory(self, name):
    """
    Delete trajectory

    Args:
        name: trajectory name

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
    """
    return self.arm._studio.delete_trajectory(name)

get_record_seconds()

Get record seconds

Note
  1. Only available if firmware_version >= 2.4.0
  2. Only valid during recording or after recording but before saving

Returns:

Name Type Description
out tuple[int, float]

tuple((code, seconds)), returned result is only corrent when code is 0.

code int

See the API Code Documentation for details.

seconds float

The actual duration of the recorded trajectory

Source code in actions\trajectory_recording.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def get_record_seconds(self):
    """
    Get record seconds

    Note:
        1. Only available if firmware_version >= 2.4.0
        2. Only valid during recording or after recording but before saving

    Returns:
        out (tuple[int, float]): tuple((code, seconds)), returned result is only corrent when code is 0.

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

        seconds (float): The actual duration of the recorded trajectory
    """
    ret = self.arm.get_common_info(50, return_val=True)
    return ret

get_traj_speeding(rate)

Obtain the joint and velocity values of joint overspeed during trajectory recording

Parameters:

Name Type Description Default
rate

speed rate, only 1/2/4

required

Returns:

Name Type Description
out tuple[int, list]

tuple((code, speed_info)), returned result is only corrent when code is 0.

code int

See the API Code Documentation for details.

speed_info list

[result_code, servo_id, servo_speed]

result_code: 0: Pass, -1: Fail, >0: abnormal(1:Trajectory not loaded or incorrect status;2:The input magnification is incorrect)

servo_id: Effective only when result_code is -1

servo_speed: Effective only when result_code is -1

Source code in actions\trajectory_recording.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def get_traj_speeding(self, rate):
    """
    Obtain the joint and velocity values of joint overspeed during trajectory recording

    Args:
        rate: speed rate, only 1/2/4

    Returns:
        out (tuple[int, list]): tuple((code, speed_info)), returned result is only corrent when code is 0.

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

        speed_info (list): [result_code, servo_id, servo_speed]

            result_code: 0: Pass, -1: Fail, >0: abnormal(1:Trajectory not loaded or incorrect status;2:The input magnification is incorrect)

            servo_id: Effective only when result_code is -1

            servo_speed: Effective only when result_code is -1
    """
    return self.arm.get_traj_speeding(rate)

get_trajectory_rw_status()

Get trajectory read/write status

Returns:

Name Type Description
out tuple[int, int]

(code, status)

code int

See the API Code Documentation for details.

status int

0: no read/write

1: loading

2: load success

3: load failed

4: saving

5: save success

6: save failed

Source code in actions\trajectory_recording.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def get_trajectory_rw_status(self):
    """
    Get trajectory read/write status

    Returns:
        out (tuple[int, int]): (code, status)

        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.

        status (int):

            0: no read/write

            1: loading

            2: load success

            3: load failed

            4: saving

            5: save success

            6: save failed
    """
    return self.arm.get_trajectory_rw_status()

load_trajectory(filename, wait=True, timeout=None, **kwargs)

Load a trajectory

Note
  1. This interface relies on Firmware 1.2.0 or above

Parameters:

Name Type Description Default
filename

The name of the trajectory to load

required
wait

Whether to wait for loading, default is True

True
timeout

Timeout waiting for loading to complete

None

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Source code in actions\trajectory_recording.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def load_trajectory(self, filename, wait=True, timeout=None, **kwargs):
    """
    Load a trajectory

    Note:
        1. This interface relies on Firmware 1.2.0 or above

    Args:
        filename: The name of the trajectory to load

        wait: Whether to wait for loading, default is True

        timeout: Timeout waiting for loading to complete

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
    """
    return self.arm.load_trajectory(filename, wait=wait, timeout=timeout, **kwargs)

playback_trajectory(times=1, filename=None, wait=True, double_speed=1, **kwargs)

Playback trajectory

Note
  1. This interface relies on Firmware 1.2.0 or above

Parameters:

Name Type Description Default
times

Number of playbacks,

  1. Only valid when the current position of the arm is the end position of the trajectory, otherwise it will only be played once.
1
filename

The name of the trajectory to play back

  1. If filename is None, you will need to manually call load_trajectory to load the trajectory.
None
wait

whether to wait for the arm to complete, default is False

True
double_speed

double speed, only support 1/2/4, default is 1, only available if version > 1.2.11

1

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Source code in actions\trajectory_recording.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def playback_trajectory(self, times=1, filename=None, wait=True, double_speed=1, **kwargs):
    """
    Playback trajectory

    Note:
        1. This interface relies on Firmware 1.2.0 or above

    Args:
        times: Number of playbacks,

            1. Only valid when the current position of the arm is the end position of the trajectory, otherwise it will only be played once.

        filename: The name of the trajectory to play back

            1. If filename is None, you will need to manually call `load_trajectory` to load the trajectory.

        wait: whether to wait for the arm to complete, default is False

        double_speed: double speed, only support 1/2/4, default is 1, only available if version > 1.2.11

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
    """
    return self.arm.playback_trajectory(times=times, filename=filename, wait=wait, double_speed=double_speed, **kwargs)

save_record_trajectory(filename, wait=True, timeout=5, **kwargs)

Save the trajectory you just recorded

Note
  1. This interface relies on Firmware 1.2.0 or above

Parameters:

Name Type Description Default
filename

The name to save

  1. Only strings consisting of standard English characters or numbers are supported, with a maximum length of 50.

  2. The trajectory will be saved in the controller box.

  3. This action will overwrite a trajectory with the same name

  4. Empty the trajectory in memory after saving, so repeated calls will cause the recorded trajectory to be covered by an empty trajectory.

required
wait

Whether to wait for saving, default is True

True
timeout

Timeout waiting for saving to complete

5

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Source code in actions\trajectory_recording.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def save_record_trajectory(self, filename, wait=True, timeout=5, **kwargs):
    """
    Save the trajectory you just recorded

    Note:
        1. This interface relies on Firmware 1.2.0 or above

    Args:
        filename: The name to save

            1. Only strings consisting of standard English characters or numbers are supported, with a maximum length of 50.

            2. The trajectory will be saved in the controller box.

            3. This action will overwrite a trajectory with the same name

            4. Empty the trajectory in memory after saving, so repeated calls will cause the recorded trajectory to be covered by an empty trajectory.

        wait: Whether to wait for saving, default is True

        timeout: Timeout waiting for saving to complete

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
    """
    return self.arm.save_record_trajectory(filename, wait=wait, timeout=timeout, **kwargs)

start_record_trajectory()

Start trajectory recording, only in teach mode, so joint teaching mode must already be set.

Note
  1. This interface relies on Firmware 1.2.0 or above
  2. set joint teaching mode: set_mode(2);set_state(0)

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Source code in actions\trajectory_recording.py
53
54
55
56
57
58
59
60
61
62
63
64
def start_record_trajectory(self):
    """
    Start trajectory recording, only in teach mode, so joint teaching mode must already be set.

    Note:
        1. This interface relies on Firmware 1.2.0 or above
        2. set joint teaching mode: set_mode(2);set_state(0)

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
    """
    return self.arm.start_record_trajectory()

stop_record_trajectory(filename=None, **kwargs)

Stop trajectory recording

Note
  1. This interface relies on Firmware 1.2.0 or above

Parameters:

Name Type Description Default
filename

The name to save

  1. Only strings consisting of standard English characters or numbers are supported, with a maximum length of 50.

  2. The trajectory will be saved in the controller box.

  3. If the filename is None stop recording and do not save, you need to manually call save_record_trajectory save before changing the mode. otherwise the recording will be lost

  4. This action will overwrite a trajectory with the same name

  5. Empty the trajectory in memory after saving

None

Returns:

Name Type Description
code int

See the API Code Documentation for details.

Source code in actions\trajectory_recording.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def stop_record_trajectory(self, filename=None, **kwargs):
    """
    Stop trajectory recording

    Note:
        1. This interface relies on Firmware 1.2.0 or above

    Args:
        filename: The name to save

            1. Only strings consisting of standard English characters or numbers are supported, with a maximum length of 50.

            2. The trajectory will be saved in the controller box.

            3. If the filename is None stop recording and do not save, you need to manually call `save_record_trajectory` save before changing the mode. otherwise the recording will be lost

            4. This action will overwrite a trajectory with the same name

            5. Empty the trajectory in memory after saving

    Returns:
        code (int): See the [API Code Documentation](./xarm_api_code.md#api-code) for details.
    """
    return self.arm.stop_record_trajectory(filename=filename, **kwargs)