HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
장지원 페이지/
🗑️
Trash
/
장지원, JANG JIWON
장지원, JANG JIWON
/HCI lab/시각 장애인을 위한 그래프/
#14. 프로세싱 (2) (12.22)

#14. 프로세싱 (2) (12.22)

 
Phantom tactile sensation 구현
Eq.3 이용
 
notion image
 
 
notion image
 
slope가 2 이상인 경우
 
analog signal의 파라미터가 진폭이라고 가정
 
2 row의 경우
1/slope = 베타
 
3 row의 경우
1/slope * 2
 
A1은 고정하고 A2만 조정하기 (slope가 2 이상일 때는 항상 A1>A2)
 
(베타)/(1-베타) = (A2^2)/(A1^2)
 

문제
1.
dalay 안 걸면 안 됨,,
근데 delay 걸면 출력 패턴 이상해짐,,
 
2.
출력 바로바로 반영 안됨,,
 
max 10 : 10짜리 진동 느끼게 / 그 뒤에 ㅇ사람이 얼만치를 느끼는지 측정
or
가속도계 위에서 축절
 
 
 

2.
프로토콜
: 0XFF(시작 바이트)가 들어오면 mode1 → 그 다음 신호 들어오면 value
모드 만들어서 ~가 들어오면 타입 처리 / ~가 들어오면 value
 
 
1.
while serial not
 
read until byte하고 계속 reset
import processing.serial.*; Serial port; // port 정의 : port를 굳이 여러 개 사용할 필요는 없구나 boolean flag = true; void setup() { size(800, 800); // 화면 크기 설정 port = new Serial(this, Serial.list()[0]); // 객체 생성, 1번 포트 사 } void draw() { background(255); // 배경색 설정 // 이차 함수 그리기 stroke(0); // 선 색상 설정 for (float x = -width/2; x < width/2; x += 0.1) { float y = quadraticFunction(x); // 이차 함수의 y 값 계산 point(x + width/2, height - y); // 그림자표시 } // 마우스 커서 위치에 점 출력 float mouseXValue = mouseX - width/2; // 마우스 커서의 x 위치 계산 float mouseYValue = height - quadraticFunction(mouseXValue); // 이차 함수의 y 값 계산 // 커서가 그래프 선 위에 위치할 때만 빨간 점 출력 (범위 10픽셀) float yOnGraph = height - quadraticFunction(mouseXValue); if (mouseY >= yOnGraph - 80 && mouseY <= yOnGraph + 80) { // 여기서의 숫자가 허용 범위 픽셀 fill(255, 0, 0); // 점의 색상 설정 (빨간색) ellipse(mouseX, yOnGraph, 10, 10); // 점 출력 // 마우스 커서 위치의 좌표 출력 fill(0); // 텍스트 색상 설정 (검은색) String coordinateText = "Coordinate: (" + nf(mouseXValue, 0, 2) + ", " + nf(mouseYValue, 0, 2) + ")"; // 기울기 계산 및 출력 float slope = 2 * 0.1 * mouseXValue + 2; // 이차 함수의 미분 계산 String slopeText = "Slope: " + nf(slope, 0, 2); // nf는 number format을 의미한다. (포맷 할 숫자, 소수점 뒤 자릿 수, 표시할 숫자의 길이) text(coordinateText, 10, 20); text(slopeText, 10, 40); // print를 의미한다. (print할 변수, 표시할 x축 위치, 표시할 y축 위치) if (2 < slope) { //기울기가 2보다 크거나 같을 때 actuator는 7->4->1 순서로 동작 float time_set1 = millis(); // 첫 번째 actuator의 시작 시간 float duration = 160; // 각 actuator의 동작 기간 float SOA = 50.5; // 각 actuator 간의 간격 while (millis() <= time_set1 + duration){ float beta = 1/slope; float A2 = sqrt(((beta)/(1-beta))*pow(255,2)); port.write('A'); port.write(byte(A2)); println("Actuator3/5 on"); println(int(A2)); } port.write('Z'); // off println("Actuator3/5 off"); customDelay(100); } } } float quadraticFunction(float x) { float a = 0.1; // 이차 함수의 계수 float b = 2; // 이차 함수의 계수 float c = 30; // 이차 함수의 상수 // 이차 함수 계산: y = ax^2 + bx + c return a * x * x + b * x + c; // 함수 바꾸고 싶으면 여기 수정하면 된다. } void customDelay(float duration) { float startTime = millis(); while (millis() - startTime < duration) { // if // 원하는 동작 수행 float mouseXValue = mouseX - width/2; float mouseYValue = height - quadraticFunction(mouseXValue); float slope = 2 * 0.1 * mouseXValue + 2; // 출력 fill(255, 0, 0); float yOnGraph = height - quadraticFunction(mouseXValue); if (mouseY >= yOnGraph - 80 && mouseY <= yOnGraph + 80) { // 여기서의 숫자가 허용 범위 픽셀 fill(255, 0, 0); // 점의 색상 설정 (빨간색) ellipse(mouseX, yOnGraph, 10, 10); // 점 출력 } fill(0); String coordinateText = "Coordinate: (" + nf(mouseXValue, 0, 2) + ", " + nf(mouseYValue, 0, 2) + ")"; String slopeText = "Slope: " + nf(slope, 0, 2); text(coordinateText, 10, 20); text(slopeText, 10, 40); } }
void setup() { Serial.begin(9600); pinMode(3, OUTPUT); pinMode(5, OUTPUT); } void loop() { if(Serial.available()>0){ char val = Serial.read(); // read 후에 텅~ if (val == 'A') { if(Serial.available()>0){ // 다시 뭐가 생기면 int input = Serial.read(); // 새로운 값을 읽어! analogWrite(3,input); analogWrite(5,255); } } if (val == 'Z') { analogWrite(3,0); analogWrite(5,0); } } }