Tampilkan postingan dengan label Programming. Tampilkan semua postingan
Tampilkan postingan dengan label Programming. Tampilkan semua postingan

TIPS WEB2PY - Fast Development

Mengambil sebagian data dan paste ke form baru.


    row = db((db.lease.unit == 35) & (db.lease.tenant == 27)).select(orderby=~db.lease.sewa_akhir).first()



    sewa_akhir = row.sewa_akhir

    tgl_masuk = row.tgl_masuk
    
    form.vars.tgl_masuk = tgl_masuk   #ini memasukkan ke fieldform

    return dict(sewa_akhir=sewa_akhir,tgl_masuk=tgl_masuk)



  1. Perhatikan tilde di orderby
  2. perhatikan .first()

di view tinggal memasukkan {{=sewa_akhir}}


Update Tanggal

    query = (db.unit.id == request.vars.unit)
    set = db(query).update(sewa_akhir=request.vars.sewaakhir)


Menambah hari ke sebuah tanggal

    dd = (datetime.datetime.now() + datetime.timedelta(days=10)).strftime("%Y-%m-%d")

    return dict(dd=dd)


kode get json

      http://127.0.0.1:8000/JPM/lease/getlast.json?unit=36&tenant=28

  di controller:

def getlast():
      row = db((db.lease.unit == 31) & (db.lease.tenant == 23)).select(orderby=~db.lease.sewa_akhir).first()
      return dict(sewa_akhir=row.sewa_akhir,sewa_awal=row.sewa_awal)

PARADIGMA PROYEK 3 HARI

Setelah melalui fase menjadi pekerja, hambatan yang paling besar dalam menuju kemajuan adalah DISTRAKSI. Di zaman penuh dengan teknologi digital ini banyak sekali yang membuat kita menjadi tidak fokus.
Kita menuju kemana? ini adalah pertanyaan yang susah dijawab apabila tidak fokus.
Saya sedang menikmati belajar kembali hal-hal yang bersifat engineering, namun dalam perjalanannya kadang tidak menemukan jawaban untuk sebuah permasalahan.
Ini perlunya pekerjaan yang berdasarkan bagian per bagian.
Kita membagi problem besar menjadi problem kecil-kecil yang dapat di pecahkan.
Disini saya tertarik pada ide paradigma proyek 3 hari.

Saya belajar dari video ini. Klik sini
https://www.youtube.com/watch?v=ohr6O78jGzs

Sangat inspiratif buat saya dan saya merasa saya dapat melakukannya.
Apa idenya?

Idenya adalah bagaimana kita belajar bagian-bagian yang kecil-kecil.

Hari pertama:
   Ngoprek dan mengetes-ngetes.
   Refactor  (ini pelajaran pentingnya. Mengecilkan bagian sampai cukup dapat dipecahkan)

Hari kedua.
  Buat semua berfungsi.
  Buat semua BUGS kabur!!!

Hari ketiga.
  Dokumentasi- dokumentasi
  Refactor
  Blog.
  Taruh di repository.



Mau tahu ip sendiri dalam bentuk text?

Query ke getip.dyndns.org

Install web2py di raspberry pi

Saya gunakan script ini.

copy paste.
chmod +x
lalu jalankan.


echo "This script will:
1) install all modules need to run web2py on Ubuntu/Debian
2) install web2py in /home/www-data/
3) create a self signed sll certificate
4) setup web2py with mod_wsgi
5) overwrite /etc/apache2/sites-available/default
6) restart apache.

You may want to read this script before running it.

Press a key to continue...[ctrl+C to abort]"

read CONFIRM

#!/bin/bash
# optional
# dpkg-reconfigure console-setup
# dpkg-reconfigure timezoneconf
# nano /etc/hostname
# nano /etc/network/interfaces
# nano /etc/resolv.conf
# reboot now
# ifconfig eth0

echo "installing useful packages"
echo "=========================="
apt-get update
apt-get -y install ssh
apt-get -y install zip unzip
apt-get -y install tar
apt-get -y install openssh-server
apt-get -y install build-essential
apt-get -y install python2.5
apt-get -y install ipython
apt-get -y install python-dev
apt-get -y install postgresql
apt-get -y install apache2
apt-get -y install libapache2-mod-wsgi
apt-get -y install python2.5-psycopg2
apt-get -y install postfix
apt-get -y install wget
apt-get -y install python-matplotlib
apt-get -y install python-reportlab
apt-get -y install mercurial
/etc/init.d/postgresql restart

