Learning journal Susant
Laser cutting
Learning question:
How can I use the laser cutters in the Makerslab so I can cut the redesigned frame for the cart.
This was my first time using a laser cutter, so when I wanted to cut the new frame for the cart I had no idea what to do. The teachers at the Makerslab where there and they explained to me how I can use the laser cutter.
After they explained to me how to use the laser cutter I tried to cut the first frame for the cart. The penholder hole was only a bit too small so I had to cut it again. To make the hole bigger I used the interface from the laser cutter
Rotate stepper motor
Learning question:
How can I convert the steps from the stepper motor into degrees.
We want to have the bot be able to rotate because that is kinda important if you want to draw shapes. To get the bot to drive forward we give it an amount of steps to rotate. But to get the bot to make a turn I wanted it to be a bit more specific by being able to give it degrees.
If I want to use degree I first need to calculate how much steps it takes to make a full 360 degree rotation. I did this by testing every possible amount of steps till I got around 360 degree. When testing I managed to get a 360 degree rotation with 6875 steps.
Last thing I needed to do was to convert the steps to degrees. I took the amount of steps it took to make a full rotaion and divided it with 360 to get the steps required for a rotation of 1 degree. With the steps required to make a rotation of 1 degree I wrote a function for rotating the cart.
1 2 3 4 5 6 7 |
|
Implementing json
Learning question:
How can I use a json file to change the parameters for the detection script
This was the first time I had to use json and I dind't really understand how it worked. I knew how you could store data or variables into a json file. But i didn't know how I could get that data out of there and use it. When looking up how to implement it I found a website that explained to me how i could store data, the website also explained how to import the data in a diffrent python file and print it to your console. It however didn't explain how I could get an individual variable from the json script into the python script. To figure that out I tried asking chatGTP to help me with extracting specific data from the json file.
For the json file I had to log seven variables they would be: the color values for lower and upper red, the color values for lower and upper white, last time the mqtt sent something, an message and the mqtt connection. When I was writing the values for the variables I didn't know you could write the integer. what I did before was having the nummers in string which results in the progam not being able to use the variables as parameters since they required a integer. I learned that you could just put the integers after a team member showed me the correct way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
1 2 3 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Source:
https://www.tutorialspoint.com/how-to-read-json-file-in-python
Learning story Ajax
Learning question: How can I implement Ajax so I can have my javascript script call the python function that sends json messages.
When looking for ways to implement my userstory and send user data to an mqtt I had a problem with trying to connect with the mqtt. When looking up ways to connect with the mqtt I thought of maybe just calling the python function that sends messages to the mqtt. But since I was using javascirpt and html I coudn't just call the function, when looking up ways to call python functions using javascript I learned about Ajax.
AJAX, which stands for Asynchronous JavaScript and XML, is a web development technique that allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This asynchronous communication means that a web page can update parts of its content without requiring a full page reload. AJAX is not a specific technology but rather a combination of several existing technologies.
In essence, this loadData function exemplifies the typical flow of an AJAX request. It initializes an XMLHttpRequest, configures it, sets up a callback function to handle the response, and sends the request asynchronously. Once a successful response is received, it processes the data, often in JSON format, and updates the content on the web page dynamically. This ability to fetch and update data without requiring a full page reload contributes to a more seamless and interactive user experience in modern web applications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Source
https://www.w3schools.com/js/js_ajax_intro.asp
Learning story Flask
Learning question:
How can I implement Flask so I can use the webpage to run python code.
This is my first time using Flask and I had no idea what it was or how it worked. I needed it because I was making a webpage that could send data to the cart to make the cart drive. But the function to send the data was made in python and the webpage was made in html and javascript.
How I learned about Flask was when I looked at the different ways to execute a python code and after trying the other options I finally decided to use Flask. The first setup I did was installing flask this was a quick pip install that I had to do and flask would be installed. After the install I had to make sure I was importing the package.
After installing Flask I looked up how Flask works, I learned that it uses routes to work and I learned to make my own route. to make a route you first start with @app.route(). In the parameters you can decide the name for the route, if you don't put anything but just a "/" that route will be the root and the program will start with that route. Note that there only can be one root. In the root I made the function to send data to the mqtt to move the cart. I also have other routes these are the other pages of the website where you can change the settings for the broker and camera. When you are done with writing the routes you wan't you also have to run everything or else you won't be able to see anything. You can run everything with a simple app.run.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Source
https://www.geeksforgeeks.org/retrieving-html-from-data-using-flask/