Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 2. Controlling Robot Car in Ogre References: 1. LEGO.com MINDSTORMS NXT Home, 2. OGRE 3D, 3. MSDN,

Similar presentations


Presentation on theme: "1 2. Controlling Robot Car in Ogre References: 1. LEGO.com MINDSTORMS NXT Home, 2. OGRE 3D, 3. MSDN,"— Presentation transcript:

1 1 2. 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

2 2 LEGO 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

3 3 Architecture of the Car Racing System Motion Tracking Server Game Server (Mindstorms Control ) Motion Tracking System Network Video Server Marker 3D Graphics Server Video + 3D Graphics Bluetooth radio (Control car movement) RF (Transmit video) Department of ELECTRONIC AND INFORMATION ENGINEERING Introduction by Dr Daniel Lun Your program

4 4 Software Architecture Game Server (Mindstorms Control) Network backbone Windows Socket Server IP: 158.132.148.218 Port: 8889 Game mCarNo mTime WindowSocket Client Windows Socket Your Client Program 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 Bluetooth Wireless Control Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

5 5 Game 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 DurationSteeringSpeed CMOVEDurationSteeringSpeed Q Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

6 6 Command 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

7 7 Command CONNECT (Con’t) 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

8 8 Command 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 CMOVEDurationSteeringSpeed” 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)) Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

9 9 When 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

10 10 Command 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

11 11 Command 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun 54321 The queue has only one command waiting for execution. The next command will go to slot 2 54321 The queue is full. Command 1 will be thrashed to make space for new command New command received Case 1 Case 2  5

12 12 Advices 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

13 13 Advices (con’t) 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

14 14 Things 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 Department of ELECTRONIC AND INFORMATION ENGINEERING 2. Controlling Robot Car in Ogre by Dr Daniel Lun

15 15 The 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 }; 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 };


Download ppt "1 2. Controlling Robot Car in Ogre References: 1. LEGO.com MINDSTORMS NXT Home, 2. OGRE 3D, 3. MSDN,"

Similar presentations


Ads by Google