# optional, uncomment for emacs
# apt-get -y install emacs

# optional, uncomment for backups using samba
# apt-get -y install samba
# apt-get -y install smbfs

echo "downloading, installing and starting web2py"
echo "==========================================="
cd /home
mkdir www-data
cd www-data
rm web2py_src.zip*
wget http://web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip
mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py
chown -R www-data:www-data web2py

echo "setting up apache modules"
echo "========================="
a2enmod ssl
a2enmod proxy
a2enmod proxy_http
a2enmod headers
a2enmod expires
a2enmod wsgi
mkdir /etc/apache2/ssl

echo "creating a self signed certificate"
echo "=================================="
openssl genrsa 1024 > /etc/apache2/ssl/self_signed.key
chmod 400 /etc/apache2/ssl/self_signed.key
openssl req -new -x509 -nodes -sha1 -days 365 -key /etc/apache2/ssl/self_signed.key > /etc/apache2/ssl/self_signed.cert
openssl x509 -noout -fingerprint -text < /etc/apache2/ssl/self_signed.cert > /etc/apache2/ssl/self_signed.info

echo "rewriting your apache config file to use mod_wsgi"
echo "================================================="
echo '
NameVirtualHost *:80
NameVirtualHost *:443
# If the WSGIDaemonProcess directive is specified outside of all virtual
# host containers, any WSGI application can be delegated to be run within
# that daemon process group.
# If the WSGIDaemonProcess directive is specified
# within a virtual host container, only WSGI applications associated with
# virtual hosts with the same server name as that virtual host can be
# delegated to that set of daemon processes.
WSGIDaemonProcess web2py user=www-data group=www-data processes=1 threads=1


  WSGIProcessGroup web2py
  WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
  WSGIPassAuthorization On

 
    AllowOverride None
    Order Allow,Deny
    Deny from all
   
      Allow from all
   

 

  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \
           /home/www-data/web2py/applications/$1/static/$2
 
    Options -Indexes
    Order Allow,Deny
    Allow from all
 

 
  Deny from all
 

 
  Deny from all
 

  CustomLog /var/log/apache2/access.log common
  ErrorLog /var/log/apache2/error.log



  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/self_signed.cert
  SSLCertificateKeyFile /etc/apache2/ssl/self_signed.key

  WSGIProcessGroup web2py
  WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
  WSGIPassAuthorization On

 
    AllowOverride None
    Order Allow,Deny
    Deny from all
   
      Allow from all
   
 

  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \
        /home/www-data/web2py/applications/$1/static/$2

 
    Options -Indexes
    ExpiresActive On
    ExpiresDefault "access plus 1 hour"
    Order Allow,Deny
    Allow from all
 

  CustomLog /var/log/apache2/access.log common
  ErrorLog /var/log/apache2/error.log

' > /etc/apache2/sites-available/default

# echo "setting up PAM"
# echo "================"
# sudo apt-get install pwauth
# sudo ln -s /etc/apache2/mods-available/authnz_external.load /etc/apache2/mods-enabled
# ln -s /etc/pam.d/apache2 /etc/pam.d/httpd
# usermod -a -G shadow www-data

echo "restarting apache"
echo "================"

/etc/init.d/apache2 restart
cd /home/www-data/web2py
sudo -u www-data python -c "from gluon.widget import console; console();"
sudo -u www-data python -c "from gluon.main import save_password; save_password(raw_input('admin password: '),443)"
echo "done!"

Marlin for CNC

ini yang saya ganti di pin.h
banyakan sih di STEP dan DIR

di configuration.h set ke motherboard 99
jangan lupa set default_step juga

configuration.h
  Z_MIN_POS -150
  HEATER_0_MINTEMP 0
  #define DEFAULT_AXIS_STEPS_PER_UNIT   {78.7402,78.7402,200.0*8/3,760*1.1}  // default steps per unit for Ultimaker
sesuaikan dengan rumus.

pin.h

#if MOTHERBOARD == 99
#define KNOWN_BOARD 1

