1 Introduction

Since the inception of contour crafting (Khoshnevis, 2004; Zhang & Khoshnevis, 2013; Zhang et al., 2019), the last decade has witnessed rapid advancements in large-scale 3D printing within engineering construction, particularly in the domain of 3D printing involving concrete (Furet et al., 2019; Vantyghem et al., 2020; Xiao et al., 2021). Commonly utilized hardware includes industrial robots and three-axis gantry systems, with the printing end-effector typically oriented perpendicular to the horizontal plane, necessitating only three degrees of freedom for the robot to execute the printing task (ICON Team, 2022; Nematollahi et al., 2017; Siddika et al., 2020). However, in scenarios demanding increased complexity, additional degrees of freedom become essential, as observed in non-horizontal printing situations (Li et al., 2023). In the construction of shell structures, non-horizontal printing proves advantageous in capitalizing on the compressive strength of concrete (Bhooshan et al., 2022; Rehman & Kim, 2021). Figure 1 illustrates the two distinct printing methods mentioned above:

Fig. 1
figure 1

a 3DCP based on 3-axis printer: when printing tilted shapes, the printing head collides with the already printed shape, shown in red in the figure; b 3DCP based on 6-axis industrial robot: the printing head can tilt to make itself perpendicular to the extruded filament

In non-horizontal 3D printing, precise definition of the goal pose for printing is of utmost importance (Breseghello et al., 2021). While defining the goal pose typically requires six degrees of freedom, specifying the goal pose for non-horizontal 3D printing, such as concrete printing, only necessitates five degrees of freedom. When the number of robot joints exceeds the degrees of freedom required for the task, redundant degrees of freedom are introduced.

Existing research on optimizing redundant robot joints encompasses the optimization of the redundant robot structure (Kivelä et al., 2017) and studies on kinematics-based trajectory optimization (Klein et al., 1995; Seng et al., 1995; Siciliano, 1990; Xiao & Huan, 2012). Typically, these methods are applied after determining the goal pose.

Another existing method involves optimizing joints by modifying the goal pose. In concrete 3D printing, rotating the goal pose around the normal direction does not impact the final printing result, as illustrated in Fig. 2. Building upon this premise, a previous optimization method was proposed, requiring the end-effector to be perpendicular to the flange coordinate frame. Expanding on this research, the current study focuses on optimizing the joint angles of a 6-axis industrial robot, accommodating an end-effector that is not perpendicular to the flange coordinate frame. The optimization results are then reflected in the non-horizontal goal pose. This approach enables the robot to seamlessly utilize the new goal pose without additional adjustments, achieving minimal motion in joint space to accomplish the same task.

Fig. 2
figure 2

Rotate a goal pose around its normal direction(x-axis)

This study integrates a combination of self-developed analytical and numerical methods. The initial pose values for the entire robot motion are determined through the analytical method. Subsequently, building upon these initial values, the subsequent goal poses undergo optimization using a numerical iterative approach, thereby completing the entire optimization process.

The paper's structure is organized as follows:

  • Part II: Introduces the analytical and numerical methods employed in this study.

  • Part III: Presents the results of printing tests conducted under the two optimization methods.

  • Part IV: Validates the proposed methods through 3D printing experiments, confirming their feasibility.

  • Part V: Provides a comparison and discussion of the strengths and weaknesses of different methods, along with an extension of the application of joint weights.

  • Part VI: Concludes the research and outlines future work.

2 Methods

This paper describes both analytical and numerical methods that effectively reduce the robot joint motion and maintain the same printing results as before optimization.

Most 6-axis industrial robots belong to the Pieper type (Pieper, 1969), and thus, this paper uses the Pieper-type “KUKA KR6 R900” robot as an example. The normal direction of the end-effector is initially defined as the direction of the milling cutter's long axis or the direction of the material extrusion end-effector. It's crucial to note that the normal direction of the end-effector coordinate frame varies among different brands of robots. For KUKA robots, the normal direction of the end-effector aligns with the x-axis direction of the goal pose. In other words, the x-axis direction of the goal pose corresponds to the normal direction of the KUKA robot's end-effector.

2.1 Analytical method

The objective of this analytical method is to derive a new printing goal pose. This ensures that when the robotic arm's end-effector reaches this new printing goal pose, the rotation angle of the 4th joint of the robotic arm is precisely 0 degrees, all while maintaining the integrity of the printing results.

Article (Lu & Yuan, 2020) presents an analytical solution for optimizing the goal poses, operating under the assumption of a common end-effector. The prerequisite for utilizing this method (Lu & Yuan, 2020) is that the normal direction of the end-effector plane must be perpendicular to the normal direction of the robot flange plane, as depicted in Fig. 3a. However, for most end-effectors, the pose direction is typically inclined, as exemplified by the welding end-effector in Fig. 3b.

Fig. 3
figure 3

The end-effector parameters for analytical method (a) is orthogonal end-effector, (b) is non-orthogonal end-effector

