Introdução à Robótica com Three.js

ENEI 2018






March 2018

Henrique Ferrolho

Agenda


  • Introdução

  • Demo 2D

  • Three.js

  • Perguntas

Dialecto


Atlas (Boston Dynamics)
  • Joint, link, end-effector

  • Base fixa / flutuante
  • Fixed / floating base

  • Configuração, q
  • Configuration, q

  • Graus de liberdade
  • Degrees of freedom

  • Curse of dimensionality
Valkyrie (NASA)

Demo 2D

[Link]

Cada cor controla um grau de liberdade.

Cinemática (Kinematics)

"É o ramo da física que se ocupa da descrição dos movimentos dos corpos, sem se preocupar com a análise das forças em causa (dinâmica)".

Directa
Forward Kinematics, FK

Dada uma configuração q,
onde está o end-effector?
Inversa
Inverse Kinematics, IK

Dada uma pose, quais são
as configurações possíveis?

Animação Digital

De que forma se relaciona com robótica?

Phase-Functioned Neural Networks for Character Control
Bio IK for Generic Inverse Kinematics in Unity3D

Three.js

Three.js

// #enei2018 ...


// Reset configuration
$('#reset-button').click(function () {
    // #enei2018 ...
})

// Random configuration
$('#random-button').click(function () {
    // #enei2018 ...
})
							

 
src/app.js — 7 ocurrências

src/js/Robot.js — 4 ocurrências





Sugestões de implementação






src/js/Robot.js

Three.js


get configuration () {
    // #enei2018 ...
}
                            

get zeroConfiguration () {
    // #enei2018 ...
}
                            

if (this._kinematics.joints.hasOwnProperty(prop)) {
    const joint = this._kinematics.joints[prop]
    if (!joint.static) {
        // #enei2018 ...
    }
}
                            

// set configuration (q) { ... }








// #enei2018 ...
                            

Three.js


get configuration () {
    return this._q.slice()
}
                            

get zeroConfiguration () {
 return new Array(this.degreesOfFreedom + 1).join('0').split('').map(parseFloat)
}
                            

if (this._kinematics.joints.hasOwnProperty(prop)) {
    const joint = this._kinematics.joints[prop]
    if (!joint.static) {
        q.push(THREE.Math.randFloat(joint.limits.min, joint.limits.max))
    }
}
                            

// set configuration (q) { ... }
this._q = q.slice()
q = q.slice()
for (const prop in this._kinematics.joints) {
    if (this._kinematics.joints.hasOwnProperty(prop)) {
        if (!this._kinematics.joints[prop].static) {
            this.setJointValue(prop, q.shift())
        }
    }
}
                            





src/app.js

Three.js


// Reset configuration
$('#reset-button').click(function () {
    // #enei2018 ...
})

// Random configuration
$('#random-button').click(function () {
    // #enei2018 ...
})
							

for (let i = 0; i < 1e4; i++) {


	
    // #enei2018 ...



}
							

Three.js


// Reset configuration
$('#reset-button').click(function () {
    robot.configuration = robot.zeroConfiguration
})

// Random configuration
$('#random-button').click(function () {
    robot.configuration = robot.randomConfiguration
})
							

for (let i = 0; i < 1e4; i++) {
    robot.configuration = robot.randomConfiguration

    for (let j = 0; j < robot.tipLinks.length; j++) {
        const point = new THREE.Vector3()
        point.setFromMatrixPosition(robot.getLinkPose(robot.tipLinks[j]))
        rawPoints[j].push(point)
    }
}
							

Three.js


case 72: // H
    console.log(`Moving robot to 'home' position`)
    // #enei2018 ...
    break
case 80: // P
    console.log('Executing motion...')
    // #enei2018 ...
    break
                            

// Initialises data structures for tween.js



// #enei2018 ...
						    

kinematicsTween.onUpdate(function () {
    // Update robot configuration, joint by joint.
    // #enei2018 ...
})
						    

Three.js


case 72: // H
    console.log(`Moving robot to 'home' position`)
    moveFromTo(robot.configuration, robot.zeroConfiguration)
    break
case 80: // P
    console.log('Executing motion...')
    moveFromTo(robot.configuration, robot.randomConfiguration)
    break
                            

// Initialises data structures for tween.js
for (const joint of robot._joints) {
    tweenStart[joint] = q_s.shift()
    tweenFinal[joint] = q_t.shift()
}
                            

kinematicsTween.onUpdate(function () {
    // Update robot configuration, joint by joint.
    for (const j of robot._joints) { robot.setJointValue(j, this[j]) }
})
                            





Fim