#define X_STEP_PIN          3
#define X_DIR_PIN           4
#define X_ENABLE_PIN        -1
#define X_STOP_PIN          -1

#define Y_STEP_PIN          7
#define Y_DIR_PIN           8
#define Y_ENABLE_PIN       -1
#define Y_STOP_PIN          -1

#define Z_STEP_PIN          5
#define Z_DIR_PIN           6
#define Z_ENABLE_PIN       -1
#define Z_STOP_PIN          -1

#define E0_STEP_PIN         9
#define E0_DIR_PIN          10
#define E0_ENABLE_PIN      -1

#define SDPOWER            -1
#define SDSS               53
#define LED_PIN            -1
#define FAN_PIN            -1
#define PS_ON_PIN           9
#define KILL_PIN           -1

#define HEATER_0_PIN        13
#define HEATER_1_PIN       -1
#define HEATER_2_PIN       -1
#define TEMP_0_PIN          6   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
#define TEMP_1_PIN         -1   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
#define TEMP_2_PIN         -1   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
#define HEATER_BED_PIN      4
#define TEMP_BED_PIN       10

#endif /* 99 */


referensi saya:
http://www.buildlog.net/blog/2012/08/hacking-your-cnc-toolchain/

Updated Robot WishList

  1. I would like to have a mobile workstation for my laptop, i usually change place while working.. living room, backyard.. etc (still in my home)
  2. Making the robot available to Indonesian language is better.
  3. I don't watch TV so much  but I would like to have recent news from selected RSS internet feed
  4. Communicating with people.. i mean telephony system in my robot.. i can perform calls from my laptop and vice versa.
  5. I want to check email.. and someone read it for me.
  6. Browsing the internet by voice or virtual touch (without mouse?)
  7. Entertaing robot..
  8. I have music clips or movie clips that i like to see many times. (building database and a navigation menu for search)
  9. I shared my laptop with my wife, and some other people.. so i cannot close the laptop for only one software. maybe other people can use the system too..
  10. Video capture
  11. I love music and love playing drums.. i want to have a recording station while jamming with my friends.
  12. Chatting with the robot would be nice
  13. Should be relatively cheap.. =)
  14. I like to have a menu system for my robot
  15. The robot should have a brain for navigating my house.
  16. The robot can recognize face and objects..
  17. Home controlled by robot.. this is good
  18. Robot Emotions? Leaf have that
  19. The robot can take or bring me something... (i think it's very hard)
  20. This one is really deep..   i want to ride my robot. transportation in my neigborhood maybe?? (last priority :) )

21. Sync with Social Media / Facebook / Twitter / email
22. Design is Modular. Can add Head / Arm / other Interface.
23. Remainder - Sync with Contacts and Google Calendar.
24. Update with weather and Traffic Jam CCTV.

25. Can use APM - Mission planner and Turnigy Remote
26. Interface to ROS


PCB Design Error

Ini kesalahan saya dalam mendesain PCB.

1. Posisi Terminal tidak lega.
posisi terminal yang miring tidak membuat pemasangan kabel menjadi mudah, melainkan cukup menyulitkan.
Buat terminal di pinggir dan lubang menghadap luar

2. Jalur bisa dibuat lebih besar.
Sepertinya saya memakai 0.5 sebagai lebar jalur. Bisa gunakan 0.7 / 0.8


Tambahan Installasi melengkapi Chippy





sudo apt-get install psmisc

sudo apt-get install python-espeak python-serial

sudo pip install npyscreen

sudo apt-get install chrony


Cwiid(Wiimote untuk Python)

sudo apt-get install libcwiid1 lswm wmgui wminput
sudo apt-get install python-cwiid

? bluetooth
sudo apt-get install bluez libbluetooth-dev python-dbus python-gobject

sudo apt-get install bluez-utils (122MB?)

sudo apt-get install lame ubuntu-restricted-extras

Serial to python



Dalam membuat robot saya memakai arduino sebagai mikrokontrollernya, banyak hal tersambung ke mikro ini. mis: sensor dan motor.

Dalam pengkodean arduino saya memakai cara yang praktis namun memakan banyak resource program. Yaitu menggunakan String sebagai alat transport serial.




setelah pembacaan sensor, semua value langsung di buatkan string seperti ini:




0:1:2:3:4:5:6:1:2:3:4#




langsung di send sekali jalan ke komputer, sama sekali nggak effisien resource, tapi program cepat jadi.




kekurangannya ialah : setiap delay(xxx) akan mempengaruhi kinerja.




maka dari itu pelajarilah contoh SerialEvent.ino yang dibundle dengan IDE arduino. dengan itu. anda dapat menggunakan serial untuk menerima karakter perintah, walaupun sensor tetap mengirim data ke komputer.




Sebelumnya saya memproses satu persatu. namun ada teknik program yang membuat serial menjadi lebih efisien.




Tetap belajar.








// ---------------------------------------------------------------------------

// This example code was used to successfully communicate with 15 ultrasonic sensors. You can adjust

// the number of sensors in your project by changing SONAR_NUM and the number of NewPing objects in the

// "sonar" array. You also need to change the pins for each sensor for the NewPing objects. Each sensor

// is pinged at 33ms intervals. So, one cycle of all sensors takes 495ms (33 * 15 = 495ms). The results

// are sent to the "oneSensorCycle" function which currently just displays the distance data. Your project

// would normally process the sensor results in this function (for example, decide if a robot needs to

// turn and call the turn function). Keep in mind this example is event-driven. Your complete sketch needs

// to be written so there's no "delay" commands and the loop() cycles at faster than a 33ms rate. If other

// processes take longer than 33ms, you'll need to increase PING_INTERVAL so it doesn't get behind.

// ---------------------------------------------------------------------------

#include
#include
// the commands needed for the SRF sensors:
#define sensorAddress 0x60
// this is the memory register in the sensor that contains the result:
#define resultRegister 0x02
#define SONAR_NUM 6 // Number or sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
#define PING1_TR 51 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define PING1_EC 53 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define PING2_TR 47
#define PING2_EC 49
#define PING3_TR 43
#define PING3_EC 45
#define PING4_TR 39
#define PING4_EC 41
#define PING5_TR 35
#define PING5_EC 37
#define PING6_TR 31
#define PING6_EC 33
#define buzzPin 13
//Arduino to EMS30 Pin
int MIN1_1 = 11;
int MIN1_2 = 10;
int MEN1_1 = 12;
int MEN1_2 = 9;
int MPWM1 = 8;
int MIN2_1 = 6;
int MIN2_2 = 5;
int MEN2_1 = 7;
int MEN2_2 = 4;
int MPWM2 = 3;
int PPWM1 = 0;
int PPWM2 = 0;
int SPEED = 0;
int DIR = 0;
String XTRA = "";
int pinBuzzer = 40;
unsigned int uS1 = 0;
unsigned int uS2 = 0;
unsigned int uS3 = 0;
unsigned int uS4 = 0;
unsigned int uS5 = 0;
unsigned int uS6 = 0;
float filterVal = .6;
float suS1 = 0;
float suS2 = 0;
float suS3 = 0;
float suS4 = 0;
float suS5 = 0;
float suS6 = 0;
float ir_filterVal = .4;
float iR1 = 0;
float iR2 = 0;
float iR3 = 0;
float iR4 = 0;
//cmps
int bearing = 0;

NewPing ping1(PING1_TR, PING1_EC, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
NewPing ping2(PING2_TR, PING2_EC, MAX_DISTANCE);
NewPing ping3(PING3_TR, PING3_EC, MAX_DISTANCE);
NewPing ping4(PING4_TR, PING4_EC, MAX_DISTANCE);
NewPing ping5(PING5_TR, PING5_EC, MAX_DISTANCE);
NewPing ping6(PING6_TR, PING6_EC, MAX_DISTANCE);

String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete


void getInfraRed()
{
iR1 = smooth(averageAnalog(6),ir_filterVal, iR1);
iR2 = smooth(averageAnalog(5),ir_filterVal, iR2);
iR3 = smooth(averageAnalog(8),ir_filterVal, iR3);
iR4 = smooth(averageAnalog(7),ir_filterVal, iR4);
// iR1 = averageAnalog(6);
// iR2 = averageAnalog(5);
// iR3 = averageAnalog(8);
// iR4 = averageAnalog(7);
//delay(100);
}
// for smoothing value in Range
int smooth(int data, float filterVal, float smoothedVal){

if (filterVal > 1){ // check to make sure param's are within range
filterVal = .99;
}
else if (filterVal <= 0){
filterVal = 0;
}
smoothedVal = (data * (1 - filterVal)) + (smoothedVal * filterVal);
return (int)smoothedVal;
}
void errorBeep()
{
digitalWrite(buzzPin, HIGH);
delay(200);
digitalWrite(buzzPin, LOW);
delay(50);
digitalWrite(buzzPin, HIGH);
delay(200);
digitalWrite(buzzPin, LOW);
delay(50);
digitalWrite(buzzPin, HIGH);
delay(200);
digitalWrite(buzzPin, LOW);
}
void getSonar() {
uS1 = ping1.ping()/US_ROUNDTRIP_CM;
uS2 = ping2.ping()/US_ROUNDTRIP_CM;
uS3 = ping3.ping()/US_ROUNDTRIP_CM;
uS4 = ping4.ping()/US_ROUNDTRIP_CM;
uS5 = ping5.ping()/US_ROUNDTRIP_CM;
uS6 = ping6.ping()/US_ROUNDTRIP_CM;
if(uS1 == 0){ uS1 = int(suS1);}
if(uS2 == 0){ uS2 = int(suS2);}
if(uS3 == 0){ uS3 = int(suS3);}
if(uS4 == 0){ uS4 = int(suS4);}
if(uS5 == 0){ uS5 = int(suS5);}
if(uS6 == 0){ uS6 = int(suS6);}
//average both
suS1 = smooth(uS1,filterVal,suS1);
suS2 = smooth(uS2,filterVal,suS2);
suS3 = smooth(uS3,filterVal,suS3);
suS4 = smooth(uS4,filterVal,suS4);
suS5 = smooth(uS5,filterVal,suS5);
suS6 = smooth(uS6,filterVal,suS6);

}
int averageAnalog(int pin){
int v=0;
for(int i=0; i<4 analogread="analogread" br="br" i="i" pin="pin" v="v"> return v/4;
}
void doubleBeep()
{
digitalWrite(buzzPin, HIGH);
delay(300);
digitalWrite(buzzPin, LOW);
delay(50);
digitalWrite(buzzPin, HIGH);
delay(300);
digitalWrite(buzzPin, LOW);
}

void turnLeft(){
digitalWrite(MIN1_1,LOW); //go back
digitalWrite(MIN1_2, HIGH);
digitalWrite(MIN2_1,HIGH); //go back
digitalWrite(MIN2_2, LOW);
}

void turnRight(){
digitalWrite(MIN1_1,HIGH); //go back
digitalWrite(MIN1_2, LOW);
digitalWrite(MIN2_1,LOW); //go back
digitalWrite(MIN2_2, HIGH);
}

void goBackward(){
digitalWrite(MIN1_1,LOW); //maju
digitalWrite(MIN1_2, HIGH);
digitalWrite(MIN2_1,LOW); //maju
digitalWrite(MIN2_2, HIGH);
}
void goForward(){
digitalWrite(MIN1_1,HIGH); //go back
digitalWrite(MIN1_2, LOW);
digitalWrite(MIN2_1,HIGH); //go back
digitalWrite(MIN2_2, LOW);
}
void stopMe() {
digitalWrite(MIN1_1,LOW);
digitalWrite(MIN1_2, LOW);
digitalWrite(MIN2_1,LOW);
digitalWrite(MIN2_2, LOW);
digitalWrite(MPWM1, HIGH); //PWM Speed Control
digitalWrite(MPWM2, HIGH); //PWM Speed Control
}
void highMen(){
digitalWrite(MEN1_1,HIGH);
digitalWrite(MEN1_2, HIGH);
digitalWrite(MEN2_1,HIGH);
digitalWrite(MEN2_2, HIGH);
delay(30);}
void lowMen(){
digitalWrite(MEN1_1,LOW);
digitalWrite(MEN1_2, LOW);
digitalWrite(MEN2_1,LOW);
digitalWrite(MEN2_2, LOW);
delay(30);}
void setPPWM(){
analogWrite(MPWM1, PPWM1); //PWM Speed Control
analogWrite(MPWM2, PPWM2); //PWM Speed Control
}
void processString() {
String stringOne = inputString;
int firsty = stringOne.indexOf(":");
int secondy = stringOne.indexOf(":",firsty+1);
int thirdy = stringOne.indexOf(":",secondy+1);
int foury = stringOne.indexOf(":",thirdy+1);
int fivy = stringOne.length();

String onez = stringOne.substring(0,firsty);
String duez = stringOne.substring(firsty+1,secondy);
String thirdez = stringOne.substring(secondy+1,thirdy);
String fourdy = stringOne.substring(thirdy+1,foury);
String fivedy = stringOne.substring(foury+1,fivy);
SPEED = onez.toInt();
DIR = duez.toInt();
PPWM1 = thirdez.toInt();
PPWM2 = fourdy.toInt();
XTRA = fivedy;
}
void stopRobot(){
stopMe();
}



void setup() {
doubleBeep();
pinMode(MIN1_1, OUTPUT);
pinMode(MIN1_2, OUTPUT);
pinMode(MEN1_1, OUTPUT);
pinMode(MEN1_2, OUTPUT);
pinMode(MIN2_1, OUTPUT);
pinMode(MIN2_2, OUTPUT);
pinMode(MEN2_1, OUTPUT);
pinMode(MEN2_2, OUTPUT);
pinMode(MPWM1, OUTPUT);
pinMode(MPWM2, OUTPUT);
highMen(); // turn on MEN

Serial.begin(115200);
Wire.begin();
//
inputString.reserve(200);
Serial.println("Ready");
}
void loop() {
// Process the string when a newline arrives:
// print the string when a newline arrives:
if (stringComplete) {
// clear the string:
inputString = "";
stringComplete = false;
}
if (DIR == 1) {
goForward();
setPPWM();
}
if (DIR == 3) {
goBackward();
setPPWM();
}
if (DIR == 2) {
turnLeft();
setPPWM();
}
if (DIR == 4) {
turnRight();
setPPWM();
}
if (DIR == 0) {
stopRobot();
}

getInfraRed();
getSonar();

// send the CMPS command to read the result in degree:
setRegister(sensorAddress, resultRegister);
// read the result:
bearing = readData(sensorAddress, 2);

sendSerial();


}
void sendSerial(){
Serial.print("S:");
Serial.print(suS1);
Serial.print(":");
Serial.print(suS2);
Serial.print(":");
Serial.print(suS3);
Serial.print(":");
Serial.print(suS4);
Serial.print(":");
Serial.print(suS5);
Serial.print(":");
Serial.print(suS6);
Serial.print(":");
Serial.print(iR1);
Serial.print(":");
Serial.print(iR2);
Serial.print(":");
Serial.print(iR3);
Serial.print(":");
Serial.print(iR4);
Serial.print(":");
Serial.print(bearing/10);
Serial.println(":");

}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '#') {
stringComplete = true;
processString();
}
}
}


