Hi Rockmaninoff,
some answers to your questions:
Rockmaninoff wrote:What exactly does the SteeringOperations class do? Is this some sort of Java functionality I don't know about? It looks like it decodes the int you transfer to the NXT, but within the class it just uses getNextID()? Could you explain how that works?
I guess the name "SteeringOperations" might be confusing.
It must be "TransferCodes". It's nothing special. It's only a container for all those transfer codes. Of course, I could have used strings as well but I just decided to use integers.
The operation getNextID() is just a counter which delivers unique IDs which also serve as transfer codes.
The PC and the Nxt share that file. Thus "SteeringOperations" represents the protocol for their communication.
Rockmaninoff wrote:Also, how does your state machine actually work?
Have you had a look on the diagrams which are in PC_RemoteControl.zip (Class_Diagram__StateAdministration.png,
State_Machine_Diagram__StateDiagramm1__StateDiagrammKeysPressedAndReleased.png)? "State_Machine_Diagram__StateDiagramm1__StateDiagrammKeysPressedAndReleased.png" is a state machine diagramm which shows the states. Its implementation is illustrated in the class diagram "Class_Diagram__StateAdministration.png").
I feel it is difficult to put the state machine in words in detail. You can say about the state machine that each movement is represented by a state in general. There are transitions (=state changes) which have an event and an action. The state pattern was applied for its implementation. The first state is "Standing".
I hope you understand the diagrams, don't you?
Rockmaninoff wrote:Is the robot in a standing state unless some button is pressed?
Yes. The robot initializes the state machine with the "Standing"-state. Whenever you release all keys you were pressing,
the state machine gets into the "standing" state.
Rockmaninoff wrote: If so, what happens when a button is released, does it return to the standing state?
That depends whether it is the only key pressed at that time.
Given two scenarios:
1) You are pressing "8". The robot is moving forward. Then you release it. The robot stops and then stands. As long as you are pressing "8", the state machine has the state "MovingForward". As soon as as you release, the state changes to "Standing".
2) You are pressing "8". The state machine has the state "MovingForward". The robot is moving forward. Then you additionally press "9" (=Right) now (so you are pressing "8" AND "9").The state changes to "MovingRightForward". The robot is moving forward and right at the same time. Now you release "9". The state changes back to "MovingForward". The robot stops moving right but it is still moving forward. Thus the second scenarios is about how two movements interfere with each other (=how they run at the same time).
By the way, the state machine makes the motors stop or move or change its speed whenever the state changes (that means the state machine gets a signal which is delegated to the current state, then the current state makes the motors stop or move or change its speed and then returns the new state which is the next state).
Rockmaninoff wrote:EDIT: Wow, so I looked at the code and for SteeringOperations (if I'm looking at this correctly) it seems pretty simple: a 1 for forward, 2 for backward, and so on for the rest of the commands. So if you wanted your robot to go forward, you would transfer a 1 over Bluetooth?
I wished it to be simple before I discovered it isn't (if you want support all basic movements.)
When you press "8" (so that your robot moves forward) then TRANSFER_CODE_KEY_FORWARD_PRESSED is transferred which took the first value of the counter which is 0. So 0 is transferred over Bluetooth.
Rockmaninoff wrote:If I understand that correctly, I guess I still have a couple more questions:
First, does the code dictate that the robot stands if nothing is being passed to it?
Be careful: The PC says only when to begin and when to end a movement into a direction.
Example:
When you press "8", your robot begins to move forward. As long as your key is pressed, the robot is moving forward. As soon as you release "8", your robot stops moving forward. If you haven't another key pressed then it stops moving forward in order to stand.
So as long as you don't have a key pressed, the robot stands (it should at least

.
When I began to program that, I used the keys as switches (that means when I wanted to move my robot forward then I pressed "8". If I wanted it to stop then I had press it again. Releasing a key was ignored). I felt the controlling of the robot was clumsy and difficult that way. That's why I took this approach which it has now. I feel it's easier and better.
Rockmaninoff wrote:Second, why is there a need for the key_released check?
I discovered a problem: my keyboard was not precise.
When I pressed or released a key, then there sometimes were more than one key event triggered which was quite disturbing (I don't know the reason).
For example:
I pressed "8" and the keyboard triggered the "key pressed"-event twice instead of once (which means the key event handler was called twice).
When I released the key, then a lot of "key released"-events were triggered instead of only one (and each resulted in a call of the event handler). The results on the robot were disturbing . So I had to cache and check the inputs the key event handlers deliver and to ignore events which orcurred twice or even more instead of once by accident.
Rockmaninoff wrote:Thanks again.
You are welcome