Considering that in many architectural 3D printing applications, the robot's end-effector is often left–right symmetric, and the offset of the Y-axis direction of the end-effector plane is zero, the analytical method is adapted accordingly. Taking KUKA 6-DoF robot arm as an example, the rigid body transformation expression of the robot end-effector is represented by six parameters: XYZABC. The first three parameters, XYZ, denote the offsets in the X, Y, and Z directions, while the last three, ABC, represent the Euler angles corresponding to rotations around the Z, Y, and X axes. When using an end-effector with Y, A, and C parameters all set to zero (i.e., when the end-effector is left–right symmetric), this analytical method yields an angle \(\theta\). By rotating the goal poses around its own normal direction by \(\theta\), a new goal poses are formed. This ensures that when the robot's end-effector reaches the new goal poses, the 4th joint of the robot becomes zero.

The origin of one goal pose \(P\) is defined as \({P}_{org}={\left[{p}_{x},{p}_{y},{p}_{z}\right]}^{T}\), and the normal axis of \(P\) (in this paper, it is the x-axis) has a direction \({n}_{x}={\left[{x}_{1},{y}_{1},{z}_{1}\right]}^{T}\) relative to the world coordinate frame. The y-axis and z-axis of the goal pose can be arbitrarily specified. The z-axis is specified as \({n}_{z}={\left[\mathrm{1,0},{z}_{3}\right]}^{T}\), with the purpose of making the projection of \({n}_{z}\) in the world coordinate frame's XY-plane a unit vector of the x-axis. Due to the orthogonality condition \({n}_{x}^{T}{n}_{z}=0\), we can obtain:

$${z}_{3}=\frac{-{x}_{1}}{{z}_{1}}$$
(1)

Therefore, we have \({{\text{n}}}_{{\text{z}}}={\left[\mathrm{1,0},-\frac{{{\text{x}}}_{1}}{{{\text{z}}}_{1}}\right]}^{{\text{T}}}\), It can be calculated that the length of \({n}_{z}\):

$$L=\sqrt{1+\frac{{x}_{1}^{2}}{{z}_{1}^{2}}}$$
(2)

Normalize \({n}_{z}\) to obtain:

$${n}_{z}={\left[\frac{1}{L},0,-\frac{{x}_{1}}{{z}_{1}L}\right]}^{T}$$
(3)

With \({n}_{z}\) determined, we can obtain \({n}_{y}\) by calculating the cross product \({n}_{z}\) and \({n}_{x}\):

$${n}_{y}={\left[\frac{{x}_{1}{y}_{1}}{{z}_{1}L},-\frac{{z}_{1}}{L}-\frac{{x}_{1}^{2}}{{z}_{1}L},\frac{{y}_{1}}{L}\right]}^{T}$$
(4)

By employing this approach, we can derive the initial rigid body transformation \({T}_{i{\text{nit}}}^{0}\) of the goal pose relative to the world coordinate frame after initialization:

$${T}_{init}^{0}=\left[\begin{array}{cccc}{n}_{x}& {n}_{y}& {n}_{z}& {P}_{org}\\ 0& 0& 0& 1\end{array}\right]$$
(5)

After initializing the pose of an arbitrary goal pose, the pose of the goal pose is determined. Subsequently, the goal pose is rotated under this established pose.

With a known initial goal pose \({T}_{init}^{0}\), our objective is to determine an angle \(\theta\) such that applying a rotation around the x-axis of the goal pose ensures the robot's 4th axis remains at 0 degrees upon reaching the goal pose.

The rigid transformation \({T}_{f}^{0}\) of the robot's flange plane relative to the world coordinate frame (or the robot's base coordinate frame) is:

$${T}_{f}^{0}={T}_{init}^{0}{R}_{x}\left(\theta \right){\left({T}_{t}^{f}\right)}^{-1}$$
(6)

All elements in \({T}_{f}^{0}\), except for \(\theta\), are known quantities.

The \({T}_{t}^{f}\) in Eq. 6 denotes the rigid body transformation corresponding to the parameters of the end-effector.

As this method exclusively considers the positional offsets \({t}_{x}\) and \({t}_{z}\) relative to the x and z-axes of the flange coordinate frame, along with the rotation around the y-axis of the flange coordinate frame, \({T}_{t}^{f}\) can be expressed as:

$$T_t^f=\begin{bmatrix}\mathrm c\mathrm o\mathrm s\;\mathrm\beta&0&\mathrm s\mathrm i\mathrm n\;\mathrm\beta&t_x\\0&1&0&0\\-\mathrm s\mathrm i\mathrm n\;\mathrm\beta&0&\mathrm c\mathrm o\mathrm s\;\mathrm\beta&t_z\\0&0&0&1\end{bmatrix}$$
(7)

It's important to note that when the 4th joint of the robot is positioned at 0 degrees, the normal vector of its flange in the world coordinate frame, projected onto the XY plane, aligns parallel to the coordinate vector of the flange plane origin in the world coordinate frame, as illustrated in Fig. 4.

Fig. 4
figure 4

The geometric interpretation for [Eq. 10]