/*
setRegister() tells the CMP sensor to change the address pointer position
*/
void setRegister(int address, int thisRegister) {
// start I2C transmission:
Wire.beginTransmission(address);
// send address to read from:
Wire.write(thisRegister);
// end I2C transmission:
Wire.endTransmission();
}
/*
readData() returns a result from the SRF sensor
*/
int readData(int address, int numBytes) {
int result = 0; // the result is two bytes long
// send I2C request for data:
Wire.requestFrom(address, numBytes);
// wait for two bytes to return:
while (Wire.available() < 2 ) {
// wait for result
}
// read the two bytes, and combine them into one int:
result = Wire.read() * 256;
result = result + Wire.read();
// return the result:
return result;
}

Install MOSQUITTO

Nyamuk-nyamuk... beneran ini sebenernya server. bukan nyamuk beneran, karena sangat ringan maka disebut mosquitto

Install karena sangat berguna.


sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update 
sudo apt-get install mosquitto python-mosquitto
sudo apt-get install mosquitto-clients


ngetest


mosquitto_pub -d -t hello/world -m "Hello, MQTT. This is my first message."

mosquitto_sub -d -t hello/world
Kalau dari python seperti ini:
import mosquitto
mqttc = mosquitto.Mosquitto("python_pub")
mqttc.will_set("/event/dropped", "Sorry, I seem to have died.")
mqttc.connect("127.0.0.1", 1883, 60, True)

mqttc.publish("hello/world", "Hello, World!") 

Network di Beagleboard

Setting /etc/network/interfaces



auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
# Example to keep MAC address between reboots
#hwaddress ether DE:AD:BE:EF:CA:FE

# WiFi Example
auto wlan0
iface wlan0 inet dhcp
 wireless-essid AZANA16-2

#    wpa-ssid "essid"
#    wpa-psk  "password"

OpenCV and SimpleCV

SimpleCV merupakan gabungan pekerjaan orang-orang yang menginginkan Opencv versi mudah. Jadi pemakaian dapat dikerjakan oleh orang-orang yang tidak terlalu teknikal.

Cocok saya pikir. Saya coba install ini di beagleboard, seharusnya bisa juga di Raspberry. (OS: UBUNTU)

ini untuk 12.04 -> saya pernah coba di 11.10 gagal terus.

Install OpenCV 2.3.1 (ya bukan yang paling terakhir)

sudo apt-get install libopencv-*


Install SimpleCV nya.

$ sudo apt-get install ipython python-opencv python-scipy python-numpy python-pygame python-setuptools python-pip
$ sudo pip install https://github.com/ingenuitas/SimpleCV/zipball/master



ROS - MQTT Robotic

Saya jatuh cinta sama ROS ketika saya sudah menyelesaikan seluruh tutorialnya. Teknik mengimplementasikan pemrograman seperti ROS (menggunakan messaging system) sangat potensial dan sangat memudahkan penggunaan kode lama.

Namun ada beberapa hal kendala, dalam perjalanan saya memakai ROS dengan Beagleboard. Sebagian besar resource dari beagle termakan oleh system. ini padahal belum penggunaan yang besar. hanya puluhan sensor. Tanpa banyaknya data feed saja sudah memakan sekitar 50% resource.
Jadi saya harus mengambil langkah lain.

Selain itu, saya sangat menyukai python sebagai bahasa pemrograman. Jadi saya memutuskan untuk mencari message broker yang ringan supaya saya bisa implementasikan teknik program seperti ROS. dan ketemulah MQTT dari IBM.

Menginstall mosquitto (server mqtt open source) sangat mudah. Jadi saya mencoba untuk buat program di manajer system dengan python dan menggunakan mqtt sebagai servernya.

Jadinya seperti ini. di bagian badan robot inilah nantinya MQTT akan mengelola seluruh informasinya.

setelah saya buat kembali programnya dengan konsep yang sama, ternyata hasil pemakaian resource di linux hanya sekitar 12% s/d 16% . jadi saya cukup puas karena masih bisa menyisakan untuk proses opencv dan speech recognition. 

Kesimpulannya:
ROS dapat mengambil info yang diperlukannya dengan konek ke MQTT.

Wassalam.



NTP update - firstmedia

Saya menggunakan firstmedia sebagai layanan provider internet di rumah. Namun salah satu kendala menggunakan provider ini ialah: port bawah < 1024 di blok untuk pengamanan.
Jadi tcp untuk menggunakan ntp akan otomatis gagal.

Namun beberapa mesin linux saya selalu reboot dan tanggalnya menjadi salah. Harus menggunakan port yang tidak umum. Baru saya tahu bahwa ada fasilitas standard dari ntp yaitu: -u

jadi install ntp
sudo apt-get install ntpdate

sudo ntpdate -u id.pool.ntp.org

selamat mencoba.

ROS - Robotic Operating System

Pada saat inilah mulai saya mengerti, apa gunanya kita memakai middleware ROS (www.ros.org)... Buaaanyaaak sekali.. hehehe.
Dasar kurang pinter ya begini, padahal saya sudah tahu dari beberapa tahun yang lalu.. tapi memang karena kurang mudeng, dan dukungan support hardware yang masih minim, jadi saya tidak memakai ROS.
Konsep dasarnya begini. ROS memberikan istilah Nodes kepada tiap elemennya, bisa wujud hardware atau wujud konseptual. Nah dengan ROS kita dapat mempermudah sistem pemindahan data antar NODES, dengan sistem TOPIC.
Bayangkan TOPIC ini semacam Papan Informasi yang tiap Nodesnya dapat melihat atau menaruh informasi. Bayangin aja Mading jaman SMA.. hehehe..

Misalnya kita membuat robot sederhana menggunakan 4 nodes.

