[Ubuntu 16.04] Samba 설치

OS/Linux 2017.10.25 13:53 Posted by 파란크리스마스

출처 : 우분투 자작 NAS – 4강, Samba를 이용한 윈도우 파일 공유 - SPACE XIAN

Samba 서버 설치

$ sudo apt-get install samba

리눅스 사용자 Samba 암호 설정

이미 리눅스 사용자 중에서 Samba용 암호 생성

$ sudo smbpasswd -a bluesanta
New SMB password:
Retype new SMB password:
Added user bluexmas.

Samba 환경 설정 - 공유 폴더 추가

$ sudo vi /etc/samba/smb.conf

[bluesanta]
comment = Cloud Root
path = /bluesanta/samba_root
writeable = yes
browseable = no
valid users = bluesanta

Samba 다시 시작

$ sudo service smbd restart
$ sudo service nmbd restart
저작자 표시
신고

[CentOS] JDK 1.8 설치

OS/Linux 2017.10.25 13:29 Posted by 파란크리스마스

출처 : CentOS JDK 설치 - 제타위키

설치 가능한 JDK 버전 확인

# yum list java*jdk-devel
......
Available Packages
java-1.6.0-openjdk-devel.x86_64        1:1.6.0.41-1.13.13.1.el6_8        base   
java-1.7.0-openjdk-devel.x86_64        1:1.7.0.151-2.6.11.0.el6_9        updates
java-1.8.0-openjdk-devel.x86_64        1:1.8.0.151-1.b12.el6_9  

JDK 1.8 설치

# yum install java-1.8.0-openjdk-devel.x86_64

설치한 JDK 버전 확인

# java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

JAVA_HOME 환경 변수 추가

# vi /etc/profile

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el6_9.x86_64
저작자 표시
신고

[CentOS] Apache 웹서버 설치

OS/Linux 2017.10.25 10:09 Posted by 파란크리스마스

출처 : CentOS 아파치 설치 - 제타위키

현재 설치된 Apache 웹서버 버전 확인

# httpd -v
Server version: Apache/2.2.3
Server built:   Apr  3 2014 19:51:47

설치 가능한 Apache 웹서버 버전 확인

# yum list httpd
......
base                                                     | 3.7 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
Available Packages
httpd.x86_64                   2.2.15-60.el6.centos.6                    updates

Apache 웹서버 설치

# yum install httpd
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * extras: mirror.navercorp.com
 * updates: ftp.kaist.ac.kr
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-60.el6.centos.6 will be installed
--> Processing Dependency: httpd-tools = 2.2.15-60.el6.centos.6 for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Running transaction check
---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.6 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package            Arch        Version                      Repository    Size
================================================================================
Installing:
 httpd              x86_64      2.2.15-60.el6.centos.6       updates      836 k
Installing for dependencies:
 apr-util-ldap      x86_64      1.3.9-3.el6_0.1              base          15 k
 httpd-tools        x86_64      2.2.15-60.el6.centos.6       updates       80 k
 
Transaction Summary
================================================================================
Install       3 Package(s)
 
Total download size: 932 k
Installed size: 3.2 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm          |  15 kB     00:00     
(2/3): httpd-2.2.15-60.el6.centos.6.x86_64.rpm           | 836 kB     00:00     
(3/3): httpd-tools-2.2.15-60.el6.centos.6.x86_64.rpm     |  80 kB     00:00     
--------------------------------------------------------------------------------
Total                                           2.8 MB/s | 932 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         1/3 
  Installing : httpd-tools-2.2.15-60.el6.centos.6.x86_64                    2/3 
  Installing : httpd-2.2.15-60.el6.centos.6.x86_64                          3/3 
  Verifying  : httpd-2.2.15-60.el6.centos.6.x86_64                          1/3 
  Verifying  : httpd-tools-2.2.15-60.el6.centos.6.x86_64                    2/3 
  Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         3/3 
 
Installed:
  httpd.x86_64 0:2.2.15-60.el6.centos.6                                         
 
Dependency Installed:
  apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1                                        
  httpd-tools.x86_64 0:2.2.15-60.el6.centos.6                                   
 
Complete!

mod_ssl 설치

# yum -y insltall mod_ssl

Apache 웹서버 서비스 실행

# service httpd start
저작자 표시
신고

[Android7.0] - 파일의 URI 정보 조회

Programming/안드로이드 2017.10.24 09:52 Posted by 파란크리스마스

출처 : Android 7.0 Nougat OS 이미지 사진 촬영 캡처 및 자르기(1/2) - 허접샴푸로그래밍

Android7.0 이전 에서는 Uri.fromFile 함수로 파일의 URI 정보를 얻을 수 있지만, Android7.0 이후 부터는 보안상 이슈로 아래와 같이 설정하고, FileProvider.getUriForFile 함수를 이용해서 URI 정보를 얻어야 합니다.

/xml/provider_paths.xml 생성

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="storage/emulated" path="."/>
</paths>

AndroidManifest.xml 내용 추가

	<provider
	   android:name="android.support.v4.content.FileProvider"
	   android:authorities="${applicationId}.provider"
	   android:exported="false"
	   android:grantUriPermissions="true">
	    <meta-data
	        android:name="android.support.FILE_PROVIDER_PATHS"
	        android:resource="@xml/provider_paths"/>
	</provider> 
	...
</application>

FileProvider.getUriForFile 사용

Uri photoUri = FileProvider.getUriForFile(
    getApplicationContext(), 
    getApplicationContext().getPackageName() + ".provider", 
    currentFile
);
저작자 표시
신고

[Ubuntu 16.04] OwnCloud 설치

OS/Linux 2017.10.24 01:28 Posted by 파란크리스마스

출처 : 우분투 자작 NAS 설치하기 - (7) OwnCloud - 살만한 세상 만들기 - Tistory
우분투 리눅스 서버 16.04 LTS에서 APM설치(PHP5 설치가 안될때) - 따뜻한 커피한잔

Apache2 설치

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install apache2

PHP 설치

$ sudo apt-get install php

Apache2 와 PHP 연동 모듈 설치

$ sudo apt-get install libapache2-mod-php

MySQL - PHP 연동 모듈 설치

$ sudo apt-get install php-mysql 

PHP 확장 모듈 설치

$ sudo apt-get install php-gd php-json php-curl php-intl php-mcrypt php-imagick
$ sudo apt-get install php-zip php-dom php-mbstring

MySQL에 OwnCloud DB와 사용자 생성

$ cd /usr/local/mysql
$ bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log
 
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> CREATE DATABASE owncloud;
Query OK, 1 row affected (0.00 sec)
 
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> create user 'owncloud'@'localhost' identified by '***';
Query OK, 0 rows affected (0.00 sec)
 
mysql> GRANT ALL privileges ON owncloud.* TO 'owncloud'@'localhost' identified by '***'; 
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
 
mysql> exit
Bye
$ 

OwnCloud 설치

$ wget https://download.owncloud.org/community/owncloud-10.0.3.tar.bz2
$ tar jxvf owncloud-10.0.3.tar.bz2
$ sudo mv owncloud /var/www
$ sudo chown -R www-data:www-data /var/www/owncloud

Apache2에 경로 추가

$ sudo vi /etc/apache2/apache2.conf

Alias /cloud "/var/www/owncloud"

# ownCloud
<Directory /var/www/owncloud>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

PHP환경파일(php.ini) - MySQL 정보 설정

Message: mysqli::real_connect(): (HY000/2002): No such file or directory 오류 발생시 적용

$ sudo vi /etc/php/7.0/apache2/php.ini

pdo_mysql.default_socket=/usr/local/mysql/mysql.sock

Apache2 재시작

$ sudo service apache2 restart







---------------------------------------------------------------------------------------

가상경로로 사용하는 경우 (참고용)

---------------------------------------------------------------------------------------

OwnCloud 설치

$ cd /etc/apache2/sites-available
$ sudo cp 000-default.conf owncloud.conf

owncloud.conf 수정

$ sudo vi /etc/apache2/sites-available/owncloud.conf

DocumentRoot /var/www/owncloud

a2dissite

$ sudo a2ensite owncloud.conf 
Enabling site owncloud.
To activate the new configuration, you need to run:
  service apache2 reload

a2dissite

$ sudo a2dissite owncloud.conf
Site owncloud disabled.
To activate the new configuration, you need to run:
  service apache2 reload
저작자 표시
신고

[Ubuntu 16.04] 디스크 추가 (파티션 추가, 수정, 삭제)

OS/Linux 2017.10.22 11:58 Posted by 파란크리스마스

출처 : Ubuntu 14.04에 새로운 하드디스크 추가 및 포맷후 자동 마운트 설정

디스크 확인

$ sudo fdisk -l
Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9AE56DAA-6072-4BF2-B94C-7CDEA00F4BD6
 
Device         Start       End   Sectors   Size Type
/dev/sda1       2048   1050623   1048576   512M EFI System
/dev/sda2    1050624 233578495 232527872 110.9G Linux filesystem
/dev/sda3  233578496 250068991  16490496   7.9G Linux swap
 
 
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9d6a04a1
 
Device     Boot   Start        End    Sectors  Size Id Type
/dev/sdb1          2048    4982527    4980480  2.4G fd Linux raid autodetect
/dev/sdb2       4982528    9176831    4194304    2G fd Linux raid autodetect
/dev/sdb3       9437184 3906824351 3897387168  1.8T fd Linux raid autodetect

파티션 삭제

bluesanta@bluesanta-ubuntu:~$ sudo fdisk /dev/sdb
 
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
 
Command (m for help): p
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9d6a04a1
 
Device     Boot   Start        End    Sectors  Size Id Type
/dev/sdb1          2048    4982527    4980480  2.4G fd Linux raid autodetect
/dev/sdb2       4982528    9176831    4194304    2G fd Linux raid autodetect
/dev/sdb3       9437184 3906824351 3897387168  1.8T fd Linux raid autodetect
 
Command (m for help): d
Partition number (1-3, default 3): 3
 
Partition 3 has been deleted.
 
Command (m for help): p
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9d6a04a1
 
Device     Boot   Start     End Sectors  Size Id Type
/dev/sdb1          2048 4982527 4980480  2.4G fd Linux raid autodetect
/dev/sdb2       4982528 9176831 4194304    2G fd Linux raid autodetect
 
Command (m for help): d
Partition number (1,2, default 2): 2
 
Partition 2 has been deleted.
 
Command (m for help): p
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9d6a04a1
 
Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 4982527 4980480  2.4G fd Linux raid autodetect
 
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
 
Command (m for help): p
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9d6a04a1
 
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
 
bluesanta@bluesanta-ubuntu:~$

파티션 생성

bluesanta@bluesanta-ubuntu:~$ sudo fdisk /dev/sdb
 
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
 
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-3907029167, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-3907029167, default 3907029167): 

Created a new partition 1 of type 'Linux' and of size 1.8 TiB.

Command (m for help): p
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9d6a04a1

Device     Boot Start        End    Sectors  Size Id Type
/dev/sdb1        2048 3907029167 3907027120  1.8T 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

bluesanta@bluesanta-ubuntu:~$

파티션 포맷

$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
/dev/sdb1 contains a ext4 file system labelled '1.42.6-15047'
        last mounted on /tmpRoot on Sun Oct 22 04:57:39 2017
Proceed anyway? (y,n) y
Creating filesystem with 488378390 4k blocks and 122101760 inodes
Filesystem UUID: 453664ac-c02b-455c-9ba1-3d35bd897f7a
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848
 
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:            
done

마운트

UUID 확인

$ sudo blkid
/dev/sdb1: UUID="453664ac-c02b-455c-9ba1-3d35bd897f7a" TYPE="ext4" PARTUUID="9d6a04a1-01"
/dev/sda1: UUID="D45D-43C1" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="25020812-a594-49f0-8f24-99da4af239dd"
/dev/sda2: UUID="53ea17c4-0915-40b0-8bbb-8bb001c978ba" TYPE="ext4" PARTUUID="dea676bf-ea7f-449c-b483-e9d624cc549a"
/dev/sda3: UUID="872f5a18-1582-4dcd-a5ba-3d3f80b06571" TYPE="swap" PARTUUID="af10b5bd-2801-4178-b182-d68a297951d7"

fstab 파일에 파티션 추가

$ sudo vi /etc/fstab

# 파티션 추가
UUID=453664ac-c02b-455c-9ba1-3d35bd897f7a /bluesanta      ext4    defaults 0       0

마운트 및 확인

$ sudo mkdir /bluesanta
$ sudo mount -a
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
....
/dev/sdb1       1.8T   68M  1.7T   1% /bluesanta
저작자 표시
신고

[Ubuntu 16.04] 원격 데스크탑(xrdp) 설치

OS/Linux 2017.10.22 11:25 Posted by 파란크리스마스

출처 : ubuntu 16.04 원격 데스크탑 :: Hyub's Tistory
XRDP – How to install XRDP on Ubuntu 16.04 – Easy Way – Griffon's IT Library

XRDP Package 설치

$ sudo apt-get install xrdp

Mate-desktop 설치 설치

$ sudo apt-get install mate-core mate-desktop-environment mate-notification-daemon

데스크탑 환경을 xRDP 사용하도록 설정

$ sudo sed -i.bak '/fi/a #xrdp multiple users configuration \n mate-session \n' /etc/xrdp/startwm.sh
저작자 표시
신고
TAG xrdp

USB 초기화, 포맷

OS/Windows 2017.10.21 10:02 Posted by 파란크리스마스

출처 : WHEREIS :: cmd 창에서 usb 포맷하기 - LKlingling - Tistory

디스크 목록 조회

DISKPART> list disk

  디스크 ###  상태           크기     사용 가능     Dyn  Gpt
  ----------  -------------  -------  ------------  ---  ---
  디스크 0    온라인       3726 GB           0 B        *
  디스크 1    온라인       1863 GB           0 B
  디스크 2    온라인       7633 MB        127 MB        *

디스크 선택

DISKPART> select disk 3

3 디스크가 선택한 디스크입니다.

디스크 초기화

DISKPART> clean

DiskPart에서 디스크를 정리했습니다.

파티션 생성하고, 포맷

DISKPART> create partition primary
DISKPART> list partition
DISKPART> select partition 1
DISKPART> active
DISKPART> format fs=ntfs quick
저작자 표시
신고

svn 백업

분류없음 2017.10.21 03:11 Posted by 파란크리스마스

출처 : ppusari: SVN사용 백업 및 복구

Dump (SVN 전체 백업)

$ svnadmin dump /bluesanta/Repositories/ > /disk_iodd/linux_backup/Repositories
* 덤프된 리비전 1.
* 덤프된 리비전 2.
* 덤프된 리비전 3.
* 덤프된 리비전 4.
저작자 표시
신고

MeArm - 원격 제어 1

OS/Arduino 2017.10.03 02:53 Posted by 파란크리스마스

MeArm - 원격 제어 1

출처 : 실습4. 아두이노 (Arduino)로 가변저항의 저항 값 읽기 : 네이버 블로그 | 메이키스트

MeArm을 원격 제어 하기 위해서 만들기 시작했는데, 아직 하나의 아두이노에서 제어만 가능한 상태입니다.

Raspberry PI를 이용해서 제어 명령을 녹화 했다가 다시 재생하고, 블루투스로 원역으로 제어 하는 부분을 구현 예정인데, 완료되면 다시 글 올리도록 하겠습니다.

최초 아두이노 소스

#include<Servo.h> 

Servo myservo1; 
Servo myservo2;
Servo myservo3; 
int servoPin1 = 10; 
int servoPin2 = 3; 
int servoPin3 = 5; 
int pos = 0; 

int analogPin1 = A1;     // potentiometer wiper (middle terminal) connected to analog pin 3
int analogPin2 = A2;
int analogPin3 = A3; // outside leads to ground and +5V
int val1 = 0;           // variable to store the value read
int val1_offset_p = 10;
int val1_p_max = 180;
int val1_offset_s = 0;
int val1_ratio = 5.6266;
long temp1_old = 0;
int val2 = 0;           // variable to store the value read
int val2_offset_p = 90;
int val2_p_max = 170;
int val2_offset_s = 60;
int val2_ratio = 6.3636;
long temp2_old = 0;
int val3 = 0;           // variable to store the value read
int val3_offset_p = 100;
int val3_p_max = 180;
int val3_offset_s = 30;
int val3_ratio = 6;
long temp3_old = 0;

void setup()
{
  Serial.begin(9600);          //  setup serial
  myservo1.attach(servoPin1); 
  myservo2.attach(servoPin2); 
  myservo3.attach(servoPin3); 
}

void loop()
{
  val1 = analogRead(analogPin1);    // read the input pin
  val2 = analogRead(analogPin2);    // read the input pin
  val3 = analogRead(analogPin3);    // read the input pin
  Serial.print(val1);             // debug value
  Serial.print(", ");             // debug value
  Serial.print(val2);             // debug value
  Serial.print(", ");             // debug value
  Serial.print(val3);             // debug value
  

  // 오른쪽 0 / 왼쪽 180
  // 오른쪽 1023 / 왼쪽 10
  // 1023-10 / 180 = 5.6266
  long temp1 = val1_p_max + val1_offset_s - ((val1 - val1_offset_p) / val1_ratio);
  if (temp1 < val1_offset_s) {
    temp1 = val1_offset_s;
  }
  if (temp1 > val1_p_max) {
    temp1 = val1_p_max;
  }
  Serial.print(", ");             // debug value
  Serial.print(temp1_old);             // debug value

  // 뒤 170 / 앞 : 60
  // 뒤 90 / 왼쪽 790
  // 790-90 / 170-60 = 6.3636  
  long temp2 = val2_p_max - ((val2 - val2_offset_p) / val2_ratio);
  if (temp2 < val2_offset_s) {
    temp2 = val2_offset_s;
  }
  if (temp2 > val2_p_max) {
    temp2 = val2_p_max;
  }

  
  Serial.print(", ");             // debug value
  Serial.print(temp2_old);             // debug value

  
  
  // 뒤 30 / 앞 : 180
  // 뒤 1000 / 앞 100
  // 1000-100 / 180-30 = 6 
  long temp3 = val3_p_max - ((val3 - val3_offset_p) / val3_ratio);
  if (temp3 < val3_offset_s) {
    temp3 = val3_offset_s;
  }
  if (temp3 > val3_p_max) {
    temp3 = val3_p_max;
  }

  Serial.print(", ");             // debug value
  Serial.print(temp3_old);             // debug value

  if (temp1_old - 25 < temp1  &&  temp1_old + 25 ) {
    myservo1.write(temp1); 
    temp1_old = temp1;  
  }

  if (temp2_old - 25 < temp2  &&  temp2_old + 25 ) {
    myservo2.write(temp2); 
    temp2_old = temp2;  
  }

  if (temp3_old - 25 < temp3  &&  temp3_old + 25 ) {
    myservo3.write(temp3); 
    temp3_old = temp3;  
  }
  
  Serial.print("\n");             // debug value
  delay(25);
}

개선된 소스 - 첫 번째

#include<Servo.h> 

Servo myservo[3];  
int servoPin[] = { 10, 3, 5 }; 

#define ARRAY_LENGTH 3
#define val1_offset_s 0
#define val1_p_max 1
#define val1_offset_p 2
#define val1_ratio 3

int analogPin[] = { A1, A2, A3 }; // outside leads to ground and +5V
double val1_offset[3][4] = {
  { 10, 180, 0, 5.6266 }, 
  { 90, 170, 60, 6.3636},
  { 100, 180, 30, 6} 
};
int val[3];           // variable to store the value read
double temp[] = { 0, 0, 0 };
double temp_old[] = { 0, 0, 0 };
int chcek_int = 3;

void setup() {
  Serial.begin(9600);          //  setup serial
  for (int i=0; i<ARRAY_LENGTH; i++) {
    myservo[i].attach(servoPin[i]);
  }
  //myservo[0].attach(servoPin[0]);
}

void loop() {
  for (int i=0; i<ARRAY_LENGTH; i++) {
    val[i] = analogRead(analogPin[i]);    // read the input pin
    Serial.print(i);
    Serial.print("=");
    Serial.print(val[i]);             // debug value
    Serial.print(",");             // debug value
  }
  Serial.print("|");             // debug value

  // 오른쪽 0 / 왼쪽 180
  // 오른쪽 1023 / 왼쪽 10
  // 1023-10 / 180 = 5.6266
  temp[0] = val1_offset[0][val1_p_max] + val1_offset[0][val1_offset_s] - ((val[0] - val1_offset[0][val1_offset_p]) / val1_offset[0][val1_ratio]);
  
  // 뒤 170 / 앞 : 60
  // 뒤 90 / 왼쪽 790
  // 790-90 / 170-60 = 6.3636 
  temp[1] = val1_offset[1][val1_p_max] - ((val[1] - val1_offset[1][val1_offset_p]) / val1_offset[1][val1_ratio]);
   
  // 뒤 30 / 앞 : 180
  // 뒤 1000 / 앞 100
  // 1000-100 / 180-30 = 6
  temp[2] = val1_offset[2][val1_p_max] - ((val[2] - val1_offset[2][val1_offset_p]) / val1_offset[2][val1_ratio]);

  for (int i=0; i<ARRAY_LENGTH; i++) {
    if (temp[i] < val1_offset[i][val1_offset_s]) {
      temp[i] = val1_offset[i][val1_offset_s];
    }
    if (temp[i] > val1_offset[i][val1_p_max]) {
      temp[i] = val1_offset[i][val1_p_max];
    }
    
    Serial.print(temp_old[i]);             // debug value
    Serial.print("/ ");             // debug value
  }
  
  for (int i=0; i<ARRAY_LENGTH; i++) {
    if (temp_old[i] - chcek_int > temp[i] || temp[i] > temp_old[i] + chcek_int ) {
      myservo[i].write(temp[i]); 
      temp_old[i] = temp[i];  
      Serial.print(", ");             // debug value
      Serial.print("servo");
      Serial.print(i);
      Serial.print(" set");             // debug value
    }
  }
  
  Serial.print("\n");             // debug value
  delay(25);
}

