Rigidbody Collision Stopping Issue

9월 16, 2021 Unity No comments , ,

문제 증상

Ball을 Rigidbody를 Dynamic으로 설정시 Reflect를 아래와 같은 형태로 추가

private void OnCollisionEnter2D(Collision2D collision)
{
    this.Direction = Vector2.Reflect(this.Direction, collision.contacts[0].normal);
}

private void FixedUpdate()
{
    this.RigiBody.velocity = this.Direction * this.Speed * Time.fixedDeltaTime;
}

정상적으로 Block에 부딪 혔을때 Reflect의 의해 Ball에 방향이 변경 됨.
하지만, 간혹 Ball이 Stopping 되는 증상이 발생
Debugging 결과 아래와 같이 OnCollisionStay2D()에서 반복적으로 Call되는것을 확인.
Resolution)
동일한 Block인 경우 강제로 Direction을 설정하여, 멈추는 것을 벗어나도록 수정

private void OnCollisionStay2D(Collision2D collision)
{
    Block collisionBlock = collision.gameObject.GetComponent<Block>();
    if (collisionBlock != null &amp;&amp; this.LastCollisionBlock2DInStay == collisionBlock)
    {
        Debug.Log("MyBall::OnCollisionStay2D::It's the same as last collison block.");
        this.Direction = new Vector2(1, 1);
    }
    this.LastCollisionBlock2DInStay = collisionBlock;
}

RigiBody Collision Issue

8월 29, 2021 Unity No comments

Ball 을 Block에 붇딪혀 Collision시 간혹 통과하는 문제가 발생

private void OnCollisionEnter2D(Collision2D collision)
{
   ...
    this.Direction = Vector3.Reflect(this.Direction, collision.contacts[0].normal);
}

private void FixedUpdate()
{
    //MyBall Velocity
    this.RigiBody.velocity = this.Direction * this.Speed;
}

위와 같이 한경우 간혹 Ball이 block을 통과하는 문제 발생.

아래와 같이 Dynamic으로 변경 후 문제 해결 (참고로, Kinematic은 물리 engine을 직접 구현하는 방식)

추가로 반복적으로 일시적으로 흔들리는 듯한 증상이 발생
Debugging 결과 동일한 Block의 Collision이 발생 됨. 아래 Code와 같이 동일 Instance인 경우 무시하도록 수정

private void OnCollisionEnter2D(Collision2D collision)
{
     if (this.LastCollisionInstanceId == collision.gameObject.GetInstanceID())
                    return;

     this.LastCollisionInstanceId = collision.gameObject.GetInstanceID();
}

Debug.Log

8월 14, 2021 Unity No comments , , ,

Unity에서 Log의 Color 설정

Debug.Log ("<color=green>Menu State</color> OnActive");
Debug.Log ("<color=red>Menu State</color> OnDeactivate");
Debug.Log ("<color=yellow>Menu State</color> OnUpdate");

Unity Tips

8월 14, 2021 Unity No comments , ,

Does not Touch  / Mouse Down


문제점

Unity MonoBehaior에 아래와 같이 OnMouseDown() or IPointerDownHandler를 사용 하였지만,동작 하지 않음

public class Tile : MonoBehaviour, IPointerDownHandler 
{
    void OnMouseDown() 
    { 
        Debug.Log("OnMouseUp"); 
    } 
    public void OnPointerDown(PointerEventData eventData) 
    { 
        Debug.Log(this.gameObject.name + " Was Clicked."); 
    }
}

해결책

Main Carmera의 Position.Z를 0에서 -10로 변경 후 정상 동작

OLED Display Control

12월 8, 2019 PSOC No comments , ,

OLED Display Control

 

우선 OLED Display는 Aliexpress에서 저렴한 item으로 구매하였습니다. (약 1300원)

해상도는 128 x 64이며, PSOC에서는 I2C로 control 합니다.
실제 Display를 control하는 chip은 Solomon Systecho의 SSD1306입니다.

해당 control chip과 관련된 library가 존재 합니다.
ssd1306.zip

PSOC에서 TopDesign은 아래와 같이 단순히 I2C와 VCC/GND만 연결해 줍니다.
VCC는 3.3V~5V를 지원하기에 Digital Output으로 High 값으로 해도 충분 합니다. 20mA Output을 가지니 충분한듯 합니다.
GND는 Low로 설정 하였습니다.

실제 main.c code입니다.

#include "ssd1306.h"
...
    I2COLED_Start();
    CyGlobalIntEnable;
    CyDelay(1000);
    
    display_init(DISPLAY_ADDRESS);    
    for(;;)
    { 
        // clearing display
        display_clear();    
        display_update();    

        // drawing a pixel
        gfx_drawPixel(10, 10, WHITE);    
        display_update();
         ... 
     }

단순하게 I2C component만 Start하고 나머지는 ssd1306의 library를 그대로 사용합니다.

실제 출력한 예제 화면 입니다.

RC Servo Motor Control

10월 26, 2019 PSOC No comments

PSOC 5LP를 이용한 RC car의 Servo Motor Control 예제

우선 RC car용 Servo모터 입니다. Traxxas의 2080으로 자세한 Spec이 없습니다.;;;

그래서 googling 해보니 나름 Standard가 있더군요.

우선 cable은 아래와 같이 Red Positive에 5V 공급하고, Negative에 Ground 연결하고, PSOC PWM output을 Signal Line에 연결해 주었습니다.

 

PWM Component를 이용하여 Servo Motor에 PWM signal을 전달 할 예정이며, Control은 아래처럼 하면 됩니다.

PWM Period는 20 msec를 유지하고, Pulse Duty Cycle을 이용하여, Servo Motor의 각도를 조정 하게 됩니다.

