The main mechanism consists of the crank and the two links inside the base and the bear's body. This mechanism drives the arm and the head movement.
We can consider the mechanism to be divided in two parts:
-The crank and first link within the base.
-The first and second link within the body.
Both links can be modeled as a slotted link with the physical slots being grounded pins on which the links rotate and slide.
By solving the loop equation for the first part of the mechanism we get 2 equations to define the rotation θ3 and length of b1.
The second part of the mechanism depends on the angle and length of link b. The top part of link b extends into the body of the bear and drives the motion of link d. We define the angle of the top part of link b as θ32 and the length that extends into the body as b2.
In general the angle of b2 is the same as b1, the Matlab code, however, outputs the angle as a negative, since it is calculating the vector going down. We can simply use the absolute value of the angle to get θ32. The length b2 is then defined as the difference between length b and length b1. The length changes depending on the angle of the crank.
The height and offset of the top slot remains constant so we can find the length of d with simple trigonometry.