{'fraction_non_alphanumeric': 0.030555243129756684, 'fraction_numerical': 0.009672702733100889, 'mean_word_length': 4.650074136835416, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learning Singularity Avoidance

With the increase in complexity of robotic systems and the rise in non-expert users, it can be assumed that task constraints are not explicitly known. In tasks where avoiding singularity is critical to its success, this paper provides an approach, especially for non-expert users, for the system to learn the constraints contained in a set of demonstrations, such that they can be used to optimise an autonomous controller to avoid singularity, without having to explicitly know the task constraints. The proposed approach avoids singularity, and thereby unpredictable behaviour when carrying out a task, by maximising the learnt manipulability throughout the motion of the constrained system, and is not limited to kinematic systems. Its benefits are demonstrated through comparisons with other control policies which show that the constrained manipulability of a system learnt through demonstration can be used to avoid singularities in cases where these other policies would fail. In the absence of the systems manipulability subject to a tasks constraints, the proposed approach can be used instead to infer these with results showing errors less than 10^-5 in 3DOF simulated systems as well as 10^-2 using a 7DOF real world robotic system.


I. INTRODUCTION
In recent years, there has been a booming shift from the development of specialised factory robots to versatile autonomous ones that are targeted at non-expert users. However, systems are performing tasks for which they were not specifically designed and there is uncertainty over the degree of redundancy (or contrastingly, overconstrainedness) in the control of their movements. Consequently, increasing importance is placed on improving control techniques to reduce such uncertainty, which otherwise may inadvertently affect the task at hand.
Traditionally, those issues are assessed by the so-called manipulability of the system, by analysing the extent to which solutions exist to the inverse problem of finding control solutions for a given set of task constraints. First introduced by Yoshikawa [1], the manipulability index works by identifying linear dependencies in the task Jacobian that may cause a singular configuration to be reached.
Initially used to devise control algorithms to avoid kinematic singularities in manipulators, it has since been used in a wide variety of contexts, such as real-time end-pose planning in walking tasks [2], grasp planning [3], and planning of human-robot interaction work spaces [4]. This measure has also been extended to account for joint limits, self-collision in redundant systems, and the need for adaptability to avoid obstacles in the work space [5].
The common assumption among studies using different forms of Yoshikawa's manipulability index, [6] is that the nature of the constraints affecting the system's manipulability (more specifically, the system's task Jacobian) is known analytically, a priori for design of the controller. However, with the rise in non-expert users and the increase in complexity of tasks, this assumption is increasingly untenable. Ignoring the manipulability in such systems risks, for instance, a nonexpert user driving a robot through an unstable singular point and causing possible damage to the robot, or worse, injury to the user.
As an alternative, this paper provides a data-driven approach in which the constrained joint manipulability is learnt from user demonstrations, without need for explicit definition through analytical approaches. This is beneficial to nonexpert users without explicit knowledge of task constraints as it optimises a system's control to avoid instabilities in the system caused by singularities when carrying out a task. The proposed approach uses constraint consistent learning [7], [8], [9], [10] to, first, learn the task constraint and, second, optimise the manipulability derived from the learnt constraint matrix within the null space of the primary task constraint. It thereby, avoids singularity by maximising the learnt manipulability throughout the motion of the constrained system, in the absence of analytical prior knowledge of the constraints. Results of estimating the manipulability subject to task constraints show errors less than 10 −5 in 3DOF simulated systems as well as 10 −2 using a 7DOF real world robotic system.

II. PROBLEM DEFINITION
This work considers the control of systems subject to uncertain constraints due to the complexity and/or naivety of nonexpert users, and the need to prioritise joint configurations, which lead to greater degrees of freedom to flexibly perform demonstrated tasks.

A. Task Prioritised Constraints
Formally, a system of S-dimensional (self-imposed or environmental) constraints can be defined as where x ∈ R P represents state (usually represented either in end-effector or joint space), A(x) ∈ R S×Q is a matrix describing the constraints, u ∈ R Q represents the action and b(x) ∈ R S is the task space policy describing the primary task to be accomplished. It is assumed that the A(x) should be learnt by the robot through demonstrations, while also autonomously handling the degree of constrainedness of the system such that it enhances the flexibility. The general solution to (1) is given by where v is the task space component that implements the task space policy, w is the null space component and is the null space projection matrix that projects the null space policy π(x) onto the null space of A. Here, I ∈ R Q×Q denotes the identity matrix and A † = A (AA ) −1 is the Moore-Penrose pseudo-inverse of A. This does not only apply to kinematics, but also to redundant actuation [11], and redundancy in dynamics [12]. Commonly, in the context of programming by demonstration by non-expert users, A, N, b and π are not explicitly known. Instead, the controller must be derived from data. In this paper, it is assumed that data is given as pairs of N observed states x n and actions u n .
What non-expert users may not be aware of is that w controls the additional free non-task related degrees of freedom of the system. It can be thought of as a lower priority task which does not conflict with the goal defined in the task space component. The benefit of having a null space component is evident in tasks which have multiple solutions. For example, a reaching task where multiple paths to a goal may be available, some paths may drive a system closer to its joint limits or singular configurations which can lead to an increased risk of getting stuck or cause turbulent movement in face of perturbations or the imposition of additional constraints.

B. Example: Opening Drawers
As a real world example, consider placing the robot in an environment designed for use by people such as an office. A robot trained to assist staff with, for example, collecting documents needs to be able to perform tasks such as opening filing cabinets. In this case, the problem of teaching the robot to open and close drawers can be solved through programming by demonstration (as shown in Fig. 1). Programming by demonstration is suitable because office staff can decide to retrain systems when required in another office or if the room layout changes without having any expert knowledge of the system and the need to call in a specialist. The primary task policy is to have the robot endeffector open the drawer, in which the constraint matrix A is determined by a linear constraint following the direction of the drawer opening.
Where the task is kinaesthetically demonstrated, the user might manually guide a robot facing a filing cabinet, from holding onto a random point on the handle to opening the drawer towards the robot, and repeating this action multiple times using different starting points. In this scenario, the primary task might be learnt in a straightforward manner using one of several constraint learning methods (see §III-C).
Unless explicitly instructed, however,the user might not take specific care of how the motion appears in the null space when performing those demonstrations. For example, the user might choose to grab the drawer from the nearest point or in a pose/grip which allows demonstrations in the most comfortable manner for the user. It is unlikely that an average user will know to avoid unstable or singular configurations-however, these may occur in various taskdependant situations. If for example, a system placed in front of a drawer starts with all the joints fully extended, and a novice user then directs it to open the drawer by moving the arm directly back towards itself without resolving redundancy in the joint space, the system may propel itself in unpredictable directions due to the singularity. Moreover, systems that use an ad hoc way of dealing with singularities, such as when using Matlab's pseudoinverse function which replaces singular values with zero are not satisfactory, as this prevents any movement of the system and thus comes at the expense of completing the task. A better way to do this is by maximising the system's manipulability.

C. Task Manipulability and Programming by Demonstration
To avoid these problems and reduce uncertainty of encountering unstable or singular configurations ( §II-B), traditionally, Yoshikawa's manipulability index is used, whereby the null space degrees of freedom are used to maximise the distance from singular points during the execution of the primary task.
The manipulability is a measure of a system's ability to position and orientate its end-effector [1]. In order to help with the designing and control of systems, Yoshikawa developed the manipulability index [1]. It works by finding the linear dependencies in the task Jacobian which could result in reaching a singular configuration. Thus the following measure is used to assess manipulability Note that, computation of the manipulability presupposes the availability of A in analytical form-however, as noted in §II-A, this is usually unavailable in the context of programming by demonstration where the primary task and associated constraints are implicit in the demonstrations.
As µ → 0, the manipulability index indicates that the system is approaching a singular pose. The upper limit of µ depends on the system itself and can only be provided once the entire work space is assessed (however the proposed method does not require this as it compares its manipulability locally). One of the applications of µ lies in its use as a cost function to replace π in (2) which results in the secondary task moving the system towards the goal using a path which favours higher manipulability (see §III-D).
To obtain µ, such that it can be used in such a manner, this paper proposes to form an estimate of the constraints in a task and derive an estimate of (5). The approach uses demonstration data such that it is applicable even for nonexperts with no formal knowledge of the constraints involved in a task. In doing so, it allows for the robot to more accurately manoeuvre towards targets while minimising the risk of crossing over singular points and avoiding potentially unstable, unpredictable behaviour.
III. METHOD In this paper, the proposed approach forms an estimate of the task space constraint matrix A to be used in π to manipulate systems away from singular points while performing a task. This minimises the risk of encountering singularities which lead to unpredictable behaviour.

A. Data Collection
The proposed method works on data given as N pairs of observed states x n and actions u n collected though kinaesthetic demonstrations of the primary task. Assumptions on the data include that (i) observations are in the form presented in (2), (ii) b from the task space varies throughout all observations, (iii) π from the null space is consistent throughout u, and (iv) A, N, b, and π are not explicitly known for any given observation.

B. Separating the task and null space component
Given the demonstration data {x n , u n } N n=1 , the first step is to separate the task and null space components. For this, the approach first proposed in [13] can be used.
As shown there, the first and second terms of (2) can be separated by seeking an estimatew that minimises wherew n :=w(x n ) andP n :=w nwn /||w n || 2 . This works on the principal that, there exists a projection P for Similarly,ṽ is required as it functions as the primary task controller for the system and can be extracted by subtracting the newly estimatedw from u, i.e.,ṽ = u −w.
C. Representation & Learning of the Constraint A At this point, the original demonstrated actions u are separated into the task and null space parts. Based on the latter, the goal now is to compose an estimate of A that can be used in assessing manipulability. Constraints imposed on motion in the task space can refer to translational and orientational coordinates in the end-effector or joint space depending on the task at hand. An important criteria for using the manipulability for control is that constraints are state-dependant [14]. Otherwise, if A is constant across the state space [9] every state has the same manipulability index and the singularity avoidance controller has no role.
Taking this into consideration, a suitable representation of the constraint matrix is [8] A(x) = ΛΦ(x) where Λ ∈ R S×P is an unknown selection matrix (to be estimated in the learning) and Φ(x) ∈ R P×Q is a feature matrix. The rows of the latter contain candidate constraints that can be predefined where there is prior knowledge of potential constraints affecting the system, or can take generic forms such as a series of polynomials. For example, one may choose Φ(x) = J(x), the Jacobian of the manipulator, where A(x) = ΛJ(x) encodes constraints on the motion of specific degrees of freedom in the end-effector space.
Depending on the assumptions made on the representation of A, one of several learning methods could potentially be used to form the estimate of the selection matrixΛ [9], [14], [15]. Of these, this paper picks [14] as it requires relatively few parameters and little data to perform robustly [9]. The estimate is formed by minimising where Φ n := Φ(x n ). This results in the estimateÃ(x) = ΛΦ(x).

D. Estimated Singularity Avoidance Policy
Using the estimated constraint matrixÃ, it is now possible to form the estimate of the system manipulability for any configuration within the support of the data. The latter is given by substitution of A in Yoshikawa's manipulability index.μ From this constrained manipulability map, states for particular end-effector poses can be selected based onμ using π to update the joint angles. When used as a cost function, this information can provide the direction in which the system should move in order to increase its manipulability and maximise the distance from singular points, thereby reducing the risk of unpredictable behaviour. The simplest such approach is to use gradient ascent by replacing π in (2) with πμ(x) = ∇ xμ .
Alternatively, if the task space trajectory is predictable,μ can be used in combination with global approximation in the null space (see, e.g., [16]). Fig. 2 shows a brief overview of the major steps involved in the proposed approach.

E. Evaluation Criteria for Learning Methods
Learning the constrained manipulability may not always be a trivial matter depending on the task at hand. Factors such as, high dimensionality of a system, or the structure of particular constraints in comparison to others, can lead to poor learning performance. It is therefore necessary to define the following metric to assess learning performance.
The Normalised Manipulability Index Error (NMIE) evaluates the fitness of the learnt manipulability indexμ, the following can be used to measure the distance between the true and learnt manipulability index where N is the number of data points. The error is normalised by the variance of µ. The MIE will reach zero as µ → µ.

IV. EVALUATION
In this section, the proposed approach is first examined through a simulated 3-link planar system, before evaluating its performance in the context of programming by demonstration of a physical robot. 1

A. Three Link Planar Arm
The aim of the first evaluation is to test the robustness of learning the manipulability from motion data. The setup is as follows. Constrained motion data is gathered from a kinematic simulation of a 3-link planar robot. The state and action space refer to the joint angle position and velocities, respectively, i.e., x := q ∈ R 3 and u :=q ∈ R 3 . The taskspace is described by the end-effector coordinates r = (r x , r y , r θ ) referring to the positions and orientation, respectively. The simulation runs at a rate of 50 Hz. Joint space motion of the system is recorded as it performs tasks under different constraints in the end-effector space. As described in §III-C,
To simulate demonstrations of reaching behaviour, the robot end-effector starts from a point chosen uniform-randomly 10 • ] to a taskspace target r * and following a linear point attractor policy b(x) = r * − r.
where r * is drawn uniformly from r * Targets without a valid inverse kinematic solution are removed. All trajectories also use a point attractor as a control policy in w The latter enforces consistency, that makes it easier to separate the constraint from the control policy. ψ ψ ψ * is arbitrarily chosen as q 1 = 10 • , q 2 = −10 • , q 3 = 10 • . For each constraint, 100 trajectories are generated each containing 10 data points (1,000 points per constraint). This is done for separate training and testing data sets (a total of 2,000 points per constraint). Finally, this whole experiment is repeated 50 times. The NMIE is presented in Table I. As can be seen, learning of the constrained manipulability index is successful with errors less 10 −5 . This shows that the manipulability index can be learnt with very high precision through demonstrations, without having to explicitly know how the constraints affect the system's motions.
To further assess the suitability of usingμ instead of µ, the RMSE is evaluated for 20 randomly generated trajectories of 100 points, using π µ learnt under the constraint Λ x,y and πμ following §III-D. The starting point is chosen uniform-randomly , and following (12), r * is drawn uniformly from . This produces two trajectories, one using π µ and the other πμ. Results given as (mean±s.d.)×10 −4 are 2.069 ± 1.001. These errors being lower than 10 −3 in both the mean and standard deviation indicate that all 20 trajectories are accurately reproduced, therefore πμ is an appropriate replacement for when π µ is difficult to infer.
At this point, the suitability of πμ in absence of explicit knowledge of the constraint has been established. In order to understand the benefit of using the manipulability-based controller (9) to handle redundancy in the joint-space, its performance can be compared to that of other commonly used policies when encountering singularities in Λ x,y . As examples of the latter, a zero policy and a linear point attractor in π are chosen. The zero policy emulates the most common and simplest approach (being the shortest path directly towards the target subject to the task constraints). The linear point attractor is also a common choice as a null space policy as a way of bringing the arm to a default posture. When considering how systems behave near singular configurations, it is also important to consider the case where a system has an ad hoc way to deal with singularities, which is becoming more common among safety protocols in commercialised systems for novice users (see §II-C). Thus two cases are presented here, one where a system starts in a singular configuration without any impromptu way of dealing with singular values, and one case where singularities are dealt with by setting the singular value to zero after it crosses a certain threshold. Here, Matlab's ad hoc approach is used, whereby the pseudoinverse function determines when singularities are encountered by using a threshold of max(size(A)) × eps(norm(A)), which in this case is 1.332 × 10 −15 . The eps in Matlab calculates the floating-point relative accuracy. Figure 3 shows how a system behaves under the three different control policies in π. This system is subject to a task constraint in the r x and r y coordinate and uses three control policies to evaluate how each handles movement from a singular pose. As shown, the proposed method is able to move away from the singular starting pose q 1 = (90 + 10 −12 ) • , q 2 = 360 • and q 3 = −360 • using the learnt manipulability. On the other hand, the zero policy gets stuck at the starting point as it attempts to move directly down towards the target r * = (0, 0). The point attractor does succeed in the task, however, the movement to the default posture q * = (−190 • , 9 • , −307 • ) T results brings the robot close to singular configurations. While both the manipulability and point attractor policies reach their target, it is evident when looking at the bottom row that the (true) manipulability index of both systems are vastly different. As shown, the point attractor nearly approaches a singular configuration at around 70 steps into the movement which explains the overall erratic movement to reach the target. On the other hand, the manipulability encounters no such problem as it moves towards the target while maximising its manipulability throughout the movement. Figure 4 looks at a case where no ad hoc method is used to detect singularities. In this case, a starting pose is set near a singular pose 2 of q 1 = 90 • , q 2 = −180 • and q 3 = (−180 + 10 −10 ) • . As shown, both the manipulaiblity and zero policy move away from the near-singular configuration. On the other hand, the point attractor with a default posture of q * = (−33 • , −283 • , 193 • ) T exhibits highly unstable behaviour (its next state exceeds 10 9 for each joint). This type unpredictable behaviour is the most hazardous when having systems work in the real world.
Overall, these experiments show that the constrained ma-  nipulability of a system can be learnt through programming by demonstration. Moreover, the learnt manipulability index can be used as a controller to avoid singularities in comparison to a straight-forward zero policy or a simple point attractor.

B. 7-Link Sawyer Arm
The final experiment assesses the proposed approach in a real world task executed on the Sawyer, a 7DOF revolute physical robotic system with a maximum reach of 1260mm and precision of ±0.1mm. The experimental scenario chosen is the closing of a drawer. The state and action space refer to the joint angle position and velocities, respectively, i.e., x := q ∈ R 7 and u := q ∈ R 7 . The taskspace is described by the end-effector coordinates r = (r x , r y , r z ) referring to positions in 3D cartesian space. The system runs at a rate of 100 Hz. Joint space motion is kinaesthetically recorded by guiding the Sawyer as it performs tasks under a constraint in the endeffector space. J ∈ R 3×7 is the manipulator Jacobian, and Λ ∈ R 3×3 is the selection matrix specifying the coordinates to be constrained. The following constraint is evaluated which models a drawer when it is orientated such that the constraint's null space lies along the x-axis (as shown in In order to have consistency in π, the system starts in a default pose of q 1 ∼ −100 • , q 2 ∼ 30 • , q 3 ∼ −100 • , q 4 ∼ 40 • , q 5 ∼ −60 • , −70 • , q 7 ∼ 250 • where the joints point outward such that stretching out the systems arm away from its body and along the constraint resolves redundancy in a similar manner for each trajectory.
Fifty trajectories are recorded and the data is downsampled such that each trajectory is reduced to 10 points. This is done as the direction of the constrained movements are captured even with such little data, and more data simply results in longer computation times.
The MIE learnt from 50 trajectories is 0.002, therefore it is learnt successfully with errors below 10 −2 . 3 While it is shown that the manipulability index is learnt, it is important to establish whether the estimated manipulability is still suitable as a cost function to avoid singularity despite a greater error margin in comparison to the simulated 3DOF system. To this end, the RMSE is evaluated for 20 randomly generated trajectories of 100 points using the learnt model. The starting point is chosen uniform-randomly . r * is drawn uniformly from ∼ U [−1, 1] for the x-axis. Two trajectories are produced, one using π µ and the other πμ. The results are 0.220 ± 0.094 (mean±s.d.). Considering the high dimensionality of the robot, it is reasonable to assume an increased error in comparison to the simulated 3-link system.

V. CONCLUSION
This paper uses learning by demonstration to merge learning and manipulability-based control optimisation of an autonomous system to avoid singularities. The control optimisation uses a learnt cost function that maximises manipulability throughout the motion of a constrained system, not limited to kinematic systems. An approach is provided 3 a similar experiment was done where the null space of the constraint lies along the y-axis giving alike performance to learn the constraint of the task, if not known, from data. Results have been presented for a 3-link simulation in a 2D workspace and a real world experiment using the sawyer's arm in its 7DOF joint space. All experiments are in agreement that manipulabilities can be learnt through demonstration. The simulation demonstrates using the learnt manipulability as a cost function to have the system avoid singularities while performing a task. This approach is also verified in the real world using a robotic system with a high dimensional configuration space, showing that constraints can be learnt with enough precision to identify and avoid singular regions, when substitutingμ for µ and being used as a cost function. When compared to other control policies such as a zero policy and a point attractor, the optimised movements from the proposed approach result in an autonomous system that moves towards the goal while handling redundancy by moving away from singular regions through local optimisation. This approach when compared to the aforementioned policies allows for the completion of the task, where the other policies are shown to succumb to the singularities within the same task resulting in either no movement at all or unpredictable behaviour.
Future work looks at conducting a study with naive subjects to evaluate the usefulness of the programming by demonstration approach to avoid singularity in practice.