<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MITRA と FR3 の粗い3D</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Zen+Kaku+Gothic+New:wght@400;500;700&display=swap" rel="stylesheet">
<style>
/* layout: one working drawing. viewer on top, the numbers that built it underneath, in two columns */
:root{--paper:#F2F4F1;--panel:#E6EAE5;--ink:#1B2227;--mute:#56626B;--line:#C5CCC6;--accent:#1663A6;--guess:#8A5A0B;
  --body:"Zen Kaku Gothic New","Hiragino Sans","Yu Gothic",sans-serif;--mono:"IBM Plex Mono",ui-monospace,Menlo,monospace}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){color-scheme:dark;--paper:#14191C;--panel:#1D2428;--ink:#E7ECE8;--mute:#9AA7AE;--line:#33403F;--accent:#6FB4EE;--guess:#E0B25C}}
:root[data-theme="dark"]{color-scheme:dark;--paper:#14191C;--panel:#1D2428;--ink:#E7ECE8;--mute:#9AA7AE;--line:#33403F;--accent:#6FB4EE;--guess:#E0B25C}
*{box-sizing:border-box}
body{margin:0;background:var(--paper);color:var(--ink);font-family:var(--body);font-size:15px;line-height:1.75}
main{max-width:1040px;margin:0 auto;padding:24px 20px 48px;display:flex;flex-direction:column;gap:20px}
h1{font-size:22px;font-weight:700;margin:0;text-wrap:balance}
h2{font-size:15px;font-weight:700;margin:0 0 8px}
p{margin:0}
@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}
</style>
</head>
<body>
<main>
<style>
.lead{color:var(--mute);max-width:42em}
</style>
<header>
  <h1>MITRA の前の端に FAIRINO FR3 を載せた形</h1>
  <p class="lead">台車は公表された寸法から箱で組み、アームは FAIRINO が公開している形のデータをそのまま読んでいます。ドラッグで回せます。</p>
</header>

<style>
.viewer{position:relative;background:var(--panel);border:1px solid var(--line);border-radius:10px;overflow:hidden}
#stage{display:block;width:100%;height:min(62vh,560px);min-height:360px;touch-action:none;cursor:grab}
#stage:active{cursor:grabbing}
.bar{display:flex;flex-wrap:wrap;gap:8px;padding:10px 12px;border-top:1px solid var(--line);align-items:center}
.bar span{font-size:12px;color:var(--mute);margin-right:2px}
.bar .sp{flex:1 1 12px}
button{font:inherit;font-size:13px;line-height:1.2;padding:8px 12px;border-radius:7px;border:1px solid var(--line);background:var(--paper);color:var(--ink);cursor:pointer}
button:hover{border-color:var(--mute)}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
button[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:var(--paper)}
#state{padding:10px 14px;border-top:1px solid var(--line);font-size:14px}
#state b{font-weight:700}
#err{padding:10px 14px;color:var(--guess);font-size:13px}
</style>
<section class="viewer" aria-label="3Dの表示">
  <canvas id="stage"></canvas>
  <div class="bar" role="group" aria-label="腕の姿勢">
    <span>姿勢</span>
    <button id="p-fold" data-pose="fold" aria-pressed="false">走るとき</button>
    <button id="p-pick" data-pose="pick" aria-pressed="false">段ボールから取る</button>
    <button id="p-tray" data-pose="tray" aria-pressed="false">荷台に積む</button>
    <button id="p-place" data-pose="place" aria-pressed="true">棚に並べる</button>
    <div class="sp"></div>
    <span>視点</span>
    <button id="v-iso" data-view="iso">斜め</button>
    <button id="v-side" data-view="side">横</button>
    <button id="v-front" data-view="front">前</button>
    <button id="v-top" data-view="top">上</button>
    <button id="z-in" aria-label="近づく">＋</button>
    <button id="z-out" aria-label="離れる">−</button>
  </div>
  <div id="state"></div>
  <div id="err" hidden></div>
</section>

<style>
.cols{display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:20px}
table{border-collapse:collapse;width:100%;font-size:14px}
th,td{text-align:left;padding:6px 8px 6px 0;border-bottom:1px solid var(--line);vertical-align:top}
th{font-weight:500;color:var(--mute);width:52%}
td{font-family:var(--mono);font-variant-numeric:tabular-nums;font-size:13px}
.g{color:var(--guess);font-family:var(--body);font-size:12px;margin-left:6px;white-space:nowrap}
.note{font-size:13px;color:var(--mute);max-width:46em}
.note a{color:inherit;text-decoration:underline;text-underline-offset:3px}
</style>
<section class="cols">
  <div>
    <h2>MITRA（スズキの広報資料の値・試作段階）</h2>
    <table>
      <tr><th>全長 × 全幅</th><td>1,015 × 590 mm</td></tr>
      <tr><th>荷台</th><td>887 × 401 mm、高さ 355 mm</td></tr>
      <tr><th>重さ / 積める重さ</th><td>85 kg / 100 kg</td></tr>
      <tr><th>タイヤ</th><td>外径 260 × 幅 85 mm</td></tr>
      <tr><th>前後の車輪の間隔</th><td>620 mm<span class="g">推定</span></td></tr>
      <tr><th>車体の箱・ばね・取っ手の形</th><td>動画から<span class="g">推定</span></td></tr>
    </table>
  </div>
  <div>
    <h2>FAIRINO FR3（公式の ROS モデルから読んだ値）</h2>
    <table>
      <tr><th>付け根</th><td>直径 128 mm、高さ 80 mm</td></tr>
      <tr><th>肩の高さ</th><td>140 mm</td></tr>
      <tr><th>上の腕 / 前の腕</th><td>280 / 240 mm</td></tr>
      <tr><th>手首のずれ</th><td>102 mm が2か所</td></tr>
      <tr><th>載せた位置</th><td>荷台の前の端から 65 mm</td></tr>
      <tr><th>つかむ道具</th><td>長さ 150 mm<span class="g">仮の形</span></td></tr>
    </table>
  </div>
</section>
<p class="note">FR3 の形のデータは、FAIRINO が <a href="https://github.com/FAIR-INNOVATION/frcobot_ros" target="_blank" rel="noopener">frcobot_ros</a> で Apache License 2.0 として公開しているものを、三角形の数を減らして使っています（<a href="NOTICE.txt">変えたこと</a>・<a href="LICENSE-FR3-model.txt">ライセンスの本文</a>）。スズキ・FAIRINO とは関係のない個人の研究です。記録は <a href="/series10">MITRAとFAIRINOで、まだないロボットをつくる</a> にあります。</p>
<p class="note">制御箱（270 × 300 × 200 mm）、荷台のコンテナ（400 × 300 × 150 mm）、段ボール（450 × 380 × 300 mm）、台（高さ 150 mm）、棚（幅 900・奥行き 350、段の高さ 150 / 500 / 850 mm）は、設計の検討で置いた仮の大きさです。</p>

<script src="three.min.js"></script>
<script>
(function(){
const D=Math.PI/180;
const POSES={
  fold:{q:[0,-125,140,-105,-90,0],scene:'none',hold:false,text:'<b>走るとき</b>　腕を畳んで、荷台の幅の中に収めます。重さの中心が低いまま走れます。'},
  pick:{q:[-19.5,-44.0,137.8,-183.8,-90,0],scene:'pallet',hold:true,text:'<b>段ボールから取る</b>　高さ150mmの台に置いた段ボールの、底の商品をつかみます。'},
  tray:{q:[157.4,-104.5,132.1,-117.6,-90,0],scene:'pallet',hold:true,text:'<b>荷台に積む</b>　腕を後ろへ回して、荷台のコンテナに置きます。'},
  place:{q:[-18.9,-98.7,91.9,-83.2,-90,0],scene:'shelf',hold:true,text:'<b>棚に並べる</b>　棚の上の段（高さ500mm）に置きます。届くのは荷台の前の端から約47cmまでです。'}
};
const VIEWS={iso:[38,20,2.5],side:[0,6,2.5],front:[90,8,2.3],top:[0,88,2.6]};
const canvas=document.getElementById('stage');
const renderer=new THREE.WebGLRenderer({canvas,antialias:true,alpha:true});
renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,2));
const scene=new THREE.Scene();
const cam=new THREE.PerspectiveCamera(32,1,0.05,30);
scene.add(new THREE.HemisphereLight(0xffffff,0x70777c,0.8));
const sun=new THREE.DirectionalLight(0xffffff,0.55);sun.position.set(1.5,3,2);scene.add(sun);
const fill=new THREE.DirectionalLight(0xffffff,0.2);fill.position.set(-2,1,-1.5);scene.add(fill);

const W=new THREE.Group();W.rotation.x=-Math.PI/2;scene.add(W);
const mat=(c,o)=>new THREE.MeshStandardMaterial(Object.assign({color:c,roughness:0.65,metalness:0.05},o||{}));
function box(p,sx,sy,sz,x,y,z,m){const b=new THREE.Mesh(new THREE.BoxGeometry(sx,sy,sz),m);b.position.set(x,y,z);p.add(b);return b}
function cyl(p,r,len,axis,x,y,z,m){const c=new THREE.Mesh(new THREE.CylinderGeometry(r,r,len,28),m);if(axis==='z')c.rotation.x=Math.PI/2;if(axis==='x')c.rotation.z=Math.PI/2;c.position.set(x,y,z);p.add(c);return c}

const grid=new THREE.GridHelper(4,20,0x7f8a8f,0x9aa4a8);grid.material.transparent=true;grid.material.opacity=0.45;scene.add(grid);

const M={alu:mat(0xC4C8CC,{metalness:0.35,roughness:0.4}),blk:mat(0x23272A),tyre:mat(0x1A1C1E,{roughness:0.9}),hub:mat(0x9CA1A6,{metalness:0.3}),spring:mat(0xD9DCDE,{metalness:0.4}),
  ctrl:mat(0xCFCDC3),tray:mat(0x3FA884),wood:mat(0xB98A4B),card:mat(0xD9A441),item:mat(0x3F86D8),steel:mat(0x6B757C,{metalness:0.3}),arm:mat(0xECEEEF,{roughness:0.45}),armBase:mat(0x3B4146),grip:mat(0x2D3236)};

const DECK_H=0.355,DECK_L=0.887,DECK_W=0.401;
const mitra=new THREE.Group();W.add(mitra);
box(mitra,DECK_L,DECK_W,0.04,-DECK_L/2,0,DECK_H-0.02,M.alu);
box(mitra,DECK_L/2-0.04,DECK_W-0.06,0.004,-DECK_L*0.25-0.005,0,DECK_H+0.001,M.blk);
box(mitra,DECK_L/2-0.04,DECK_W-0.06,0.004,-DECK_L*0.75+0.005,0,DECK_H+0.001,M.blk);
box(mitra,0.74,0.30,0.21,-0.45,0,0.205,M.blk);
box(mitra,0.03,0.14,0.09,-0.07,0,0.21,M.spring);
const AX_F=-0.135,AX_R=-0.755,WY=0.2525,WR=0.13;
[[AX_F,1],[AX_F,-1],[AX_R,1],[AX_R,-1]].forEach(a=>{
  cyl(mitra,WR,0.085,'y',a[0],a[1]*WY,WR,M.tyre);
  cyl(mitra,0.062,0.09,'y',a[0],a[1]*WY,WR,M.hub);
  cyl(mitra,0.02,0.1,'y',a[0],a[1]*0.18,WR,M.blk);
  const s=cyl(mitra,0.017,0.17,'z',a[0]+(a[0]>-0.4?-0.06:0.06),a[1]*0.165,0.235,M.spring);s.rotation.y=a[1]*0.25;
});
cyl(mitra,0.011,0.34,'y',-DECK_L-0.11,0,DECK_H-0.02,M.steel);
[1,-1].forEach(s=>cyl(mitra,0.011,0.12,'x',-DECK_L-0.055,s*0.17,DECK_H-0.02,M.steel));

box(mitra,0.27,0.30,0.20,-DECK_L+0.145,0,DECK_H+0.10,M.ctrl);
const tray=new THREE.Group();tray.position.set(-0.33,0,DECK_H);mitra.add(tray);
box(tray,0.40,0.30,0.008,0,0,0.004,M.tray);
[[0,0.146,0.40,0.008],[0,-0.146,0.40,0.008],[0.196,0,0.008,0.30],[-0.196,0,0.008,0.30]].forEach(w=>box(tray,w[2],w[3],0.15,w[0],w[1],0.075,M.tray));
const trayItems=[[-0.1,0.07],[0.02,0.07],[-0.1,-0.06]].map(p=>box(tray,0.07,0.07,0.10,p[0],p[1],0.058,M.item));

const pallet=new THREE.Group();W.add(pallet);
box(pallet,0.46,0.52,0.025,0.24,0,0.1375,M.wood);box(pallet,0.46,0.52,0.02,0.24,0,0.01,M.wood);
[-0.2,0,0.2].forEach(y=>box(pallet,0.46,0.08,0.105,0.24,y,0.0725,M.wood));
box(pallet,0.38,0.45,0.006,0.24,0,0.153,M.card);
[[0.05,0,0.006,0.45],[0.43,0,0.006,0.45],[0.24,0.222,0.38,0.006],[0.24,-0.222,0.38,0.006]].forEach(w=>box(pallet,w[2],w[3],0.30,w[0],w[1],0.30,M.card));
[[0.13,0.13],[0.13,-0.12],[0.35,0.12],[0.35,-0.02],[0.24,-0.14],[0.13,0.01]].forEach(p=>box(pallet,0.07,0.07,0.10,p[0],p[1],0.206,M.item));

const shelf=new THREE.Group();W.add(shelf);
[[0.06,0.44],[0.06,-0.44],[0.39,0.44],[0.39,-0.44]].forEach(p=>box(shelf,0.025,0.025,0.86,p[0],p[1],0.43,M.steel));
[0.15,0.5,0.85].forEach(h=>box(shelf,0.35,0.9,0.018,0.225,0,h-0.009,M.alu));
[[0.2,0.3,0.15],[0.2,0.2,0.15],[0.3,-0.25,0.15],[0.22,0.22,0.5],[0.22,0.12,0.5],[0.3,-0.3,0.5]].forEach(p=>box(shelf,0.07,0.07,0.10,p[0],p[1],p[2]+0.05,M.item));

const mount=new THREE.Group();mount.position.set(-0.065,0,DECK_H);mount.rotation.z=Math.PI;W.add(mount);
function joint(parent,x,y,z,roll){const f=new THREE.Group();f.position.set(x,y,z);f.rotation.x=roll;parent.add(f);const j=new THREE.Group();f.add(j);return j}
const J=[];
J[0]=joint(mount,0,0,0,0);J[1]=joint(J[0],0,0,0.14,Math.PI/2);J[2]=joint(J[1],-0.28,0,0,0);
J[3]=joint(J[2],-0.24001,0,0,0);J[4]=joint(J[3],0,0,0.102,Math.PI/2);J[5]=joint(J[4],0,0,0.102,-Math.PI/2);
const tool=new THREE.Group();tool.position.z=0.1;J[5].add(tool);
box(tool,0.11,0.035,0.04,0,0,0.02,M.grip);
[1,-1].forEach(s=>box(tool,0.012,0.028,0.11,s*0.042,0,0.095,M.grip));
const held=box(tool,0.07,0.07,0.10,0,0,0.15,M.item);
const tip=new THREE.Object3D();tip.position.z=0.15;tool.add(tip);

const LINKS=[['base_link',mount,M.armBase],['shoulder_link',J[0],M.arm],['upperarm_link',J[1],M.arm],['forearm_link',J[2],M.arm],['wrist1_link',J[3],M.arm],['wrist2_link',J[4],M.arm],['wrist3_link',J[5],M.arm]];
fetch('fr3_meshes.json').then(r=>{if(!r.ok)throw new Error('mesh');return r.json()}).then(d=>{LINKS.forEach(l=>{const m=d[l[0]];const pos=new Float32Array(m.p.length);for(let k=0;k<pos.length;k++)pos[k]=m.p[k]/100000;
    const g=new THREE.BufferGeometry();g.setAttribute('position',new THREE.BufferAttribute(pos,3));g.setIndex(m.i);g.computeVertexNormals();l[1].add(new THREE.Mesh(g,l[2]))})})
  .catch(()=>{const e=document.getElementById('err');e.hidden=false;e.textContent='アームの形のデータを読み込めませんでした。台車と関節の位置だけを表示しています。'});

let q=POSES.place.q.slice(),qGoal=q.slice(),pose='place';
function applyQ(){for(let i=0;i<6;i++)J[i].rotation.z=q[i]*D}
function setPose(name){pose=name;const p=POSES[name];qGoal=p.q.slice();pallet.visible=p.scene==='pallet';shelf.visible=p.scene==='shelf';held.visible=p.hold;
  trayItems[2].visible=name!=='tray';
  document.getElementById('state').innerHTML=p.text;
  document.querySelectorAll('button[data-pose]').forEach(b=>b.setAttribute('aria-pressed',b.dataset.pose===name?'true':'false'))}
document.querySelectorAll('button[data-pose]').forEach(b=>b.addEventListener('click',()=>setPose(b.dataset.pose)));

let az=VIEWS.iso[0],el=VIEWS.iso[1],dist=VIEWS.iso[2];const target=new THREE.Vector3(-0.22,0.36,0);
function placeCam(){const a=az*D,e=el*D;cam.position.set(target.x+dist*Math.cos(e)*Math.sin(a),target.y+dist*Math.sin(e),target.z+dist*Math.cos(e)*Math.cos(a));cam.lookAt(target)}
document.querySelectorAll('button[data-view]').forEach(b=>b.addEventListener('click',()=>{const v=VIEWS[b.dataset.view];az=v[0];el=v[1];dist=v[2]}));
document.getElementById('z-in').addEventListener('click',()=>{dist=Math.max(1.0,dist*0.85)});
document.getElementById('z-out').addEventListener('click',()=>{dist=Math.min(6,dist/0.85)});
let drag=null;
canvas.addEventListener('pointerdown',e=>{drag=[e.clientX,e.clientY];canvas.setPointerCapture(e.pointerId)});
canvas.addEventListener('pointermove',e=>{if(!drag)return;az-=(e.clientX-drag[0])*0.4;el=Math.max(-5,Math.min(89,el+(e.clientY-drag[1])*0.3));drag=[e.clientX,e.clientY]});
['pointerup','pointercancel'].forEach(n=>canvas.addEventListener(n,()=>{drag=null}));

function fit(){const w=canvas.clientWidth,h=canvas.clientHeight;if(!w||!h)return;renderer.setSize(w,h,false);cam.aspect=w/h;cam.updateProjectionMatrix()}
if(window.ResizeObserver)new ResizeObserver(fit).observe(canvas);window.addEventListener('resize',fit);fit();
const still=window.matchMedia&&window.matchMedia('(prefers-reduced-motion:reduce)').matches;
function frame(){for(let i=0;i<6;i++){const d=qGoal[i]-q[i];q[i]=(still||Math.abs(d)<0.05)?qGoal[i]:q[i]+d*0.08}
  applyQ();placeCam();renderer.render(scene,cam);requestAnimationFrame(frame)}
setPose('place');applyQ();
window.__tips=function(){const out={};Object.keys(POSES).forEach(k=>{for(let i=0;i<6;i++)J[i].rotation.z=POSES[k].q[i]*D;W.updateMatrixWorld(true);const v=tip.getWorldPosition(new THREE.Vector3());out[k]=[+(v.x+0.065).toFixed(3),+(-v.z).toFixed(3),+(v.y-DECK_H).toFixed(3)]});applyQ();return out};
frame();
})();
</script>
</main>
</body>
</html>
