반응형

다이오드의 전압 전류 특성을 시뮬레이션 해 보자.

 

적당한 다이오드와 저항으로 회로를 구성한다. (전압은 0V로 설정한다)

 

DC sweep에서 전원이 -105V 부터 5V 까지 변화하도록 설정한다.

 

시뮬레이션을 실행한다.

 

다이오드의 전압 전류 특성이 시뮬레이션 된다.

 

반응형
Posted by J-sean
:
반응형

간단한 전압분배기를 시뮬레이션 해 보자.

 

회로를 구성한다.

 

시뮬레이션 결과 Output의 전압은 3V이다.

V(output) = 3K/(3K+7K) X 10V

 

반응형
Posted by J-sean
:
반응형

AC를 DC로 변환하는 adapter를 시뮬레이션 해 보자.

 

회로에 220V 60Hz 교류를 준비한다. 직렬 저항(Series Resistance)을 생략하면 오류가 발생한다.

 

최댓값은 약 311V다.

 

전압을 낮추기 위해 변압기를 추가한다.

 

최댓값이 약 6.6V로 낮아졌다.

 

 

직류로 바꾸기 위해 전파 정류회로를 추가한다.

 

교류에서 직류(ripple)로 바뀌었다.

 

맥류(ripple)를 줄이기 위해 평활회로(커패시터)를 추가한다.

 

리플이 줄어들었다.

아래 링크처럼 정전압 레귤레이터를 사용하면 좀 더 완벽한 직류를 만들 수 있다.

2023.10.10 - [Electronics] - [PSpice] 직류 전원 공급 장치 DC Power Supply

 

※ 회로 및 시뮬레이션 LTspice 파일

DCPowerSupply.asc
0.00MB

 

반응형
Posted by J-sean
:
반응형

급격한 전류의 변화로 큰 역기전력이 발생하는 인덕터를 시뮬레이션 해 보면 왜 릴레이에 다이오드를 연결해야 하는지 알 수 있다.

 

회로를 구성한다.

  • 전원: 5VDC
  • 스위치: 2ms 후에 2ms 동안 켜졌다 꺼진다. (Voltage Controlled Switch의 작동 방식 때문에 정확히는 2+(0.1/2)ms 후에 켜졌다 2+(0.1/2)ms후에 꺼지지만 중요하지 않다)
  • 시뮬레이션 시간: 10ms

 

시뮬레이션을 실행하고 화살표 부분의 전압을 측정한다.

 

2ms에서 스위치가 켜지므로 5V의 전압이 흐르다 스위치가 꺼지는 순간 약 -27V의 역기전력이 발생한다.

 

인덕터에 다이오드를 병렬로 연결한다.

 

역기전력이 약 -0.7V로 줄었다.

※ 회로 및 시뮬레이션 LTspice 파일

Inductor.asc
0.00MB

 

반응형
Posted by J-sean
:
반응형

스크립트 작성 시 SerializeField와 Range 어트리뷰트를 함께 사용할 수 있다.

 

스크립트를 작성한다. 두 가지 방법으로 작성 할 수 있다.

 

a, b 멤버 변수를 Range에 정해진 범위 내에서 조절 가능하다.

 

반응형
Posted by J-sean
:
반응형

애니메이션 커브를 사용해 보자.

 

Sphere와 Cube 2개(A지점, B지점)를 생성한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Curve : MonoBehaviour
{
    public Transform targetA;
    public Transform targetB;
 
    public AnimationCurve lerpCurve;
 
    public Vector3 lerpOffset;
    public float lerpTime = 3.0f;
    private float timer = 0.0f;
 
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > lerpTime)
        {
            timer = lerpTime;
        }
 
        float lerpRatio = timer / lerpTime;
        Vector3 positionOffset = lerpCurve.Evaluate(lerpRatio) * lerpOffset;
 
        transform.position = Vector3.Lerp(targetA.position, targetB.position, lerpRatio) + positionOffset;
    }
}
 

 

스크립트를 작성한다.

 

작성한 스크립트를 Sphere에 추가한다.

 

TargetA, TargetB를 지정하고 Lerp Curve, Lerp Offset을 수정한다.

 

Lerp Curve는 위와 같이 수정한다.

 

플레이하면 Sphere가 부드럽게 이동한다.

 

반응형
Posted by J-sean
:
반응형

유도 미사일을 만들어 보자.

 

Square(Target)와 Capsule(Missile) 스프라이트를 생성한다.

 

Missile에 Rigidbody2D(Gravity Scale = 0)와 스크립트를 추가한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
[RequireComponent(typeof(Rigidbody2D))]
public class Guide : MonoBehaviour
{
    public Transform target;
    private Rigidbody2D rb;
 
    public float speed = 5.0f;
    public float rotateSpeed = 200.0f;
 
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }
 
    private void FixedUpdate()
    {
        Vector2 direction = (Vector2)target.position - rb.position;
        direction.Normalize();
 
        float rotateAmount = Vector3.Cross(direction, transform.up).z;
        rb.angularVelocity = -rotateAmount * rotateSpeed;
 
        rb.velocity = transform.up * speed;
    }
}
 

 

스크립트를 작성한다.

 

스크립트 Target 변수에 Target 오브젝트(Square)를 선택한다.

 

 

플레이 하면 미사일이 목표를 향해 날아간다.

 

반응형
Posted by J-sean
:
반응형

특정 조건에서 카메라를 흔들어 보자.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class CameraShake : MonoBehaviour
{
    public float shakeTime = 1.0f;
    public float shakeSpeed = 2.0f;
    public float shakeAmount = 1.0f;
 
    private Transform cam;
 
    // Start is called before the first frame update
    void Start()
    {
        cam = GameObject.FindGameObjectWithTag("MainCamera").transform;
    }
 
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.S))
        {
            StartCoroutine(Shake());
        }
    }
 
    IEnumerator Shake()
    {
        Vector3 originPosition = cam.localPosition;
        float elapsedTime = 0.0f;
 
        while (elapsedTime < shakeTime)
        {
            Vector3 randomPoint = originPosition + Random.insideUnitSphere * shakeAmount;
            cam.localPosition = Vector3.Lerp(cam.localPosition, randomPoint, Time.deltaTime * shakeSpeed);
 
            yield return null;
 
            elapsedTime += Time.deltaTime;
        }
 
        cam.localPosition = originPosition;
    }
}
 

 

'S'키를 누르면 카메라가 진동한다.

 

스크립트를 Cube 오브젝트에 추가하고 'S'키를 누르면 카메라가 진동한다.

 

반응형
Posted by J-sean
: