Connect robot servo to RPi and use Java Embedded to program it (Part 3)

It's Alive! My Raspberry Pi servo motor is alive with Java Embedded programming!

See:

See RPi Servo demo w/Java Embedded

I'm using Java Embedded to run a Java app that uses the GPIO pins to drive an analog LS-0006 servo motor. Just think of this as a way to control a robotic arm or industrial automation equipment.

Here's a code snippet for now to show what I'm doing (more details and full Java code explanation in a future blog post):

            // Loop forever to create Pulse Width Modulation - PWM
            while (true) {
                
                /*--- Move clockwise to 90 degrees position ---*/
                
                // Create a pulse for repeatLoop number of cycles
                for (counter=0; counter < repeatLoop; counter++) {
                    
                    // HIGH: Set GPIO port ON
                    commandChannel.write(GPIO_ON);
                    commandChannel.flush();               
                
                    // Pulse Width determined by amount of 
                    //   sleep time while HIGH
                    java.lang.Thread.sleep(0, 800000);
        
                    // LOW: Set GPIO port OFF
                    commandChannel.write(GPIO_OFF);
                    commandChannel.flush();
                
                    // Frequency determined by amount of 
                    //  sleep time while LOW
                    java.lang.Thread.sleep(period);
                }
                
                /*--- Move counterclockwise to 0 degrees position ---*/

                // Create a pulse for repeatLoop number of cycles
                for (counter=0; counter < repeatLoop; counter++) {
                    commandChannel.write(GPIO_ON);
                    commandChannel.flush();               
                
                    java.lang.Thread.sleep(2, 200000);
        
                    // Set GPIO port OFF
                    commandChannel.write(GPIO_OFF);
                    commandChannel.flush();
                
                    // Wait for a while
                    java.lang.Thread.sleep(period);
                }
            }

See the full series of blogs posts for this demo:
Connect robot servo to RPi and use Java Embedded to program it (Part 1)
Connect robot servo to RPi and use Java Embedded to program it (Part 2)
Connect robot servo to RPi and use Java Embedded to program it (Part 3)
Connect robot servo to RPi and use Java Embedded to program it (Part 4)
Connect robot servo to RPi and use Java Embedded to program it (Part 5)

Comments:

Post a Comment:
Comments are closed for this entry.
About

Hinkmond Wong's blog on making Machine to Machine (M2M) and the Incredible Internet of Things (IoT) smarter with Java Embedded Technologies

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today