robi.sim.objects
Class SimRobot

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--robi.sim.objects.SimObject
                          |
                          +--robi.sim.objects.SimRobot
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, MotorListener, java.lang.Runnable, SensorCaller, java.io.Serializable

public class SimRobot
extends SimObject
implements MotorListener, SensorCaller, java.lang.Runnable

Author:
Reto Witschi The robot object in the simulation
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class robi.sim.objects.SimObject
SimObject.SimMouseAdapter, SimObject.SimMouseMotionAdapter
 
Field Summary
 double angle
          Angle (in radiant)
 java.awt.geom.AffineTransform at
          Current transformation
 boolean isRunning
          Running switch
 boolean isThRunning
          Thread sunning switch
 int motorA
          Power of motor A
 int motorB
          Power of motor B
 int motorC
          Power of motor C
 SimSensor[] sensor
          Sensors 1..3
 SimRoboOption sro
          Robot Option Panel
 java.lang.Thread thRobo
          Robo thread
private  double xc
          Center of canvas
private  double yc
          Center of canvas
 
Fields inherited from class robi.sim.objects.SimObject
DISABLE, ENABLE, height, img, picHeight, picWidth, selected, width, xpos, ypos
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SimRobot(java.lang.String n, int x, int y)
           
 
Method Summary
 void controlMotor(char aMotor, int aMode, int aPower)
          Implementation of MotorListener interface
private  void displayRCXValues()
          Refreshs RCX values
 int getSensorValue(int iSensorId)
          Implementation of SensorCaller interface Returns the requested sensor value
private  void loadPicture(java.lang.String path, java.lang.String filename)
          Loads roboter picture
 void paintComponent(java.awt.Graphics g)
          Paints robot and sets new transformation values
 void remove()
          Removes this object from simulation
 void removeSensor()
          Removes sensors from robot
 void run()
          Main method of painting thread.
private  void setSensors()
          Sets sensor position
 void sh()
          Shows robot and starts painting thread
 void start()
          Starts robot movements
 void step()
          Calculates new position values
 void stop()
          Stops robot movements
 
Methods inherited from class robi.sim.objects.SimObject
actionPerformed, getCX, getCY, getPreferredSize, setLocation, setMenu
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

thRobo

public java.lang.Thread thRobo
Robo thread


angle

public double angle
Angle (in radiant)


at

public java.awt.geom.AffineTransform at
Current transformation


motorA

public int motorA
Power of motor A


motorB

public int motorB
Power of motor B


motorC

public int motorC
Power of motor C


sensor

public SimSensor[] sensor
Sensors 1..3


xc

private double xc
Center of canvas


yc

private double yc
Center of canvas


isRunning

public boolean isRunning
Running switch


isThRunning

public boolean isThRunning
Thread sunning switch


sro

public SimRoboOption sro
Robot Option Panel

Constructor Detail

SimRobot

public SimRobot(java.lang.String n,
                int x,
                int y)
Method Detail

sh

public void sh()
Shows robot and starts painting thread


loadPicture

private final void loadPicture(java.lang.String path,
                               java.lang.String filename)
Loads roboter picture


paintComponent

public void paintComponent(java.awt.Graphics g)
Paints robot and sets new transformation values

Overrides:
paintComponent in class javax.swing.JComponent

run

public void run()
Main method of painting thread. Calculates robot position every 100ms. Collision detection (with frame and lights).

Specified by:
run in interface java.lang.Runnable

controlMotor

public void controlMotor(char aMotor,
                         int aMode,
                         int aPower)
Implementation of MotorListener interface

Specified by:
controlMotor in interface MotorListener
Parameters:
aMotor - The motor id: 'A', 'B' or 'C'.
aMode - 1=forward, 2=backward, 3=stop, 4=float
aPower - A value in the range [0-7].

getSensorValue

public int getSensorValue(int iSensorId)
Implementation of SensorCaller interface Returns the requested sensor value

Specified by:
getSensorValue in interface SensorCaller

step

public void step()
Calculates new position values


start

public void start()
Starts robot movements


stop

public void stop()
Stops robot movements


displayRCXValues

private void displayRCXValues()
Refreshs RCX values


setSensors

private void setSensors()
Sets sensor position


removeSensor

public void removeSensor()
Removes sensors from robot


remove

public void remove()
Removes this object from simulation

Specified by:
remove in class SimObject