Therefore, we can establish an equation between these two vectors. Let \({T}_{f}^{0}\left(i,j\right)\) denote the element in the i-th row and j-th column of the rigid transformation matrix \({T}_{f}^{0}\). We can obtain the projection vector \({f}_{n}\) of the normal vector (i.e., the z-axis of the flange coordinate frame) of the robot flange on the XY plane of the world coordinate frame as follows:

$${{\text{f}}}_{{\text{z}}}^{0}={\left[{T}_{f}^{0}\left(\mathrm{1,3}\right),{T}_{f}^{0}\left(\mathrm{2,3}\right),0\right]}^{T}$$
(8)

The projected vector of the origin of the flange coordinate frame on the XY plane of the world coordinate frame can be obtained as follows:

$${f}_{org}^{0}={\left[{T}_{f}^{0}\left(\mathrm{1,4}\right),{T}_{f}^{0}\left(\mathrm{2,4}\right),0\right]}^{T}$$
(9)

Since these two vectors are parallel, we can express the relationship with the following equation:

$$\frac{{T}_{f}^{0}\left(\mathrm{1,3}\right)}{{T}_{f}^{0}\left(\mathrm{2,3}\right)}=\frac{{T}_{f}^{0}\left(\mathrm{1,4}\right)}{{T}_{f}^{0}\left(\mathrm{2,4}\right)}$$
(10)

This relationship can be expressed as:

$${T}_{f}^{0}\left(\mathrm{1,3}\right){T}_{f}^{0}\left(\mathrm{2,4}\right)={T}_{f}^{0}\left(\mathrm{2,3}\right){T}_{f}^{0}\left(\mathrm{1,4}\right)$$
(11)

where:

$$\begin{array}{c}{T}_{f}^{0}\left(\mathrm{1,3}\right)=cy\left(\frac{cx}{L}-\frac{{x}_{1}{y}_{1}sx}{L{z}_{1}}\right)-{x}_{1}sy\end{array}$$
$$\begin{array}{c}{T}_{f}^{0}\left(\mathrm{2,3}\right)=cysx\left(\frac{{x}_{1}^{2}}{L{z}_{1}}+\frac{{z}_{1}}{L}\right)-{y}_{1}sy\end{array}$$
$$\begin{array}{c}{T}_{f}^{0}\left(\mathrm{1,4}\right)={{\text{p}}}_{{\text{x}}}-\left({t}_{z}cy+{t}_{x}sy\right)\left(\frac{cx}{L}-\frac{{x}_{1}{y}_{1}sx}{L{z}_{1}}\right)-{x}_{1}\left({t}_{x}cy-{t}_{z}sy\right)\end{array}$$
$$\begin{array}{c}{T}_{f}^{0}\left(\mathrm{2,4}\right)={{\text{p}}}_{{\text{y}}}-{y}_{1}\left({t}_{x}cy-{t}_{z}sy\right)-sx\left(\frac{{x}_{1}^{2}}{L{z}_{1}}+\frac{{z}_{1}}{L}\right)\left({t}_{z}cy+{t}_{x}sy\right)\end{array}$$

where:

$$\begin{array}{c}sx=sin\theta , cx=cos\theta , sy=sin\beta , cy=cos\beta \end{array}$$

Equation 11 is an equation with one unknown variable \(\theta\). We can simplify it to obtain the following equation:

$$\text{sin}\;\theta+\frac kh\text{cos}\;\theta=\frac jh$$
(12)

where:

$$\begin{array}{c}k=-\frac{1}{L}\end{array}$$
$$\begin{array}{cc}h=\frac{x_1y_1}{Lz_1}+\frac{c_1c_4c_3-cyc_4p_x+cyc_4x_1c_2}{-cyp_y+cyy_1c_2+c_5c_3},&\begin{array}{c}j=\frac{-c_5p_x+c_5x_1c_2+p_yc_1-c_1y_1c_2}{-cyp_y+cyy_1c_2+c_5c_3}\end{array}\end{array}$$
$$\begin{array}{cccc}c_1=x_1sy,&c_2=t_xcy-t_zsy,&c_3=t_zcy+t_xsy,&c_4=\frac{x_1^2}{Lz_1}+\frac{z_1}L\end{array}$$

Solving Eq. 12 yields an analytical expression for \(\theta\). The steps for solving this type of equation are described in (Shwetank, 2017). To obtain more reasonable results, the result is expressed as a two-argument arctangent function. Thus, the analytical expression for \(\theta\) is:

$$\uptheta =\underset{x\in \left\{{\uptheta }_{1},{\uptheta }_{2}\right\}}{{\text{min}}}abs\left(x\right)$$
(13)

where:

$$\begin{array}{ccc}\theta_1=\;\mathrm{acos}\left(d\right)\;+\;\mathrm{atan}2\left(1,\;\frac kh\right),&\theta_2=\;-\mathrm{acos}\left(d\right)\;+\;\mathrm{atan}2\left(1,\;\frac kh\right),&\mathrm d\end{array}=\;\frac j{h\sqrt{1\;+\;\left({\displaystyle\frac kh}\right)^2}}$$

