Title: 2. Controlling Robot Car in Ogre
12. Controlling Robot Car in Ogre
- References
- 1. LEGO.com MINDSTORMS NXT Home,
http//mindstorms.lego.com - 2. OGRE 3D, http//www.ogre3d.org/
- 3. MSDN, Microsoft
2LEGO Mindstorms Robots
- The LEGO Mindstorms is a robotic building system
consisting of - The NXT Intelligent Brick the brain of the
system - Sensors and servo motors
- LEGO TECHNIC Elements
- Programming software
3Architecture of the Car Racing System
Motion Tracking Server
Network
Motion Tracking System
Your program
Game Server (Mindstorms Control )
Marker
Marker
Bluetooth radio (Control car movement)
Video Server
Video 3D Graphics
3D Graphics Server
RF (Transmit video)
4Software Architecture
Windows Socket Server IP 158.132.148.218 Port
8889
Network backbone
Your Client Program
Game Server (Mindstorms Control)
Client Windows Socket
Bluetooth Wireless Control
Game mCarNo mTime
WindowSocket
Ogre Graphics Engine (also use for car control)
Should be used to keep the reserved car number
and the time to wait for a free car
5Game Server
- To simplify the task of controlling the robot
car, a Game Server is developed - Provide a Windows socket interface that allows
multiple clients to connect with it using TCP/IP - Commands sent to the Game Server should be in the
form of a string - Four commands
- CONNECT Group_no Student_ID
- MOVE Duration Steering Speed
- CMOVE Duration Steering Speed
- Q
6Command CONNECT
- Before using a robot car, user needs to make a
request to the system - User needs to provide his group number and
student ID for registration - e.g. CONNECT Group01 06123456d
- The whole command should be in the form of a
string with space between the parameters - The command string should be sent to the Game
Server via the Windows Socket connection
established - Consult your tutor about your group number
7Command CONNECT (Cont)
- Upon the receipt of the command, the Game Server
will respond in either one of the following 2
ways - 1. Sending back the acknowledgement string
- ACK CarNo
- CarNo are two characters, e.g. 01, 02,
10 that indicate the no. of the car reserved - 2. Sending back the negative acknowledgement
string - NCK Time
- It means that no free car is available. The user
needs to wait Time seconds for a free car, where
Time is a set of numerical characters
representing the no. of seconds
8Command MOVE and CMOVE
- Once a car is reserved, user can send the MOVE or
CMOVE command to control its motion - Both MOVE and CMOVE have the same format
- MOVE or CMOVE Duration Steering Speed
- Duration Characters that indicate the degree of
wheel rotate (e.g. 720) - (positive ? forward negative ? backward)
- Steering Characters that indicate the direction
of car movement (-100 to 100) - (positive ? turning right, negative ? turning
left) - Speed Characters that indicate the speed of the
car (0 to 100 (full speed))
9When to use MOVE and CMOVE
- The difference of MOVE and CMOVE is only in how
the car stops - MOVE Stop with a brake
- CMOVE Natural stop hence the car may coast for a
while depending on the ground condition - MOVE is used when precise control is needed
- CMOVE is used when smooth movement is needed
10Command Q
- To break the connection with the Game Server, the
user can send a string with a single letter Q - e.g. Q
- Once a connection is made, you need to break the
connection before stopping your program - An error window will be generated by the system
otherwise
11Command Queue of Mindstorms
- The NXT of Mindstorms has a command queue that
allows the buffering of 5 commands working in the
first-in-first-out mode - If the buffer is full and a new command is
received, the oldest command in the queue will be
thrashed to make space for the new one
The queue has only one command waiting for
execution. The next command will go to slot 2
Case 1
5
4
3
2
1
New command received
Case 2
The queue is full. Command 1 will be thrashed to
make space for new command
?
5
4
3
2
1
5
12Advices
- If you issue commands faster than the rate that
Mindstorms executes the commands, - need to prepare some commands may be loss
- need to prepare your commands will have a delay
for going thru the queue before they are executed - If you issue commands slower than the rate that
Mindstorms executes the commands, - the robot car just stays there to wait for your
command - The rate of execution of the commands is
determined by the speed and duration of your MOVE
or CMOVE commands - the faster the speed shorter the duration, the
higher is the rate - Need a good match between the rate of issuing
commands and the choice of MOVE or CMOVE
parameters
13Advices (cont)
- For better control of your car (e.g. for
turning), you may want to have shorter duration,
slower speed - The choice of turning angle may also be important
for better control - For going faster (e.g. to run on a straight
road), you may want to have longer duration,
higher speed - You may also want to use CMOVE instead of MOVE
for a smoother motion - To maximize the performance, the rate of issuing
the commands should match with the parameters you
have chosen
14Things to do in Lab2
- 1. To develop the Game class, which is derived
from the WindowSocket class - Create a Windows socket using the functions of
WindowSocket and connect to the Game server - Implement all member functions for reserving and
controlling the movement of the car - 2. To complete the application in Ogre such that
- When key 1 to 4 is pressed on the keyboard, the
car will move forward, backward, turn left and
right, respectively in MOVE mode - When key 5 to 8 is pressed on the keyboard, the
car will move forward, backward, turn left and
right, respectively in CMOVE mode
15The Game class
- class Game
- public WindowSocket
-
- public
- Game(void)
- Game(void)
- void GetCar(void) // Reserve a car
- void MoveCar(int duration, int steering, int
speed) - // Move the car based on the parameters
- void CMoveCar(int duration, int steering, int
speed) - // CMove the car based on the parameters
- int GetCarNo() return mCarNo
- int GetCarTime() return mTime
- private
- int mCarNo // Store the reserved car number
- int mTime // Store the waiting time
-