Skip to content

02 Superman API Documentation

YuKyungKim edited this page Nov 19, 2015 · 1 revision

Superman

Overview

Superman은 linux 기반 Drone OS이다.

이 문서는 Superman API에 대해 기술한 문서이다.

tables of contents

  • Control
    • Motor
      • Class Motor
      • MotorInterface.c
    • PID
      • Class PID
    • Sensor
      • Class IMUInterface
  • Network
    • network.c
    • protocol.c
    • Struct PACKET
    • TCP_Server.c
    • UDP_Server.c
    • Drone_Epoll.c
    • ctl.c

Superman/Control/Motor/MotorInterface.h

Class Motor

모터 장치를 위한 기본 클래스. 공통된 인터페이스를 제공하기 위해 사용.

새로운 장치 추가시 이 파일을 include 하여 그대로 사용하도록 함.

각 함수들은 새로 추가하는 장치 환경에 따라 설정.

Field Summary


private int speed

private int pin


Method Summary


public int init()

set up wiringPi enviroment

Returns

 - -1 : Error
 - 1 : OK

public int setPin (int pinNum)

Selecting Pin number using softpwm output

Parameters

- pinNum
- pin using pwm gpio

Returns

- -1 : Error
- 1 : OK

public void calibration()

Calbration for init setting ESC motor.

public void setSpeed (int value)

Setting speed

Parameters

- Speed value
- range (0 ~ 2500)

public void stop()

Stop drone



Superman/Control/Motor

MotorInterface.c

MotorInterface 의 구현부로 동일한 인터페이스를 제공하기 위함.

Motor.h 에 의해 사용되는 장치가 결정되며 해당 파일을 인터페이스로 사용.

새로운 장치를 추가하기 위해 이 파일을 복사하여 사용.

Method Summary


public int Motor::init()

set up wiringPi enviroment

공통부분. wiringPi 설정 및 속도 초기화

Returns

 - -1 : Error
 - 1 : OK

public int Motor::setPin (int pinNum)

Selecting Pin number using softpwm output

공통부분. 모터 사용 핀넘버 설정.

Parameters

- pinNum
- pin using pwm gpio

Returns

- -1 : Error
- 1 : OK

public void Motor::calibration()

Calbration for init setting ESC motor.

각 ESC 의 데이터시트 참조하여 Clibrate 코드 작성

public void Motor::setSpeed (int value)

Setting speed

공통부분. Range 범위 내의 속도 지정

Parameters

- Speed value
- range (0 ~ 2500)

public void Motor::stop()

Stop drone

공통부분. 속도 0 지정



Superman/Control/PID/PID.h

Class PID

Field Summary


private float Kd

private float Ki

private float Kp

private float P_pid

private float I_pid

private float D_pid

private float P_err

private float I_err

private float D_err

private float dt

private float P_ pid_prev

private struct timeval start_point

private struct timeval end_point


Method Summary


public int init()

public void setTuning (float kd, float ki, float kp)

set pid constant for calculating

Parameters

- kp : p constant
- ki : i constant
- kd : d constant

public int calcPID (float aimVal, float inVal)

Calculation pid ( input to aim value )

Parameters

- aimVal : aim that we want tilt
- inVal  : current tilt

Returns

- int : integer value that motor power

public void initKpid (float kd, float ki, float kp)

changing pid constant during executing program



Superman/Control/Sensor/SensorInterface.h

Class IMUInterface

IMU의 기본적인 함수들을 정의 한 부분으로, 새로운 센서를 추가할때 IMUInterface 클래스를 상속 받아 코딩할 것.

Method Summary


public int init()

센서 초기화, 연결확인.

Returns

- 1  = 연결 성공
- 0 = 연결 실패

public void getIMUData (float *roll, float *pitch, float *yaw)

센서의 Roll, Pitch, Yaw를 계산.

public void calibration()

센서 offest 보정



Superman/Network/

network.c

network의 선언을 간단하게 만들기 위한 파일.

Method Summary


int network_init (int* tcp, int* udp)

설명

Parameters

- param1 :
- parma2 :

Returns

- result1 :
- result2 :

int json_read (int socket, double x, double * y, double * z, int * t)

설명

Parameters

- param1 :
- parma2 :

Returns

- result1 :
- result2 :

void json_write (int socket, double x, double y, double z, int t)

설명

Parameters

- param1 :
- parma2 :

int network_exit (int tcp, int udp)

설명

Parameters

- param1 :
- parma2 :

int tcp_read (int socket)

설명

Parameters

- param1 :
- parma2 :


Superman/Network/

Protocol.c

network의 선언을 간단하게 만들기 위한 파일.

Method Summary


Packet string_to_struct (char* buf)

char array에 있는 데이터를 packet구조체에 넣는 함수.

char를 리턴 뒤에도 사용해야하기 때문에, argu에 집어넣는다.

Parameters

- packet : buf에 집어넣을 데이터가 있는 struct
- buf : struct의 데이터가 들어가는 char

void struct_to_string (Packet packet, char *buf)

packet구조체의 데이터를 char array로 넘기는 함수 char를 리턴뒤에도 사용해야하기 때문에, argu에 집어넣는다.

Parameters

- packet : buf에 집어넣을 데이터가 있는 struct
- buf : struct의 데이터가 들어가는 char

float ntohf* (float f)

float형 변수는, htonl함수가 안먹는 경우가 있으므로, 바꿔주는 함수이다.