By rotating the goal pose p (around the x-axis direction of p by an angle \(\uptheta\), the optimized goal pose is obtained.

2.2 Numerical method

The approach outlined in this section relies on numerical optimization (Nocedal & Wright, 1999; Antoniou & Lu, 2007). It adopts an innovative strategy by constructing a Jacobian matrix associated with the rotation around the target coordinate frame for numerical iteration. The numerical optimization is grounded in the Levenberg–Marquardt method (Marquardt, 1963), chosen for its superior convergence properties compared to the Gauss–Newton method.

The Jacobian matrix of a 6-DoF robot consists of both the spatial Jacobian and the body Jacobian. The body Jacobian maps joint velocities to the angular velocity and linear velocity \({V}_{b}={\left[{\upomega }_{{\text{b}}},{\upupsilon }_{{\text{b}}}\right]}^{T}\) at the end-effector, based on the end-effector coordinate frame. \({\upomega }_{{\text{b}}}\) \(={\left[{\upomega }_{bx},{\upomega }_{by},{\upomega }_{bz}\right]}^{T}\) represents the angular velocity of the end-effector around the xyz-axes in its coordinate frame, and \({\upupsilon }_{b}={\left[{\upupsilon }_{bx},{\upupsilon }_{by},{\upupsilon }_{bz}\right]}^{T}\) represents the linear velocity of the end-effector along the xyz-axes in its coordinate frame. The definition of the Jacobian matrix based on screw axis is:

$$\begin{array}{cc}J_{bi}\left(\theta\right)=Ad_{e^{-\left[{\mathcal B}_{\mathcal n}\right]\theta_n}{...} e^{-\left[{\mathcal B}_{\mathcal i+1}\right]\theta_{i+1}}}\left({\mathcal B}_{\mathcal i}\right),&i=1,2,3,4,5,6\end{array}$$
(14)

The \({\mathcal{B}}_{\mathcal{i}}\) in Eq. 14 refers to the screw axis of the i-th joint based on the end-effector coordinate frame. \({J}_{bi}\) represents the i-th column of the Jacobian matrix based on the end-effector coordinate frame. Ad is the function to obtain the adjoint matrix. By multiplying the object Jacobian matrix with the velocity of each joint, we can obtain the instantaneous angular velocity and linear velocity of the end-effector in its own coordinate frame, which are given by:

$${V}_{b}={J}_{b}\dot{\theta }$$
(15)

To obtain the influence of a small rotation of the end-effector around its own normal (i.e., its own x-axis) on the joints of the entire robot, we can invert the object Jacobian \({J}_{b}\) to obtain its inverse \({J}_{b}^{-1}\), and then multiply it by the instantaneous velocity \({V}_{b}\) of the end-effector in its object coordinate frame. This gives us \(\dot{\theta }\):

$$\dot{\theta }={J}_{b}^{-1}{V}_{b}$$
(16)

As we are only interested in the angular velocity around the X-axis of the end-effector coordinate frame, we take the first column of \({J}_{b}^{-1}\):\({J}_{b1}^{-1}\), and multiply it by the angular velocity around the x-axis in the end-effector coordinate frame, \({\omega }_{bx}\):

$$\dot{\theta }={J}_{b1}^{-1}{\omega }_{bx}$$
(17)

Equation 17 represents the joint velocities \(\dot{\theta }\) of the robot's 6 axes when the robot's end-effector rotates around its own x-axis in the end-effector coordinate frame. Multiplying both sides of Eq. 17 by the time increment \({\text{dt}}\) and rearranging, we get:

$$\frac{d\theta }{d{\theta }_{bx}}={J}_{b1}^{-1}$$
(18)

The right-hand side of Eq. 18 represents the infinitesimal changes in the six axes of the robot when the end-effector undergoes a small rotation around its own normal axis (x-axis).

To incorporate this problem into a numerical optimization framework, we define the error \(e\) as a column vector of length n, where n is the number of joints in the robot. As this paper considers a 6-axis robot, n = 6:

$$\begin{array}{cc}e_i=\left(\theta_{last_i}-\theta_{current_i}\right)W_i,&i=1,2,3,4,5,6\end{array}$$
(19)

The variable \({\uptheta }_{{\text{last}}}\) in the equation represents the values of the 6 joints of the manipulator at the previous time step, while \({\uptheta }_{current}\) represents the current values of the 6 joints. The weighting factor \({\text{W}}={\left[{{\text{W}}}_{1},{{\text{W}}}_{2},{{\text{W}}}_{3},{{\text{W}}}_{4},{{\text{W}}}_{5},{{\text{W}}}_{6}\right]}^{T}\) is a column vector of length 6, which determines the degree of optimization for each error term. Before using \(W\), it is normalized so that each component is between 0 and 1. A component of 0 means that there is no optimization, while a component of 1 means that the optimization is carried out to the maximum extent possible.

In general robot building tasks, the values of the robot arm's joint angles need to be kept close to the robot's initial pose throughout the task. Equation 7 sets a proportional parameter \(p\), which determines how closely the joint angles need to be kept to the robot's initial pose.

$$\begin{array}{cc}\theta_{newlast}=\left(1-p\right)\theta_{last}+p\theta_{first},&0\leq p\leq1\end{array}$$
(20)

When p = 0, the optimization is completely based on the end-effector orientation in the previous goal pose, and when p = 1, it is completely based on the initial end-effector orientation at the beginning of the task. The modified equation:

$$\begin{array}{cc}e_i=\left(\left(\left(1-p\right)\theta_{last_i}+p\theta_{first_i}\right)-\theta_{current_i}\right)W_i,&i=1,2,3,4,5,6\end{array}$$
(21)

The cost value is obtained by taking the root-mean-square of the error vector \({\text{e}}\):

$$cost=\sqrt{\frac{{\sum }_{i=1}^{6}\left({e}_{i}^{2}\right)}{6}}$$
(22)

After defining the above variables, the subsequent phase involves initiating the optimization process. The primary objective of this optimization process is to enhance a series of input goal poses, resulting in an equivalent number of goal poses that have undergone a specific degree of rotation concerning their normal vectors. Our optimization procedure unfolds sequentially, focusing on optimizing each goal pose individually.

In the context of 3D printing, the proximity of each goal pose (< 20 mm) and the similarity in their orientations make it feasible to commence optimization from the second goal pose onward. In this strategy, the orientation component of the current goal pose is replaced with the optimized orientation from the preceding goal pose, while maintaining the positional component of the current goal pose unchanged. This methodology ensures that each goal pose optimization fully leverages the optimized outcomes of its predecessor.

In computing the gradient G, we compute the derivative of the error e with respect to the incremental rotation angle \({\text{d}}{\uptheta }_{bx}\) around the x-axis. Subsequently, we multiply this derivative by the weight vector W and apply Eq. 5. The resulting expression is as follows:

$$G=\frac{de}{d{\theta }_{bx}}=-W\frac{d{\theta }_{current}}{d{\theta }_{bx}}=-W{J}_{b1}^{-1}$$
(23)

The incremental equation:

$$\left(G{G}^{T}+\lambda \right)dx=-Ge$$
(24)

As \({{\text{GG}}}^{{\text{T}}}+\uplambda\) is a scalar, it can be derived as:

$$dx=\left(-Ge\right){\left({GG}^{T}+\lambda \right)}^{-1}$$
(25)

\(d{\text{x}}\) is the increment of a small rotation that we apply to the normal axis of each goal pose, and this slight perturbation takes the form of a rigid body transformation:

$${R}_{x}\left(\Delta x\right)=\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& {\text{cos}}\left(dx\right)& -{\text{sin}}\left(dx\right)& 0\\ 0& {\text{sin}}\left(dx\right)& {\text{cos}}\left(dx\right)& 0\\ 0& 0& 0& 1\end{array}\right]$$
(26)

