BowlerKernel
CreateSensors.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2010 Neuron Robotics, LLC
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  ******************************************************************************/
15 package com.neuronrobotics.sdk.addons.irobot;
16 
17 import com.neuronrobotics.sdk.common.ByteList;
18 
19 // TODO: Auto-generated Javadoc
23 public class CreateSensors {
24 
26  public boolean rightBump=false;
27 
29  public boolean leftBump=false;
30 
32  public boolean rightDrop=false;
33 
35  public boolean leftDrop=false;
36 
38  public boolean centerDrop=false;
39 
41  public boolean wall=false;
42 
44  public boolean clifFrontLeft=false;
45 
47  public boolean clifFrontRight=false;
48 
50  public boolean clifLeft=false;
51 
53  public boolean clifRight=false;
54 
56  public boolean vitrualWall=false;
57 
59  public short distance=0;
60 
62  public short angle=0;
63 
65  public int tempreture=0;
66 
68  public int charge=0;
69 
71  public int capacity=0;
72 
74  public float voltage=0;
75 
77  byte [] data;
78 
84  public CreateSensors(byte [] packet){
85  data=packet;
86  bumps(data[0]);
87  clifLeft = data[1]==1;
88  clifFrontLeft = data[2]==1;
89  clifFrontRight = data[3]==1;
90  clifRight = data[4]==1;
91  vitrualWall = data[5]==1;
92  distance = (short) ((((short)data[12])<<8)+data[13]);
93  angle = (short) ((((short)data[14])<<8)+data[15]);
94  voltage = (float) ((((int)data[17])<<8)+data[18])/1000;
95  tempreture=(char) data[21];
96  charge = (int) ((((int)data[22])<<8)+data[23]);
97  capacity = (int) ((((int)data[24])<<8)+data[25]);
98  }
99 
105  private void bumps(byte data){
106  rightBump=(data&0x01)>0;
107  leftBump=(data&0x02)>0;
108  rightDrop=(data&0x04)>0;
109  leftDrop=(data&0x08)>0;
110  centerDrop=(data&0x10)>0;
111  }
112 
113  /* (non-Javadoc)
114  * @see java.lang.Object#toString()
115  */
116  public String toString(){
117  String s="Raw: "+new ByteList(data);
118  s+="\nDistance: "+distance;
119  s+="\nAngle: "+angle;
120  s+="\nTempreture: "+tempreture;
121  s+="\nCharge: "+charge;
122  s+="\nCapacity: "+capacity;
123  s+="\nVoltage: "+voltage;
124  s+="\nBump right: "+rightBump;
125  s+="\nBump left: "+leftBump;
126 
127  s+="\nDrop right: "+rightDrop;
128  s+="\nDrop left: "+leftDrop;
129  s+="\nDrop center: "+centerDrop;
130 
131 
132  return s;
133  }
134 }