Constructor
new Robot(scale)
Constructs a new instance of Robot. Will automatically load the required
assets to animate the robot.
Parameters:
Name | Type | Description |
---|---|---|
scale |
number | The scale to animate the quadruped at, the obj files naturally are animated with sub pixel sizes. |
Methods
base_draw()
Draws the top base plate of the robot on the canvas.
draw(tx, ty, tz, rx, ry, rz)
Draws the robot on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
tx |
number | x translation parameter in pixels. |
ty |
number | y translation parameter in pixels. |
tz |
number | z translation parameter in pixels. |
rx |
number | Rotation around the x axis in radians. |
ry |
number | Rotation around the y axis in radians. |
rz |
number | Rotation around the z axis in radians. |
home(i)
Function to return the quadruped to the seated position with legs
above the base and folded neatly.
Parameters:
Name | Type | Description |
---|---|---|
i |
number | Increment value to determine how close to the final position the servos should be. Value is given between 0 and 1 with 1 being the final position. |
lb_draw()
Draws the left back leg of the robot on the canvas.
lb_servos_read() → {Array.<number>}
Function to give the angle of the 3 servos of the left back leg of the
robot in radians from 0 to PI.
Returns:
An array of angle values in radians denoting
the angles of the: hip yaw, hip elevation
and the knee servos from index 0-2
respectively.
- Type
- Array.<number>
lb_servos_write(new_angles)
Function to write new values to the 3 servos of the left back leg of
the robot. The order of the angles is as follows: hip yaw, hip elevation
and knee servo are index from 0-2 respectively.
Parameters:
Name | Type | Description |
---|---|---|
new_angles |
Array.<number> | The new servo angles in radians from 0 to PI. |
lerp_angles(start, end, i) → {Array.<number>}
Function to calculate the linear interpolation of a set of 3 angles.
This is calculated between the start and end sets using the given
increment. The i parameter is the amount to interpolate between the
two sets where 0.0 equal to the first set, 0.1 is very near the first
set, 0.5 is half-way in between them, and 1.0 is equal to the second set.
If the value of i is more than 1.0 or less than 0.0, the number will be
calculated accordingly in the ratio of the two given numbers. This usage
however is not recommended as it may lead to servo values that the exceed
the specification and are impossible to reach.
Parameters:
Name | Type | Description |
---|---|---|
start |
Array.<number> | The start set of angles in radians between 0 and PI. |
end |
Array.<number> | The end set of angles in radians between 0 and PI. |
i |
number | The increment value, it is suggested that this remains between 0 and 1. |
Returns:
An array of interpolated angle values.
- Type
- Array.<number>
lf_draw()
Draws the left front leg of the robot on the canvas.
lf_servos_read() → {Array.<number>}
Function to give the angle of the 3 servos of the left front leg of the
robot in radians from 0 to PI.
Returns:
An array of angle values in radians denoting
the angles of the: hip yaw, hip elevation
and the knee servos from index 0-2
respectively.
- Type
- Array.<number>
lf_servos_write(new_angles)
Function to write new values to the 3 servos of the left front leg of
the robot. The order of the angles is as follows: hip yaw, hip elevation
and knee servo are index from 0-2 respectively.
Parameters:
Name | Type | Description |
---|---|---|
new_angles |
Array.<number> | The new servo angles in radians from 0 to PI. |
load_legs()
Loads the upper and lower leg obj files from the assets folder.
load_parts()
Loads the obj parts from the assets folder.
load_servos()
Loads the obj servos from the assets folder.
rb_draw()
Draws the right back leg of the robot on the canvas.
rb_servos_read() → {Array.<number>}
Function to give the angle of the 3 servos of the right back leg of the
robot in radians from 0 to PI.
Returns:
An array of angle values in radians denoting
the angles of the: hip yaw, hip elevation
and the knee servos from index 0-2
respectively.
- Type
- Array.<number>
rb_servos_write(new_angles)
Function to write new values to the 3 servos of the right back leg of
the robot. The order of the angles is as follows: hip yaw, hip elevation
and knee servo are index from 0-2 respectively.
Parameters:
Name | Type | Description |
---|---|---|
new_angles |
Array.<number> | The new servo angles in radians from 0 to PI. |
rf_draw()
Draws the right front leg of the robot on the canvas.
rf_servos_read() → {Array.<number>}
Function to give the angle of the 3 servos of the right front leg of the
robot in radians from 0 to PI.
Returns:
An array of angle values in radians denoting
the angles of the: hip yaw, hip elevation
and the knee servos from index 0-2
respectively.
- Type
- Array.<number>
rf_servos_write(new_angles)
Function to write new values to the 3 servos of the right front leg of
the robot. The order of the angles is as follows: hip yaw, hip elevation
and knee servo are index from 0-2 respectively.
Parameters:
Name | Type | Description |
---|---|---|
new_angles |
Array.<number> | The new servo angles in radians from 0 to PI. |
servos_read() → {Array.<number>}
Function to give the angle of all 12 servos of the quadruped robot. The
order of the legs is: right front, left front, right back, left back. In
each leg the order of the servos is: hip yaw, hip elevation and knee.
Therefore the first index is the hip yaw for the right front leg and the
last index is the knee for the left back leg.
Returns:
An array of angle values in radians denoting
the angles of the: hip yaw, hip elevation
and the knee servos from index 0-2
respectively.
- Type
- Array.<number>
servos_write(new_angles)
Function to write new values to all 12 servos on the quadruped robot. The
order of the legs is: right front, left front, right back, left back. In
each leg the order of the servos is: hip yaw, hip elevation and knee.
Therefore the first index is the hip yaw for the right front leg and the
last index is the knee for the left back leg.
Parameters:
Name | Type | Description |
---|---|---|
new_angles |
Array.<number> | The new servo angles in radians from 0 to PI. |
stand90(i)
Function to return the quadruped to the standing position with all servos
at 90 degrees, or HALF_PI radians.
Parameters:
Name | Type | Description |
---|---|---|
i |
number | Increment value to determine how close to the final position the servos should be. Value is given between 0 and 1 with 1 being the final position. |
under_base_draw()
Draws the bottom base plate of the robot on the canvas.
walk(control, i) → {boolean}
Function to control the motion of the robot. The order of the control
parameters in the array are as follows:
[0] walking x [1] walking y [2] walking rotation
[3] static offset x [4] static offset y [5] static offset z
[6] static offset yaw [7] static offset pitch [8] static offset roll
Parameters:
Name | Type | Description |
---|---|---|
control |
Array.<number> | The control values array |
i |
number | Increment value |
Returns:
Success condition depending on correct input
parameters and valid servo motions.
- Type
- boolean