Once \(d{\text{x}}\) is obtained, and if it is smaller than a predetermined threshold, the optimization for the current goal pose has completed, and the optimization process is terminated. Otherwise, the optimization process persists.

We denote the transformation of the i-th target coordinate frame relative to the world coordinate frame as \({T}_{i}\). With a small perturbation \(R{\text{x}}\), we can derive a new transformation \({T}_{newi}\) of the target coordinate frame relative to the world coordinate frame. Given that it is a rigid transformation based on the existing goal pose coordinate frame, we multiply \({R}_{x}\) on the right side of \({T}_{i}\).

$${T}_{ne{w}_{i}}={T}_{i}{R}_{x}$$
(27)

By using numerical inverse kinematic solution, the robot joint values \({\uptheta }_{new}\) corresponding to \({T}_{newi}\) can be obtained. The error \({\text{e}}\) and the cost corresponding to \({\uptheta }_{new}\) can be calculated through Eqs. 21 and 22, respectively. We compare the cost obtained in this calculation with the cost obtained in the previous iteration. If the current cost is greater than or equal to the last cost, we increase the step size by multiplying \(\uplambda\) by a number greater than 1, such as 2. If the current cost is less than the last cost, we take \({\uptheta }_{new}\) and \({T}_{ne{w}_{i}}\) as the robot joint values and the target optimization plane, respectively, for the current optimization iteration. We then update \(\uplambda\) by dividing it by the scale value to reduce \(\uplambda\). If the difference between the last cost and the cost is less than a threshold value, the optimization is considered to have converged, and finish the optimization. Finally, all optimized goal poses and corresponding robot joint values are obtained. The above process can be shown in detail through the flowchart in Fig. 5:

Fig. 5
figure 5

Numerical method diagram

In summary, this numerical optimization method builds upon the foundation of the Levenberg–Marquardt method, incorporating enhancements to refine the optimization of robot joints in a more granular manner. The key improvements encompass:

  • Inclusion of a Weight Parameter (\(W\)): Addition of a weight parameter \({\text{W}}\), which is introduced to regulate the extent of optimization for the involved robot joints.

  • Introduction of an Initial Pose Weighting Parameter (\(p\)): Integration of an initial pose weighting parameter, denoted as \(p\), is implemented to govern the influence of the robot's initial pose on the overall optimization process.