2 Nodes warna biru adalah nodes yang menggunakan hardware. Satu usb camera dan yang satu lagi adalah motor penggerak / servo.

2 Nodes kuning adalah nodes yang konseptual, artinya hanya ada secara konsep. Tidak ada benda fisiknya. Namun kita dapat membuatnya di ROS. Masing masing nodes itu adalah sebuah program yang di buat dengan bahasa pemrogramman cpp atau python.

Nah setelah menentukan nodes, kita dapat menentukan Topik, pengembangannya sbb.


Tiap -tiap nodes terhubung melalui sebuah topik khusus. Nodes Camera mem'publish' Topik Landmark Visual. Isi dari Topik ini adalah data yang ditangkap oleh kamera. Namun data ini berguna bagi nodes visualisasi titik lokasi, nodes ini 'subscribe' ke topik tsb, mengambil datanya.. lalu mengolahnya menjadi data yang berguna untuk menentukan titik kordinat robot sekarang.

Nah setelah kita dapat menentukan dimana posisi robot maka node ini akan mempublish ke topik yang berhubungan dengan navigasi. Maka nodes navigasi akan mengambil data tsb untuk diolah menjadi arah navigasi robot mau kemana.
lalu Nodes motor / servo mengambil lagi data olahan tersebut menjadi gerak daripada robot.

Tentunya ini hanya gambaran yang sangat disederhanakan. Inti dari menggunakan ROS ini adalah...
Banyaknya Nodes yang ditulis oleh programmer-programmer lain.
Artinya kolaborasi menjadi penting, dan banyak code yang dapat di pergunakan secara berulang-ulang.

Nodes / fasilitas ROS yang sangat menarik saya meliputi.

  • Navigasi / Slam / Vslam / gMapping
  • OpenCV (Computer Vision)
  • 3D Manipulator (Kalau mau buat robot tangan)
  • Debugging tools
  • Nodes dapat terdistribusi... artinya Nodes bisa berada di mesin lain yang terkonek secara network.
  • SMACH - Logika / prioritas.
  • Koneksi ke ARDUINO.. yipeee..
  • dan banyak lainnya.. wweeewww....
Terima kasih.. nanti saya terusin lagi.. so excited untuk ngoprek

Arduino interface ke CMPS03 Davantech

Terima kasih, arduino telah memfasilitasi I2c, pull-up di pin SCA/SCL 4.7
kohm sehingga tidak perlu lagi resistor tersebut.
Pin yang di gunakan arduino untuk I2c ialah pin4 dan pin 5
pin 4 – SDA
pin 5 – SCL
tinggal masukan power dan ground maka cmps03 langsung berfungsi.
Kode ini bisa jalan dengan mulus.
 
#include <Wire.h>

/*
CMPS03 compass reader
language: Wiring/Arduino

Reads data from a Devantech CMP03 compass sensor.

Sensor connections:
SDA - Analog pin 4
SCL - Analog pin 5

created 5 Mar. 2007
by Tom Igoe

*/

// include Wire library to read and write I2C commands:

// the commands needed for the SRF sensors:
#define sensorAddress 0x60
// this is the memory register in the sensor that contains the result:
#define resultRegister 0x02

void setup()
{
// start the I2C bus
Wire.begin();
// open the serial port:
Serial.begin(9600);
}

void loop()
{

// send the command to read the result in inches:
setRegister(sensorAddress, resultRegister);
// read the result:
int bearing = readData(sensorAddress, 2);
// print it:
Serial.print("bearing: ");
Serial.print(bearing/10);
Serial.println(" degrees");
// wait before next reading:
delay(70);
}

/*
setRegister() tells the SRF sensor to change the address pointer position
*/
void setRegister(int address, int thisRegister) {
// start I2C transmission:
Wire.beginTransmission(address);
// send address to read from:
Wire.send(thisRegister);
// end I2C transmission:
Wire.endTransmission();
}
/*
readData() returns a result from the SRF sensor
*/

int readData(int address, int numBytes) {
int result = 0; // the result is two bytes long

// send I2C request for data:
Wire.requestFrom(address, numBytes);
// wait for two bytes to return:
while (Wire.available() < 2 ) {
// wait for result
}
// read the two bytes, and combine them into one int:
result = Wire.receive() * 256;
result = result + Wire.receive();
// return the result:
return result;
}