OLADIPUPO JOHN SHOTADE, 20084356 #10
This week Jason the team leader asked me to work on moving the thrusters using a green ball.
Processes involved in this
- Setup of serial communication between the microbit and roborealm
- Setup in roborealm
Setup of serial communication between the microbit and roborealm
Steps involved
- Connected the microbit to a pc using a usb cable
Serial communication module
Steps involved
- Changed the port number to COM3 which is the port the microbit is communicating on
- Changed the baudrate to 115200
Makecode
Onstart block
Steps involved
- Placed the set radio group block from the radio extension and set it to 1 to communicate with the microbit that controls the thrusters.
- Placed the serial redirect to usb block from the serial extension ( which in this case will redirect the serial communication between the microbit and roborealm to usb ) under the set radio group block .
- Placed the serial write line block from the serial extension and changed the value to started (This send the value started serially to roborealm as proof that the serial communication between roborealm and microbit work).
Forever block
Steps involved
- Placed the set variable block from the variables extension (to store the string serially passed in a variable).
- Created a variable received in the variables extension and placed it on variable side of the set variable block to store whatever string that is serially passed in.
- Placed the serial read string block (which reads in the serial values sent from roborealm) in the value part of the set block.
- Placed an if/else statement block from the logic extension under the set block and added twp extra elses.
- Placed the received variable created before in the variable part of the if statement and typed the values left, right, stop and go
- Placed two radio send value blocks (which in this case sends values via radio signals to the microbit that controls the thrusters ) from the radio extension under each value of the received variable.
- Stated if the received variable is equals to the string left the strings left and right are sent to the microbit that controls the thrusters with the value 105 for the string left (which moves the left thruster forward) and the value 90 for the string right (which stops the right thruster).
- Stated if the received variable is equals to the string right the strings left and right are sent to the microbit that controls the thrusters with the value 90 for the string left (which stops the left thruster) and the value 105 for the string right (which moves the right thruster forward).
- Stated if the received variable is equals to the string stop the strings left and right are sent to the microbit that controls the thrusters with the value 90 for the string left (which stops the left thruster) and the value 90 for the string right (which stops the right thruster).
- Stated if the received variable is equals to the string go the strings left and right are sent to the microbit that controls the thrusters with the value 105 for the string left (which moves the left thruster forward) and the value 90 for the string right (which moves the right thruster forward).
Roborealm
Steps involved
- Setup the rgb filter module to filter only the colour green
- Declared a variable serial_cmd using the set variable module and initialized it to hello to send serial commands to the microbit.
- Setup the center of gravity module to stop tracking the green ball if pixel area is below .02% and if pixel density is below 10% in the filter section of the module.
- Setup the display variables module to display the variables COG_AREA (which is the area of the of the roborealm screen), COG_X (which is the X coordinates of the screen) and serial_cmd (which represents the strings values sent serially to the microbit and back to roborealm) and their values at each point in time in the middle of the screen.
- Setup the set variable module to set the serial_cmd variable to stop whenever the green ball isnt on the screen to prevent the thrusters from moving without the green ball being on the screen.
- Wrote an if statement using the if comparison module that states that if the green ball is between the X coordinate of the screen greater than 0 and less than or equals to 200 then the serial_cmd value left is sent to the microbit to move the left thrusters forward.
- Wrote a second if statement that states that if the green ball is between the X coordinate of the screen greater than or equals to 200 and less than or equals to 400 then the serial_cmd value go is sent to the microbit to move both the left and right thrusters forward.
- Wrote a third if statement that states that if the green ball is between the X coordinate of the screen greater than or equals to 400 and less than or equals to 600 then the serial_cmd value right is sent to the microbit to move the right thrusters forward.
- Wrote a fourth if statement that states that if the green ball is between the X coordinate of the screen greater than or equals to 200 and less than or equals to 400 and Area coordinates of the screen is greater than 16000 then the serial_cmd value stop is sent to the microbit to stop both the left and right thrusters.
- Setup the display lines module to display green lines on the roborealm screen starting from the X coordinate and ending at the X coordinate of 200. Starting also at the Y coordinate of 0 and ending at the Y coordinate of 600.
- Another display lines module was setup on the roborealm screen starting from the X coordinate and ending at the X coordinate of 400. Starting also at the Y coordinate of 0 and ending at the Y coordinate of 600.
- Two green lines were drawn using the display lines module to dimarcate the screen into left, middle and right for trial test.
Trial test
Steps involved
- Ran the roborealm code
- Powered the microbit on the usv in order enable communication with the thrusters
- Placed the green ball in the middle of the screen (which stops the thrusters).
- Placed the green ball on the left the screen (which moves the left thruster alone )
- Placed the green ball on the right of the screen (which moves the right thruster alone)
- Placed the green ball back to the middle of the screen and kept moving the green ball toward the web cam and the green ball (which moves both the left and right thrusters until the coordinates of the area is greater than 16000)
Problem encountered
The thrusters were not stopping when the green ball went off the screen
Problem solution
Setting the serial_cmd variable to the value stop just above the if statements (which means if the green ball isnt on the screen both thrusters should be at a halt).
Below are screenshots of the setup in both roborealm and make code
Below is a video of the trial test
Make code link
Roborealm file link
Next step:
FINAL TESTING
Comments
Post a Comment