The outcomes of these enhancements will be explicated in next section. With the incorporation of these refinements, the optimization process has demonstrated commendable results.

2.3 Comparison

For a more comprehensive comparison of results, we employed a straightforward closed curve as the basis for the printing task. This closed curve was derived by projecting a planar closed curve onto a surface. Subsequently, we systematically divided the projected curve into equal segments, thereby acquiring a set of printing points.

Given the adaptability of numerical optimization to various end-effectors, we utilized a welding end-effector featuring a Y-axis offset and rotation. The specific parameters of the end-effector are as follows: X = -46.671 mm, Y = 49.886 mm, Z = 411.816 mm, A = 2.015°, B = -45.743°, and C = 0.

The comparative results for the three cases are illustrated in Fig. 6a:

  1. 1.

    The default goal pose in Fig. 6a(a).

  2. 2.

    When the initial angle weight parameter (p) is set to 0 and the axis weight parameter (\({\text{W}}\)) is defined as [0, 0, 0, 1, 0, 0]—indicating that only the A4 axis undergoes numerical optimization—the results are depicted in Fig. 6a(c).

  3. 3.

    The optimization results obtained by the analytical method in Fig. 6(b).

Fig. 6
figure 6

a The comparison between default, numerical and analytical methods (non-horizontal). b The comparison between default, numerical and analytical methods (horizontal)

Figure 6a(a) illustrates that the motion range of the fourth and sixth joints of the robot is significantly larger than the joint motion ranges in Fig. 6a(c) and Fig. 6a(b).

Figure 6a(c) shows that when only optimizing the fourth axis of the robot, the rotation value of the fourth joint remains almost 0 throughout the entire printing process. However, as shown in Fig. 6a(b), it is found that the fourth joint of the robot does not become 0 as in Fig. 6a(c) under the optimization of this analytical method. This is because the assumption made by this analytical method is that the y-axis offset of the end-effector is strictly zero, but the end-effector in this example does not conform this assumption. Nevertheless, even in this case, a more stable motion can be obtained using the analytical method. Therefore, by using the analytical method to obtain the first goal pose of the entire printing task, the axis joint values obtained by inverse kinematics when the robot moves to this optimized goal pose can be regarded as a good initial value, and then the remaining goal poses can be numerically optimized to obtain more robust results.

We do the same comparison in the case where the goal pose is horizontal Fig. 6b, and the results show that the analytical and numerical solutions do not significantly improve with respect to the default case. Special attention is paid to the horizontal case, the joint motion amplitudes of the 4th and 6th axis from which the analytical solution is the optimal choice.

3 Experiments

To verify the optimization effects based on the goal pose of the analytical method and numerical method in the application of 3D printing of non-horizontal layer-stacked concrete by a 6-axis robot, this study conducted software printing simulation and actual printing experiments. The three-dimensional modeling and construction of the non-horizontal layer-stacked printing plane were based on Rhino and Grasshopper software. The robot simulation and simulation were based on a Grasshopper plugin, FURobot, developed by the author in a previous study (Lu et al., 2020). The main function of this plugin is to input the goal pose set of the robot end-effector and generate G-code files that the robot can read. It is a robot manufacturing plugin designed for designers that connects the output of shape design to robot manufacturing files. In addition, the plugin can obtain the angle changes of each axis joint of the 6-axis robot in a printing job, and by analyzing the speed changes of the axis joints of the same robot in the same position to complete the same printing task process under two optimization methods, the advantages and disadvantages of different optimization methods can be analyzed.

3.1 3DCP system setup

The 3DCP system used in this study employs a KUKA KR90 R3700 robot. To enable the robot's 5-axis to move away from the zero point during the printing process and avoid singular poses as much as possible, the robot is set on a base at a height of 750 mm. The lifting of the concrete base allows the robot to achieve more complex spatial movements during printing without joint limits, which is beneficial for the 3D printing of complex curved surfaces. In previous research, a new type of "set on demand" concrete was developed (Yuan et al., 2022). The concrete is mixed with water in a mixing machine and pumped to the print head by a special concrete pump. At the same time, a quick-setting accelerator is pumped through another channel into the print head by another pump. The concrete and quick-setting accelerator are mixed at high speed in the print head, and then extruded through a nozzle for printing. Figure 7 shows the hardware setup of this 3DCP system.

Fig. 7
figure 7

Shows the setup of the 3DCP system, including (a) Mortar mixing and pumping machines, (b) Accelerator pump, (c) KUKA KR90 R3700 set on a 750mm height standoff, (d) Multi-component extruder end-effector

3.2 Design of test samples

