美文网首页
COMP2401作业代做、C/C++编程作业调试、代写C/C++

COMP2401作业代做、C/C++编程作业调试、代写C/C++

作者: tupimei | 来源:发表于2019-03-20 18:15 被阅读0次

COMP2401 - Assignment #5(Due: Mon. Mar 25, 2019 @ 12 noon)In this assignment, you will make a simulator for simple robots that uses multiple threads and allowsmultiple robots to connect to it … with each robot running as its own process.To begin this assignment, you should download the following files: simulator.h – contains definitions and structs that will be used throughout your code simulator.c – contains a template for the code that will run the simulator server display.c – contains the window/drawing code that you will use to display the robots stop.c – contains a template for the code for a process that will stop the simulator robotClient.c – contains a template for the code for a process that will run a single robotWhen compiling the files, you will need to include the -lm -lpthread and -lX11 libraries.(but the -lX11 is only needed for the simulator.c file since it uses a window and graphics.)Follow the steps below (in order) to complete the assignment:(1) Examine the simulator.h file. The robots have a radius of ROBOT_RADIUS. Each robot isrepresented as an (x,y) location and a direction. The x and y values are the location of therobot in the window … which will be in the range from ROBOT_RADIUS to (ENV_SIZE -ROBOT_RADIUS). The direction should always be in the range from -180° to +180°. Eachtime a robot moves forward, it moves ROBOT_SPEED pixels in the direction that it is facing.Each time a robot turns, it turns ±ROBOT_TURN_ANGLE degrees. The Environmentcontains up to MAX_ROBOTS robots in an array. numRobots is the number of robotscurrently registered with the server. The shutDown flag indicates whether or not theenvironment has been shut down, it must be set to 0 upon startup.(2) The simulator.c file contains the code for the server template. The main function in this fileMUST spawn two threads … one that will repeatedly accept incoming client requests … andanother that will repeatedly redraw the robots in the window. Both of these threads shouldcontinue until the shutDown flag in the Environment has been set at which point the threadswill each exit gracefully. A pointer to the Environment should be passed in when spawningthe threads so that the threads have access to the robots and the shutdown flag.Write the code so that the two threads call these two functions, respectively:void *handleIncomingRequests(void *environment)void *redraw(void *environment)The redraw() function is in the display.c file and has been completed for you. You MUSTNOT alter any code in the display.c file. When you compile and run the simulator.c file, youshould see a window come up which is empty. Run it in the background (i.e., use &) and thentype ps in the terminal window to see the process id. When you close the window, you shouldsee some XIO error (don’t worry about this). Then typing ps, you should see that the simulatoris no longer running.Write the code in the handleIncomingRequests() function so that it starts up the server andrepeatedly waits for incoming user requests. There are three possible incoming requestsdefined by the definitions in the simulator.h file: (1) REGISTER, (2) STOP and (3) MOVE_TO.For now, write code that accepts an incoming request to STOP the simulator. The codeshould be based on the TCP version of the client/server sockets that were discussed in thenotes. The incoming command for STOP should come in as a single byte. Upon receiving it,the server should shut down gracefully and both threads should be stopped cleanly.Complete the code in the stop.c file so that it attempts to connect to the server and send theSTOP command to the server. Test your code by running the simulator server in thebackground and then running the stop program. If all works well, the simulator window shouldclose and should shut down garecfully. Use ps to make sure that the simulator has indeedshut down properly as well as the stop program. Make sure that you don’t have anysegmentation faults.(3) Now add code to the robotClient.c file so that it attempts to register with the runningsimulator server. To do this, it should send a REGISTER command byte . It should thenwait for a response from the server that should contain an OK or NOT_OK byte response. If the response byte was OK, then additional bytes should be received containing the id of therobot (i.e., its number in the environment array of robots), the randomly chosen (x, y) positionand the randomly chosen direction. Note that it is the simulator server that should choose therandom location and direction (see step (1) above for valid ranges). If you are setting up thesend/receive buffer as unsigned bytes, you will need to split the x, y and direction values intohigh and low bytes. You may also want to have an extra byte to indicate the sign of thedirection (i.e., positive or negative) since the magnitude will be 0 to 180. You will need toadjust the handleIncomingRequests() function in the simulator.c file so that it sends theappropriate bytes back to the client. When all is working, you should see the robot appear inthe simulator window. You’ll need to run the simulator first and then run the robotClientprocess. Once it works, try running a second and third robotClient process … you shouldsee 2 and then 3 robots appearing. Make sure that the stop process still shuts down thesimulator properly.(4) There is a limit to how many robots that can be added. It is set as MAX_ROBOTS, which is 20by default. Adjust the code in the simulator server to deny any registrations that go beyondthis limit. Simply send a NOT_OK response when it is full to capacity. Make sure that therobotClient handles this response properly. Test everything by adding 20 robots and then tryadding a 21st robot. Make sure that you display an appropriate error message in therobotClient code so that it is clear when the client is unable to register.(5) Now add functionality to the robotClient so that it repeatedly moves the robot around in theenvironment indefinitely. To move forward, the robot should calculate a new location basedon its current location and direction as follows: (newX, newY) = (x+S*cos(d), y+S*sin(d))where (x,y) is the current robot location, S is the robot’s speed (in pixels) and d is the robotsdirection. The robot should then send the MOVE_TO request to the server simulator whichshould contain the following information: the MOVE_TO command the robot’s ID the new location that the robot would like to move to the robot’s directionKeep in mind that if you use unsigned char array to send the bytes, you will need to breakdown the newX, newY into two bytes (most significant byte and least significant byte). Youwill also need to be careful sending the direction (which is ±180°) since an unsigned char onlystores values in the 0-255 range and a signed char in the -128 to +127 range.The robot should receive a single byte back from the server which has one of 3 values:1. OK if the robot can move to that location without problems,2. NOT_OK_BOUNDARY if the robot cannot move to that location because it would gooutside the boundary of the environment, and3. NOT_OK_COLLIDE if the robot cannot move to that location because it would collidewith another robot.If all is OK, the robot’s (x,y) location should be updated at the client end. Otherwise, the robotshould turn left or right (chosen randomly) by ROBOT_TURN_ANGLE degrees. To do this, donot change the (x,y) location, just change the direction. Make sure that the direction alwaysremains in the ±180° range. Also, set your code up so that when the robot first hits a boundaryor collides with another robot, it computes the random direction to turn towards (CW or CCW). If the robot is unable to move on any successive turns, it should continue to turn in the SAMEdirection again. It should keep turning ROBOT_TURN_ANGLE degrees once per loopiteration. Only when it is OK to move forward should it begin its forward movement again.Coding things in this manner will ensure that the robot does not alternate turning back andforth in what appears to be an indecisive pattern. If coded properly, you should see the robotturning little by little upon collision.(6) To make things work, you will need to adjust the handleIncomingRequests() function in thesimulator.c file so that it handles incoming MOVE_TO requests from the robots. It will needto receive all the incoming data that was sent to it as part of the MOVE_TO request. It willthen need to ensure that the new location request is valid. Write a canMoveTo() function thatdetermines whether or not the robot can move to that location without collision. It will need tocheck the boundary values as well as the locations of all other robots to decide whether toreturn a value of OK, NOT_OK_BOUNDARY or NOT_OK_COLLIDE. Test your code with asingle robot to see if it works properly. You can lengthen the usleep() delays to slow thingsdown and investigate the movements, but you must put them back to their initial values whenthings seem to be working properly. Test everything with multiple robots and ensure that themoving and collisions are working properly. You might end up with robots stuck on each other… see the next part as a possible explanation,(7) When registering many robots, each is given an initial start location. Sometimes, the locationof one robot may overlap with the location of another robot and the two can get stuck together.Adjust the handleIncomingRequests() function in the simulator.c file so that it ensures thateach robot is placed a unique non-overlapping location in the environment. That is, makesure that the robot can “move to” (i.e., or be initially placed at) the randomly chosen location.You might want to use a WHILE loop until a good random location is found.________________________________________________________________________________IMPORTANT SUBMISSION INSTRUCTIONS:Submit all of your c source code files as a single tar file containing:1. A Readme text file containing your name and studentNumber a list of source files submitted any specific instructions for compiling and/or running your code2. All of your .c source files and all other files needed for testing/running your programs.3. Any output files required, if there are any.The code MUST compile and run on the course VM, which is COMP2404B-W19. If your internet connection at home is down or does not work, we will not accept this as a reason forhanding in an assignment late ... so make sure to submit the assignment WELL BEFORE it is due ! You WILL lose marks on this assignment if any of your files are missing. So, make sure that you handin the correct files and version of your assignment. You will also lose marks if your code is not writtenneatly with proper indentation and containing a reasonable number of comments. See coursenotes for examples of what is proper indentation, writing style and reasonable commenting).本团队核心人员组成主要包括硅谷工程师、BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:C/C++/C#代写Java代写IT代写Python代写辅导编程作业Matlab代写Haskell代写Processing代写Linux环境搭建Rust代写Data Structure Assginment 数据结构代写MIPS代写Machine Learning 作业 代写Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导Web开发、网站开发、网站作业ASP.NET网站开发Finance Insurace Statistics统计、回归、迭代Prolog代写Computer Computational method代做因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 微信:codehelp

相关文章

网友评论

      本文标题:COMP2401作业代做、C/C++编程作业调试、代写C/C++

      本文链接:https://www.haomeiwen.com/subject/izvtvqtx.html