Page 244 - The Ultimate Palm Robot
P. 244

Color profile: Generic CMYK printer profile
           Composite  Default screen
                                                          Bots /The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8






                                                   Chapter 8  Taking Control of the BrainStem Robot  227



                                            CommPortIdentifier.getPortIdentifier(portname);
                                          SerialPort serialPort =
                                            (SerialPort) portId.open("AbstractBrainStem", 2000);

                                          inputStream = serialPort.getInputStream();
                                          outputStream = serialPort.getOutputStream();


                                          serialPort.addEventListener(stem);
                                          serialPort.notifyOnDataAvailable(true);

                                          stem.SetStream(inputStream, outputStream);

                                          gp = new jGP(stem, moduleAddress);
                                        } catch (Exception e) {
                                          e.printStackTrace();
                                        }
                                      }

                                      public float readSensor(int sensorNumber) {
                                        float result = -1;
                                        try {
                                          result = gp.AnalogIn((byte) sensorNumber);
                                        } catch (jErr e) {
                                          e.printStackTrace();
                                        }
                                        return result;
                                      }
                                      public void startServo(int servoNumber, float amount) {
                                        try {
                                          gp.ServoAbs((byte) servoNumber, amount);
                                        } catch (jErr e) {
                                          e.printStackTrace();
                                        }
                                      }

                                      public void stopServo(int servoNumber) {
                                        try {
                                          gp.ServoAbs((byte) servoNumber, 0f);
                                        } catch (jErr e) {
                                          e.printStackTrace();
                                        }
                                      }
                                   }








           P:\010Comp\Bots\880-6\ch08.vp
           Monday, May 12, 2003 1:16:48 PM
   239   240   241   242   243   244   245   246   247   248   249