To validate the optimization effects of numerical and analytical methods for robot posture under non-horizontal layer printing, a standardized printing object needs to be constructed and the goal pose set of the end-effector coordinate during the printing process needs to be obtained. Using the Rhino platform and Grasshopper parametric modeling software, a centrally symmetric shape with a maximum width of 690 mm * 690 mm and a maximum height of 795 mm was constructed. The overall shape is high in the middle and low around it, with overhangs in four directions as shown in Fig. 8. Based on previous printing experience, this shape is divided into 66 layers, with a layer height variation range of 8.7 mm to 12.5 mm, which is a common setting suitable for this printing system and can ensure good printing results.

Fig. 8
figure 8

A centrally symmetric shape with a maximum width of 690mm * 690mm and a maximum height of 795mm was designed. a Front view, b Top view

Using Grasshopper software, the goal pose of the robot end-effector for printing this shape was obtained, with a total of 9657 goal poses, as shown in Fig. 9. The goal pose of the end-effector is tilted and changing at every moment, and this printing task requires the end-effector to have 5 degrees of freedom.

Fig. 9
figure 9

The goal pose of the end-effector is tilted and changing at every moment

3.3 Printing experiment

This study conducted three sets of printing experiments. In the first set, the goal poses were not optimized and were directly inputted to the robot. In the second set, the numerical method was used for optimization, and in the third set, the analytical method was used for optimization. In the first set, the printing simulation could not be passed due to axis joint limits errors without optimizing the goal poses. The second and third sets passed the printing simulation and completed the printing of the test specimens in the same position under the same conditions, such as material formulation, environmental temperature, and post-curing time. The three sets of experimental conditions are shown in the Fig. 10. Although both the numerical and analytical methods completed the printing experiment, there were significant differences in the Angle-time change curve and the robot.

Fig. 10
figure 10

a Using the initial goal pose, the Angle-time curve does not converge, resulting in uncontrolled axis angles of the robot. The simulation in the FURobot program indicates that the printing process cannot be completed. The red portion represents axis angles that exceed the limitations of the robot. b Applying numerical methods to optimize the plane allows for successful printing. c Employing analytical methods to optimize the plane also enables successful printing

3.4 Results comparison

3.4.1 Simulation results

By examining the axis-time graph, for the unoptimized group, when the robot is printing the upper part, the values of axes a4 and a6 greatly exceed the limit, and the absolute values continue to increase. Obviously, these unoptimized goal poses cannot be printed. By comparing the two optimized groups through the axis-time graph, it can be found that the entire task can be completed by the robot through the optimization of numerical and analytical methods. When the robot is executing the task of the planes generated by the numerical solution, the maximum absolute value of the axis with the largest range of motion is less than 180˚, while the same value in the analytical solution is close to 300˚. At the same time, the results from the numerical method also have smaller ranges of motion for each individual joint compared to those from the analytical method. For example, the maximum range of motion of joint a6 occurs in the final stage of the printing task with an absolute amplitude of less than 100˚ in the numerical method, while in the analytical solution, the absolute amplitude is about 150˚. In the actual printing comparison, the values of the fifth joint under the numerical method are generally greater than those under the analytical method. In the above indicators, the numerical method is better than the analytical method. On the other hand, the biggest advantage of the analytical method compared to the numerical method is its high computational efficiency. On a regular personal computer, the numerical method takes about 5300 ms to calculate the 9657 target points, while the analytical method only takes 0.0009 ms. Figure 11 shows the variation amplitude of axis angles in three different situations.

Fig. 11
figure 11

The variation amplitude of the six axes of the robot in three different situations. a Default goal poses without optimization, the variation amplitude of A4 and A6 is extreme large. Due to the large variation in axis angles, the robot is unable to perform the printing process. b After optimizing the default goal poses using two different optimization methods, the variation amplitude of the axis angles significantly decreases. As a result, the robot can accurately read the angles and execute the printing process

We split an average of 200 time periods throughout the printing process and collected 200 sampling points Fig. 12, and calculate the standard deviation of each joint value at the sampling point. The standard deviation of the analytical solution and the numerical solution are far less than the default case Fig. 13, and the overall fluctuation of the joint motion obtained by the numerical solution is the smallest, which is the best:

Fig. 12
figure 12

Standard deviation of robot axis in default, analytical and numerical case

Fig. 13
figure 13

The comparison of standard deviation

3.4.2 Printing results

By comparing the printing results of the two samples, both optimization methods achieved relatively good surface quality of the prints, and successfully completed the 3D printing task.

3.5 Case study

The two optimization methods based on the goal pose mentioned above can be applied to relevant scenarios in non-horizontal layered concrete 3D printing. The research case proposed in this paper (Wu et al., 2022) utilized the analytical method presented in this study to optimize the goal pose. (Fig. 14).

Fig. 14
figure 14

(Left) Completed spatial structure, (Right) cables within the spatial structure

To achieve the construction of this 3D spatial prototype, the structure was divided into 18 building components. Among these 18 components, 6 (with numbers) can be manufactured using traditional methods, while the other 12 (with numbers) require non-horizontal printing in Fig. 15.

Fig. 15
figure 15

Display of 18 divided sections