Parameters

- f : byteorder를 바꾸고 싶은 float

Returns

- host byte order로 바뀐 float 변수

float htonf (float f)

설명

Parameters

- param1 :
- parma2 :

int endian_check()

network byte order인지 host byte order인지 확인하는 함수

Returns

- 0 : 
- 1 : 

void print_buf (char* buf)

char array의 buffer를 출력하기 위한 버퍼

Parameters

- buf : 값을 출력하기 위한 변수

void print_packet (Packet packet)

설명

Parameters

- packet : 값을 출력하기 위한 변수

void packet_swticher (Packet packet)

설명

Parameters

- param1 :

int init_message (int socket)

init 절차를 수행하는 프로세스 flag==1일때,

Parameters

- param1 :
- parma2 :

Returns

- result1 :
- result2 :

void recv_control (int socket)

control message를 받는 패킷

Parameters

- param1 :
- parma2 :

void send_status (int socket)

status message를 보내는 패킷

Parameters

- param1 :
- parma2 :


Superman/Network/Protocol.h

Struct _ PACKET_

Packet의 구조.

Field Summary


uint8_t H

Header 부분이다. 0xEE로 고정.

uint8_t F

flag부분이다. 이 flag를 통한 switch문으로 함수를 실행한다.

uint16_t S

sequence 부분이다. 추후에 결정할 예정이다.

float X

control시에는 x축에 대한 데이터를 보낸다.

float Y

control시에는 y축에 대한 데이터를 보낸다.

float Z

control시에는 z축에 대한 데이터를 보낸다.

uint32_t T

control시에는 thoughput에 대한 데이터를 보낸다.

// 다른 경우에는 X,Y,Z,T는 데이터를 실어보내는 역할을 한다.// -> 어떤 다른 경우? 어떤 데이터? 자세한 설명 필요..



Superman/Network/

TCP_Server.c

TCP_Socket의 생성과 해당 디스크립터 반환.

Method Summary


int CreateTCPServerSocket (unsigned short port)

ServerSocket을 생성하기 위한 함수 socket->bind->listen까지

Parameters

- port : 해당 포트번호로 Tcp server socket을 생성하기 위한 변수

Returns

- -1 : socket 생성 실패
- 0 : bind error

int AcceptTCPConnection (int servSock)

CreateTCPServerSocket을 통해 생성된 Serversocket으로 accept하기 위한 함수

Parameters

- servSock : ServerSocket의 디스크립터

Returns

- 실제로 연결된 client와 1:1로 연결되어 있는 TCP소켓 디스크립터

int TCP_connect_init (unsigned short port)

CreateTCPServerSocket와 AccpetTCPConnection을 수행해, 실제 1:1 로 client 연결된 소켓의 디스크립터만 가져오기 위한 함수.
DOS-project에서는 더 이상의 TCP server socket이 필요 없기 때문에, close를 통해 닫고, 1:1로 연결된 디스크립터만 반환한다.

Parameters

- port: Server Socket을 열기 위한 port number

Returns

- 실제로 연결된 client와 1:1로 연결되어 있는 TCP소켓 디스크립터


Superman/Network/

UDP_Server.c

UDP_Socket의 생성과 해당 디스크립터 반환.

Method Summary


int CreateUDPServerSocket (unsigned short port)

UDP socket을 생성하기 위한 함수.
socket에서 bind까지.

Parameters

- port: 해당 포트번호로 UDP server socket을 생성하기 위한 변수

Returns

- -1 : socket 생성 실패
- 0 : bind error

int UDP_connect_init (unsigned short port)

기존의 1:1 방식의 UDP 연결 방법 대신 connected UDP 방식을 이용하면, UDP socket에 IP와 PORT번호를 미리 입력한 상태에서 데이터만 전송하여 성능 향상을 기대 할 수 있다.

또한 기존의 UDP 방식에서는 recvfrom이나 sendto 함수를 사용했던 것에 반해, Conneted UDP 방식에서는 read, write함수를 사용할 수 있어 실제 코드의 효율성도 증가하므로, Connected UDP 방식으로 구현하였다.

Parameters

- tcp : getpeername으로 상대방의 ip를 확인하기 위한 변수
- port: 상대 udp port번호를 알기 위한 변수

Returns

- 실제로 연결된 client와 1:1로 연결되어 있는 TCP소켓 디스크립터.


Superman/Network/

Drone_Epoll.c

EPOLL 해당 디스크립터 생성과, epoll에 소켓을 추가하는 과정과, 돌리는 과정

Method Summary


int epoll_init()

epoll 디스크립터를 생성하는 함수

Returns

- epoll 디스크립터를 반환

int epoll_run (int tcp1, int udp1, int udp2, int timeout)

설명

Parameters

- param1 :
- parma2 :

Returns

- result1 :
- result2 :


Superman/Network/

ctl.c

socket의 설정과 확인에 대한 함수 구현.

Method Summary


void get_string_access_mode2 (int val, char* ret)

설명

Parameters

- param1 :
- parma2 :

int async_test (int fd, int flag)

설명

Parameters

- param1 :
- parma2 :

Returns

- result1 :
- result2 :

int change_mode (int socket)

설명

Parameters

- param1 :
- parma2 :

Returns

- result1 :
- result2 :

int sock_reuse (int socket)

설명

Parameters

- param1 :
- parma2 :

Returns

- result1 :
- result2 :

Clone this wiki locally