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

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



                                                                                  CHAPTER 3  ■  MOTION   105



                                leg2 = new BasicLeg(new ServoPosition2(4, 127, 50, 200),
                                        new ServoPosition2(5, 127, 100, 150));
                                leg3 = new BasicLeg(new ServoPosition2(8, 127, 50, 200),
                                        new ServoPosition2(9, 127, 50, 200));
                                leg4 = new BasicLeg(new ServoPosition2(16, 127, 200, 50),
                                        new ServoPosition2(17, 127, 200, 50));
                                leg5 = new BasicLeg(new ServoPosition2(20, 127, 200, 50),
                                        new ServoPosition2(21, 127, 150, 100));
                                leg6 = new BasicLeg(new ServoPosition2(24, 127, 200, 50),
                                        new ServoPosition2(25, 127, 200, 50));

                            }

                            // put legs into walking groups
                            private void setLegGroups() throws Exception {
                                legGroup1.add(leg1);
                                legGroup1.add(leg3);
                                legGroup1.add(leg5);
                                legGroup2.add(leg2);
                                legGroup2.add(leg4);
                                legGroup2.add(leg6);
                            }

                            // this will create an entire string of commands for all legs
                            public String getTotalMove(ArrayList legs, int cmd) throws Exception {
                                StringBuffer cmds = new StringBuffer();
                                for (int i = 0; i < legs.size(); i++) {
                                    BasicLeg tmpLeg = (BasicLeg) legs.get(i);
                                    if (cmd == UP) {
                                        cmds.append(tmpLeg.up());
                                    }
                                    if (cmd == DOWN) {
                                        cmds.append(tmpLeg.down());
                                    }
                                    if (cmd == FORWARD) {
                                        cmds.append(tmpLeg.forward());
                                    }
                                    if (cmd == BACKWARD) {
                                        cmds.append(tmpLeg.backward());
                                    }
                                    if (cmd == NEUTRAL) {
                                        cmds.append(tmpLeg.neutral());
                                    }
                                }
                                return cmds.toString();
                            }
   119   120   121   122   123   124   125   126   127   128   129