PWM Clock은 480KHz를 연결 해 줍니다.

PWM Configuration 입니다. PWM Mode를 Center Aligh으로 설정합니다.
Period를 20 msec를 설정 하기 위해 아래와 같이 계산 합니다.
20 msec / ( 1 / 480 KHz * 2)
(2: Center Align 설정)

위 식에 의해 20msec은 Period는 4800으로 설정 됩니다.
다음 Duty Cycle은 CMP Type이 Greater로 설정 되어 있기에, 설정 원하는(ex, 1.5 msec) Duty Cycle을 Count값로 계산한 후 Period count에 뺀 값을 입력 합니다.
1.5 msec / ( 1 / 480 KHz * 2)

Duty Cycle은 240 count값이고 4800 – 240 = 4560을 입력 하면 됩니다.

위의 Control 하는 move_surve() function 입니다.

void move_survo(float duration, float pulsewidth)
{
    double clock = 480.0e3;

    double periodCount = duration / (1.0 / clock * 2.0);
    double pulsewidthCount = pulsewidth / (1.0 / clock * 2.0);

    uint16 period = periodCount;
    uint16 compare = periodCount - pulsewidthCount;

    char buffer[USBUART_BUFFER_SIZE];
    PWM_SERVO_WritePeriod(period);
    PWM_SERVO_WriteCompare(compare);
    sprintf(buffer, "duration:%f, pulsewidth: %f, period: %d, compare: %d\r\n", duration, pulsewidth, period, compare);
    DebugLog(buffer);
}

예제로 1.4 msec ~ 2.0 msec을 반복 하여 움직이도록 control 해 보았습니다.

double startPeriod = 1.4e-3;
double endPeriod = 2.0e-3;
for(;;)
{
    for(double i=startPeriod; i&lt;endPeriod; i+=0.1e-3) 
    { 
        move_survo(20.0e-3, i); 
        CyDelay(50); 
    }
 
    for(double i=endPeriod; i&gt;=startPeriod; i-=0.1e-3)
    {
        move_survo(20.0e-3, i);
        CyDelay(50);
    }
}

실제 작동 화면 입니다.

UART Logging

10월 19, 2019 PSOC No comments ,

PSOC 개발시 Logging을 사용하기 위해 USB UART를 사용하는 예제 입니다.

TopDesign은 아래와 같이 USBUART Component 를 추가 합니다.
LED는 Test 목적으로 Red, Green, Yellow LED를 ON/OFF 시키도록 할 예정입니다.

초기화 하고, USBUART를 Configuration 합니다.

    /* Start USBFS operation with 5-V operation. */
    USBUART_Start(USBFS_DEVICE, USBUART_5V_OPERATION);
    
    for(;;)
    {
        /* Host can send double SET_INTERFACE request. */
        if (0u != USBUART_IsConfigurationChanged())
        {
            /* Initialize IN endpoints when device is configured. */
            if (0u != USBUART_GetConfiguration())
            {
                /* Enumeration is done, enable OUT endpoint to receive data 
                 * from host. */
                USBUART_CDC_Init();
                break;
            }
        }
    
    }

아래와 같이 USBUART_PutString()을 이용하여, UART로 String을 전송 하여, Log Data를 전송 합니다.
Test 목적으로 LED Control에 3 bit로 write 합니다.

    int count =0;
    for(;;)
    {
        Control_Reg_LED_Write(count % 8);
           
        /* Service USB CDC when device is configured. */
        if (0u != USBUART_GetConfiguration())
        {
            sprintf(buffer, "LED Count 0x%x\r\n", count++);
            USBUART_PutString(buffer);
        }
        CyDelay(100);
    }

Tera Term을 이용하여 COM Port를 통해 UART Data를 Receive한 예

실제 Test를 위한 LED 예제 입니다.

Breathing LED

10월 12, 2019 PSOC No comments ,

PWM을 이용하여 Breathing LED 구현

Result)

Design


PWM 2개를 이용하여 2개의 Period 차이를 XOR Gate를 사용하여 Breathing LED 구현

PWM 출력을 XOR Gate에 연결하여 LED 출력으로 연결

PWM_1 Period: 255, CMP Value: 128
PWM_2 Period: 245, CMP Value: 120

 

Voltage Drop Circuit

10월 12, 2019 PSOC No comments , ,

SZH-PWSDF-036

Power Supply를 구매해서 사용 하고 싶지만, 가격이 비싸서;;;
어차피 주로 Digital Logic으로 구성해서 작업 할 예정이기에, 저렴한 Voltage Drop Kit을 구매하였습니다.

Specification

Input Voltage 4.0V ~ 38V
Output Voltage 1.25V ~ 35V (연속 가변)
Output Current 5A (max) (4.5A 권장)
Size 60mm * 37mm * 18mm
Weight 28g

 
Input Voltage를 USB to 악어 클립 을 사용시, 2.5V, 3.3V로 Drop시킬수 있고
12V Adaptor를 사용하여 12V 이하로 사용 가능 할듯 합니다.

USB를 이용하여 전원 구성하고, Bread Board에 연결하여, PSOC 5LP Dev Kit에 Power를 공급해 보았습니다.

Element Value 수정 추가

5월 8, 2018 eDICOMViewer No comments

1.vex-dialog input에서 read only인 text 구분을 위해 text color를 변경
div tag의 class vex-dialog-input하위의 input tag중 read-only attribute를 가지는 tag만 변경 시도

div.vex-dialog-input>input:read-only{
    color: #808080;
}

2.추가로 실제 row 값을 변경 후 table에 redraw를 위해 아래와 같이 row의 invalidate 사용

///modify
rowData['value'] = data.value.trim();
nodeDCMTK.SetElementValue(ID2Elements[id], rowData['value']);
row.invalidate().draw();