Page 116 - The Definitive Guide to Building Java Robots
P. 116

Preston_5564C03.fm  Page 97  Wednesday, October 5, 2005  7:21 AM



                                                                                  CHAPTER 3  ■  MOTION    97



                            The result is the same as BasicArm, but smoother, and with more axes. (See Example 3-18.)

                        Example 3-18. ComplexArm.java
                        package com.scottpreston.javarobot.chapter3;

                        import java.util.ArrayList;

                        import com.scottpreston.javarobot.chapter2.JSerialPort;
                        import com.scottpreston.javarobot.chapter2.SingleSerialPort;

                        public class ComplexArm{

                            // servo positions for differnt servos
                            // shoulder 1
                            private ServoPosition2 s1;
                            // shoulder 2
                            private ServoPosition2 s2;
                            // elbow
                            private ServoPosition2 e;
                            // wrist
                            private ServoPosition2 w;
                            // grip 1
                            private ServoPosition2 g1;
                            // grip 2
                            private ServoPosition2 g2;
                            // LM32 worker
                            private LM32 lm32;
                            // list of servos
                            private ArrayList servos;

                            public ComplexArm(JSerialPort serialPort) throws Exception {
                                lm32 = new LM32(serialPort);
                                // put in seperate method for cleanliness
                                init();
                            }

                            private void init() throws Exception {

                                // note the position pin is not used for the LM32 because it remembers
                                // the position
                                s1 = new ServoPosition2(0);
                                s2 = new ServoPosition2(1);
                                e = new ServoPosition2(2);
                                w = new ServoPosition2(3);
                                g1 = new ServoPosition2(4);
                                g2 = new ServoPosition2(5);
   111   112   113   114   115   116   117   118   119   120   121