At the beginning of this case, we tried to use the default goal pose, and robot could not complete the simulation because of the joint limit (as shown in Fig. 10a). The goal poses must be optimized. Because the workload is relatively large, the analytical solution has advantages in computational efficiency, and it can successfully complete the printing simulation, so we use the analytical method to ensure that the robot program generation can be completed on time.

4 Discussion

4.1 Joint weights

In the numerical method outlined in this paper, the optimization degree of each joint can be regulated by configuring the joint weight \({\text{W}}\). Each joint is assigned a numerical value in the range of 0 to 1, signifying its weight. We conducted a comparison of results by assigning a weight of 1 to only one joint and 0 to the other joints, as depicted in Fig. 16.

Fig. 16
figure 16

The comparison between different joint weights. a is the case that only the 1st joint (A1) is optimized; b is the case that only the 2st joint (A2) is optimized; c is the case that only the 3st joint (A3) is optimized; d is the case that only the 4st joint (A4) is optimized; e is the case that only the 5st joint (A5) is optimized; f is the case that only the 6st joint (A6) is optimized; g is the case that all the joints are optimized equally

Figure 16 illustrates that through numerical iteration, the motion of a specific axis can be constrained within a very narrow range, essentially restricting the motion of that particular joint. Figure 16a-f showcase the limitation of the motion of a single joint. It is evident that the analytical method proposed in this paper can only limit the motion of the fourth joint, whereas the numerical method is capable of constraining the motion of all joints of the robot.

Fig. 16g demonstrates that when all joint weights are equal, optimizing all joints generally results in reducing the motion range of other joints by optimizing either 4th or 6th joint, approximating the effect of optimizing all joints.

4.2 Initial joint weights

In standard contouring printing, the robot is expected to maintain a similar pose at the starting and ending positions of each layer. However, in printing tasks where the normal vector direction of the goal pose varies significantly, the robot's pose at the starting and ending positions of the same layer can differ, leading to divergence in joint values and, ultimately, printing failure. To address this issue in the numerical method, an initial joint weight parameter is introduced. By configuring this parameter, as shown in Fig. 17, the problem can be resolved.

Fig. 17
figure 17

Set initial joint weight to 0 and 0.02

The above figure indicates that when p \(=0\), there is a noticeable difference in the joint values of 4th, 5th, and 6th joint between the beginning and end of the printing task when optimizing the 2nd axis. However, after setting \(p\) to 0.02, the distance value is nearly zero.

5 Conclusion

5.1 Summary of contributions

The main contribution of this paper lies in optimizing 6-axis robots with redundant degrees of freedom based on the goal pose, achieving joint motion optimization through modifications to the printing goal pose. The paper extensively elaborates on the calculation processes involved in both analytical and numerical methods. Feasibility of the two algorithms is validated through practical examples, particularly in the context of concrete 3D printing in construction. The paper also discusses the optimization results under different parameters.

The conclusions of the related simulations and experimental verifications are summarized as follows:

  • The plane optimization methods based on numerical and analytical methods can allow the robot to complete redundant degree of freedom 3D printing jobs with the smallest possible changes in axis under the optimized planes, while the unoptimized planes cannot print or the robot terminates the job due to exceeding the axis speed limit during printing.

  • The optimization methods proposed in this paper can be applied to any additive or subtractive manufacturing process under any end-effector.

  • Numerical iterative methods are generally suitable for general end-effectors and provide more detailed joint control, such as the ability to set joint weights.

  • The utilization of analytical methods to provide well-established initial values for numerical optimization serves to prevent the optimization process from getting trapped in local optima.

  • Analytical methods are used for specific end-effectors and are more computationally efficient than numerical methods. Analytical methods are a better choice under horizontal goal pose. The best approach is to choose the solution by comparing 3 approaches (default, analytical, numerical).

  • Since the general robot task is linear motion at constant speed, this method will not optimize the printing time (unless the robot is using joint motion mode).

  • Because analytical and numerical methods can optimize the default target pose to avoid the joint limits of the robot, the robot can perform tasks with a larger range of distances and tilt angles.

5.2 Future work

The goal pose-based six-axis robot joint optimization methods proposed in this paper provides a convenient workflow, offering a method for optimizing non-horizontal printing.

The prospective avenues for enhancing this study are outlined as follows:

  1. 1.

    Incorporate Collision Detection and Address Singularity Points for Optimization: Integrate collision detection mechanisms and address singularity points to fortify the optimization process, enhancing its practical applicability.

  2. 2.

    Expand Numerical Methods to Accommodate 7-Axis and Multi-Axis Robots: Extend the numerical optimization methods to encompass 7-axis and multi-axis robots, broadening the scope of application and adaptability of the proposed techniques.

  3. 3.

    Broaden Analytical Methods to Constrain the Rotation of Additional Joints: Expand the analytical methods to impose constraints on the rotation of joints beyond the fourth joint, thereby providing a more comprehensive framework for controlling the robot's motion.

These proposed advancements aim to augment the robustness, versatility, and effectiveness of the optimization techniques delineated in this study.