개선된 소스 - 두 번째

#include<Servo.h> 

Servo myservo[3];  
int servoPin[] = { 10, 3, 5 }; 

#define ARRAY_LENGTH 3
#define resi_s 0
#define resi_e 1
#define servo_s 2
#define servo_e 3
#define arm_ratio 4

int analogPin[] = { A1, A2, A3 }; // outside leads to ground and +5V
double cvalue[3][5] = {
  {  50, 1023,   0, 180, 5.6266 }, 
  {  90,  790,  60, 170, 6.3636 },
  { 100, 1000,  30, 180, 6 } 
};
int val[3];           // variable to store the value read
double temp[] = { 0, 0, 0 };
double temp_old[] = { 0, 0, 0 };
int chcek_int = 3;

void setup() {
  Serial.begin(9600);          //  setup serial
  for (int i=0; i<ARRAY_LENGTH; i++) {
    myservo[i].attach(servoPin[i]);

    // 790-90 / 170-60 = 6.3636 
    cvalue[i][arm_ratio] = (cvalue[i][resi_e] - cvalue[i][resi_s])
      / (cvalue[i][servo_e] - cvalue[i][servo_s]); 
  }
}

void loop() {
  for (int i=0; i<ARRAY_LENGTH; i++) {
    val[i] = analogRead(analogPin[i]);    // read the input pin
    Serial.print(i);
    Serial.print("=");
    Serial.print(val[i]);             // debug value
    Serial.print(",");             // debug value
  }
  Serial.print("|");             // debug value

  // 오른쪽 0 / 왼쪽 180
  // 오른쪽 1023 / 왼쪽 10
  // 1023-10 / 180 = 5.6266
  temp[0] = cvalue[0][servo_e] + cvalue[0][servo_s] - ((val[0] - cvalue[0][resi_s]) / cvalue[0][arm_ratio]);
  
  // 뒤 170 / 앞 : 60
  // 뒤 90 / 왼쪽 790
  // 790-90 / 170-60 = 6.3636 
  temp[1] = cvalue[1][servo_e] - ((val[1] - cvalue[1][resi_s]) / cvalue[1][arm_ratio]);
   
  // 뒤 30 / 앞 : 180
  // 뒤 1000 / 앞 100
  // 1000-100 / 180-30 = 6
  temp[2] = cvalue[2][servo_e] - ((val[2] - cvalue[2][servo_s]) / cvalue[2][arm_ratio]);

  for (int i=0; i<ARRAY_LENGTH; i++) {
    if (temp[i] < cvalue[i][servo_s]) {
      temp[i] = cvalue[i][servo_s];
    }
    if (temp[i] > cvalue[i][servo_e]) {
      temp[i] = cvalue[i][servo_e];
    }
    
    Serial.print(temp_old[i]);             // debug value
    Serial.print("/ ");             // debug value
  }
  
  for (int i=0; i<ARRAY_LENGTH; i++) {
    if (temp_old[i] - chcek_int > temp[i] || temp[i] > temp_old[i] + chcek_int ) {
      myservo[i].write(temp[i]); 
      temp_old[i] = temp[i];  
    }
  }
  
  Serial.print("\n");             // debug value
  delay(25);
}

실행

저작자 표시
신고


 

티스토리 툴바