top of page

    บันทึกการฝึกงานสหกิจศึกษา

การควบคุมหุ่นยนต์จำลอง

 1.การ Export ไฟล์โมเดลจากโปรแกรมต่างๆ

- โปรแกรม V-Rep วิธีการก็คือ ทำการคลิกเลือกโมเดลที่ต้องการมาวางไว้ คลิกที่โมเดลให้เกิดกรอบสี่เหลี่ยมขึ้นรอบโมเดล แล้วคลิกที่เมนู File -> Export -> Selected shapes -> ตั้งชื่อไฟล์ แล้วเลือกชนิดของไฟล์เป็น Mesh file -> บันทึก

- โปรแกรม SketchUp วิธีการก็คือ คลิกที่เมนู File -> 3D Model -> ตั้งชื่อไฟล์ แล้วเลือกชนิดของไฟล์เป็น FBX -> บันทึก

- หรือจะดาวโหลดไฟล์จากเว็บ 3D warehouse ( https://3dwarehouse.sketchup.com/)  แล้วทำการเปิดไฟล์ในโปรแกรม SketchUp และทำการ Export File .FBX ออกมาเช่นเดียวกับวิธีข้างบน

- และวิธีสุดท้ายคือการดาวน์โหลดจากเว็บที่ให้ดาวโหลดฟรี เช่น 

1.https://free3d.com/

2.https://www.yobi3d.com/

 2.การ Import ไฟล์โมเดลเข้ามาในโปรแกรม Unity

- คลิกขวาที่ Asset -> เลือก Import New Ssset -> เลือกไฟล์ที่ต้องการ -> คลิก Import

- หรืออีกวิธีหนึ่งก็คือ ทำการลากไฟล์ที่เราต้องการเข้าไปในโปรแกรมเลย

 3.การทำให้โมเดลหุ่นยนต์จำลองเลื่อนไหวได้

 3.1.การทำให้โมเดลหุ่นยนต์จำลองเลื่อนไหวได้โดยใช้ Component ประเภท Confixgulation Joint

     

 3.2.การทำให้โมเดลหุ่นยนต์จำลองเลื่อนไหวได้โดยใช้ Script

         ตัวอย่างสคริป Inverse Kinematics ของหุ่นยนต์ประเภท Cartesian Robot

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class IKCartesian : MonoBehaviour {
    public Transform Base;
    public Transform Side;
    public Transform Head;

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        var pp = Mathf.Clamp(Base.transform.position.x, 0.2f, 0.5f);

        var pa = Mathf.Clamp(Side.transform.position.y, 0.2f, 0.5f);

        var pt = Mathf.Clamp(Head.transform.position.z, 0.2f, 0.2f);

    }
}

 

         ตัวอย่างสคริปที่ใช่ปุ่มในการควบคุมการเคลื่อนไหวของหุ่นยนต์ประเภท Artoculate Robot

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class buttonArticulate : MonoBehaviour {
    public Transform Robotupper;
    public float robot;
    public float upperturnrate = 0.2f;
    private float RobotUpper;
    public float RobotUpperMin;
    public float RobotUpperMax;
    // Update is called once per frame
    void Update()
    {
        RobotUpper += robot * upperturnrate;
        RobotUpper = Mathf.Clamp(RobotUpper, RobotUpperMin, RobotUpperMax);
        Robotupper.localEulerAngles = new Vector3(Robotupper.localEulerAngles.x, Robotupper.localEulerAngles.y, RobotUpper);
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Button L")
        {
            robot = 1f;
        }
        if (other.tag == "Button R")
        {
            robot = -1f;
        }
    }
    void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Button L"))
        {
            robot = 0f;
        }
        if (other.CompareTag("Button R"))
        {
            robot = 0f;
        }
    }
}

bottom of page