Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c3a402e
rotor endstop, diskspace warning
OpenScanEu Sep 4, 2023
ceff2e7
Add support for motor endstops (#1)
Unus-Multorum Jun 27, 2024
f5e3562
add swagger
Sep 15, 2024
61ac413
update changelog
Sep 15, 2024
1a1d7c6
add motor_run endpoint
Sep 21, 2024
ac729cd
update api to v1
Sep 23, 2024
a0174fd
remove old code
Sep 23, 2024
5f1ffbc
change on shutdown
Sep 23, 2024
6c02855
shutdown button
Sep 24, 2024
ae9cc6a
add API documentation usage
Sep 24, 2024
482c072
Meanwhile Update
Sep 27, 2024
56ec112
add statistics file
Sep 27, 2024
98164e2
Updated beta with latest changes
Sep 28, 2024
f075988
Shield choice on meanwhile
Sep 28, 2024
ae1bbbf
move the rotor before tt
Sep 29, 2024
972cddf
change the movement order, first rotor, then tt
Sep 29, 2024
5ae6a3a
Merge branch '2024-11S' into 2024-12o
Sep 29, 2024
3febe33
first 2024-12o version
Sep 29, 2024
d330df6
2024-12o stable
Sep 29, 2024
56b3211
ensure that when pin_tt_endstop has been eliminated the scanner keeps…
Sep 29, 2024
82714cf
reorganize settings section to split rotor and turntable, add option …
Sep 29, 2024
3018e87
u0pdate statistics with openscan versionig
Sep 29, 2024
2953355
add more statistics!
Sep 30, 2024
b75d126
stable branch
Sep 30, 2024
aad761b
rename branch
Oct 1, 2024
c205fbf
rename branch
Oct 1, 2024
3e969e1
add a new way to get the configuration from the files, store it as a …
Oct 2, 2024
88be18b
add settings logic
Oct 2, 2024
79c4ba3
get_settings
Oct 5, 2024
8b76ccd
update
Oct 5, 2024
a57436c
update meanwhile
Oct 5, 2024
d7e5738
zip file
Oct 5, 2024
45b6b9d
statistics endpoint
Oct 5, 2024
fd5f6c4
statistics
Oct 5, 2024
83e95e0
settings
Oct 6, 2024
28522b8
user bugfixes
Oct 10, 2024
b638ed5
Endstops enabled
Unus-Multorum Oct 13, 2024
faec8ab
Update update.json
Unus-Multorum Oct 13, 2024
bc68c57
Last update for endstops
Unus-Multorum Oct 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# OpenScan2 - 3D Scanner
## Related and more specific repositories

Please take a look at the current [CHANGELOG](./docs/changelog.md)

This is not the official OpenScan repository. This is a fork of [Thomas Megel](https://github.com/OpenScanEu) work but completly user-centric. Openscan is great in both software and hardware an
and Thomas has done a great job. But openscan has those things that:
* Users hate and complain continually and there is no one fixing nor acepting fixes/features
* The workflow has ups and downs and some interactions feel buggy.
The aim of this project is to tackle both weaknesses. COnvert this to a pleasant experience fro the burning of the image to the exporting of the model from the scanner.

## Official Openscan repositories:

If you want to take part in the development of a specific part of the OpenScan system, feel free to join:

* [OpenScan2 - Official Openscan files](https://github.com/OpenScanEu/OpenScan2)
* [OpenScanCloud - Web API for photogrammetry processing of image files](https://github.com/OpenScanEu/OpenScanCloud)
* [OpenScan-Design - 3D printable files and other design approaches](https://github.com/OpenScanEu/OpenScan-Design)
* [OpenScan-PCB - A place to discuss and improve the PCB designs](https://github.com/OpenScanEu/OpenScan-PCB)
* [OpenScan-ML - Development of new tools using Machine Learning](https://github.com/OpenScanEu/OpenScan-ML)

## Contribution and contributors

The project is based on the contribution of many great and open-minded people by doing tutorials on Youtube, comments on Reddit, publications on GitHub and many other places. Without all those voluntary contributors, this project would not be possible at all. Please feel free to join the discussions and development preferably in this repository or on [r/OpenScan](https://www.reddit.com/r/OpenScan/), [Facebook - LowBudget3DScan](https://www.facebook.com/groups/142108429832711) or [OpenScan.eu/forum](https://openscan.eu/forum)
The official project is based on the contribution of many great and open-minded people by doing tutorials on Youtube, comments on Reddit, publications on GitHub and many other places. Without all those voluntary contributors, this project would not be possible at all. Please feel free to join the discussions and development preferably in this repository or on [r/OpenScan](https://www.reddit.com/r/OpenScan/), [Facebook - LowBudget3DScan](https://www.facebook.com/groups/142108429832711) or [OpenScan.eu/forum](https://openscan.eu/forum)

Thank you!
78 changes: 78 additions & 0 deletions docs/ADR/API_definition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ADR: Design and Implementation of OpenScan API

## Status

Accepted

## Context

The OpenScan Meanwhile project requires a robust API to facilitate communication between the front-end interface and the underlying hardware components, including the camera and motors. The API must support various operations such as taking photos, controlling the camera settings, managing system states (shutdown and reboot), and operating motors, as well as feedback to the user.

## Decision

We will implement a RESTful API using Flask and Flask-RESTX, structured to provide clear and organized access to system functionalities. The API will be versioned and will include the following namespaces:

1. **System Operations (`/v1/system`)**:
- **GET `/status`**: Retrieve the current status of the system, including elapsed time and estimated time remaining for ongoing operations.
- **GET `/shutdown`**: Initiate a shutdown of the Raspberry Pi.
- **GET `/reboot`**: Initiate a reboot of the Raspberry Pi.
- **GET `/ringlight`**: Control the state of the ringlight (on/off).

![System](../img/Openscan%20Api%20System.png)

2. **Camera Operations (`/v1/camera`)**:
- **GET `/picam2_init`**: Initialize the camera and set up configurations.
- **GET `/picam2_take_photo`**: Capture a photo, process it, and save it to a specified location.
- **GET `/picam2_take_photo_raw`**: Capture a photo and return it in raw format.
- **GET `/picam2_focus`**: Set the focus of the camera to a specified position.
- **GET `/picam2_af`**: Trigger auto-focus functionality.
- **GET `/picam2_exposure`**: Set the camera's exposure time.
- **GET `/picam2_contrast`**: Adjust the camera's contrast settings.
- **GET `/picam2_saturation`**: Adjust the camera's saturation settings.
- **GET `/picam2_switch_mode`**: Switch between different camera modes.
- **GET `/picam2_show_mode`**: Retrieve the current camera mode.

![Camera](../img/Openscan%20Api%20Camera.png)

3. **Motor Operations (`/v1/motor`)**:
- **GET `/motor_run`**: Control a specified motor, allowing for angle adjustments and endstop configurations.

![Motor](../img/Openscan%20Api%20Motor.png)
## Consequences

### Positive

1. **Modular Design**: The API is organized into namespaces, making it easy to understand and extend in the future.
2. **Versioning**: The API is versioned (`/v1`), allowing for backward compatibility as new features are added in future versions.
3. **Clear Documentation**: Each endpoint is documented with parameters and expected responses, facilitating easier integration and usage.


### Negative

1. **Complexity**: The introduction of multiple namespaces and endpoints may increase the complexity of the codebase.
2. **Error Handling**: While basic error handling is implemented, more comprehensive error management may be required as the API evolves.
3. **Performance**: Depending on the implementation of the underlying hardware interactions, performance may vary, especially during high-load operations.

## Implementation

The API is implemented using Flask and Flask-RESTX, with the following key components:

- **Flask**: A lightweight WSGI web application framework for Python.
- **Flask-RESTX**: An extension for Flask that simplifies the creation of RESTful APIs.
- **Picamera2**: A library for controlling the Raspberry Pi camera.
- **GPIO**: A library for controlling the Raspberry Pi's GPIO pins.

### Example Endpoint

**GET `/v1/system/shutdown`**

- **Description**: Initiates a shutdown of the Raspberry Pi.
- **Response**:
- **200 OK**: If the shutdown is initiated successfully.
- **500 Internal Server Error**: If an error occurs while processing the request.

## Notes

- Consider implementing more robust logging and monitoring for the API to track usage and errors.
- Future versions of the API may include additional features such as user authentication, more granular control over camera settings, and enhanced error reporting.
- The API should be designed to be scalable and can be easily integrated with other systems and services.
52 changes: 52 additions & 0 deletions docs/Telegram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Telegram Messaging
### Why
Would it be great to be alerted when a long session ends? The aim of this feature is to have a way (in this case, via telegram) to know when a session is started (giving some basic information about what will happen) and another message when the session ends.

### How
Its only some conditions along the existing flows. If you have activated (and properly configurated) the `Telegram Api Token` and `Telegram Client_id` you will receive the status messages to telegram.

<img src="./img/telegram_configuration.png" width="300" height="200" />

## Setup
Everything is managed by [botfather](https://telegram.me/BotFather). Follow the next steps:

Request a new bot: send the command `/newbot`. The response to that command will be:
```
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
```
Now you name your bot whtever you like. This is how you will identify your bot in your telegram user list from now on.
After choosing the name you willget that response:

```
Done! Congratulations on your new bot. You will find it at t.me/openscan_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.

Use this token to access the HTTP API:
4815162342:N334AA-covfefeskibidi
Keep your token secure and store it safely, it can be used by anyone to control your bot.

For a description of the Bot API, see this page: https://core.telegram.org/bots/api
```

This is a really important part: store that token safely as its the way you will securely talk with your bot.

Now you have 2 ways to fint your "client_id":

The first is open a chat with [@userinfo](https://t.me/userinfobot). If you type ```/start```there you will get an ```Id```response and you can complete the process.

Another way is opening an url in your browser to get your id:

```
https://api.telegram.org/bot<telegram_token>/getUpdates
```

you will revive a response like this:

```
{"ok":true,"result":[{"update_id":462349,
"message":{"message_id":123,"from":{"id":1111111,"is_bot":false,"first_name":"Meanwhile","username":"meanwhile","language_code":"ca"},
```

The Client_id is the "id" field (not the "update_id" or "message_id").
Upon completing the settings with that information you are ready to go!

<img src="./img/telegram_bot_watch.jpg" width="300" height="320" />
52 changes: 52 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Changelog

### 2024-11S
* fixed: shutdown and reboot button in the UI
* Added Swagger UI to help build, design and document the API
* Fixed the FKMSGate
* New update mechanism: Releases have their own version with their own stable, beta and meanwhile flavours.

### 2024-02-26
* Fixed: Without telegram configured it was impossible to finish a scan (hanged on finish). But who in their sanity would not use telegram if available right?
* After a reboot/shutdown, if you forgot to close that tab it will not trigger a disaster when you are scanning in the future

### 2024-02-23 Meanwhile (23F)

This is the beginning of a fork. After several attempts to add a feature and get silence as response I have decided to create my own OpenScan fork.
* added: When doing a focus stack session you can store the contents inside the zip with all the photos sorted in their own folder. Some focus stacking applications will benefit from this.
* added: [You can now get alerts on Telegram](Telegram.md) when the session starts and the session ends
* fixed: The "delete all files" operation no longer prevents the refresh of the file list

### 2022-05-19 documentation
* changed: overall structure --> the OpenScan2 repository will serve as a central hub for all informations concerning OpenScan (i.e. firmware, hardware, tutorials ...)
### 2022-05-11 beta
* added: changelog and version (finally ;)
* added: create an update using the node-red-backend inject node ("create beta" and "prepare image creation" in "update" tab)
* fixed: Error handling in flask (when no preview is taken)
* fixed: Error when upload failed + node red restarted (multiple instances of curl)
* fixed: When closing the browser session/missing the popup after the routine, the data set got lost (if this happens, just restart the device and it will be moved to the right location)
### 2022-04-26 beta
* added: donation button ;)
* fixed: the wonderful camera position algorithm was faulty and a bit inefficient
* fixed: downscaling the preview image caused the preview to disappear (when crop value was to high)
* fixed: delay_before and delay_after are now properly applied, so that you can set a delay before/after taking a photo
* fixed: updates might crash the selected camera --> it is now necessary to re-select the camera after certain updates
### 2022-04-21 beta
* added: timer (ETA) until a routine is done
* added: showing progress, while files are being split (before uploading to OpenScanCloud)
* added: infotexts (FINALLY :)
* added: several stats/device information
* fixed: combining two sets did not delete the smaller set
### 2022-04-20 beta & main
* !fixed: pi cameras (v1.3, v2.1 and HQ) finally work and can be simply selected in the settings menu
* !fixed: Raspberry Pi 3B+ and 4 work! (the main limiting factor now is the RAM, where at least 1GB RAM is needed)
* fixed: live preview sometimes did not work. This has been a network speed issue and has been solved by downscaling the image (resolution can be set)
* fixed: it is now possible to delete individual sets.
* fixed: it is now possible to use all LEDs.
* added: Turntable mode (disable the second axis)
* added: Pause scan. You can pause and un-pause the scan by simply pressing the button
* added: second scan pass. When one scan is done, you can immediately run a second pass. This is especially useful, if you want to re-orient the object
* added: auto-timeout. Turn off the ringlight (todo: and motors) after 300 seconds (value can be set)
* added: diskspace warning. When free diskspace drops below a given threshold (4GB by default), a warning message will appear
* changed: new background image, minor design changes
* changed: log file can be easily generated and downloaded by clicking a button (update&info tab)
Binary file added docs/img/Openscan Api Camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/Openscan Api Motor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/Openscan Api System.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/telegram_bot_watch.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/telegram_configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions update/betaArdu/OpenScan.py → update/2024-11S/beta/OpenScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ def add_wifi_network(ssid, password, country):
with open(conf_file, "w") as f:
f.write(updated_content)
os.system("sudo systemctl restart wpa_supplicant@wlan0")

return True


def load_str(name):
filename = basepath+'settings/'+name
if not isfile(filename):
Expand Down Expand Up @@ -165,7 +163,14 @@ def motorrun(motor,angle,ES_enable=False,ES_start_state = True):
step_count=-step_count
for x in range(step_count):
if ES_enable == True and GPIO.input(ES_pin) != ES_start_state:
break
i = 0
while i <= 10:
if GPIO.input(ES_pin) == ES_start_state:
i = 11
if i == 10:
return
i = i + 1

GPIO.output(steppin, GPIO.HIGH)
if x<=ramp and x<=step_count/2:
delay = delay_init * (1 + -1/acc*cos(1*(ramp-x)/ramp)+1/acc)
Expand Down Expand Up @@ -194,8 +199,6 @@ def take_photo(file):

model=load_str('model')



shutter = str(load_int('cam_shutter'))
saturation = load_str('cam_saturation')
contrast = load_str('cam_contrast')
Expand Down
18 changes: 18 additions & 0 deletions update/2024-11S/beta/OpenScanStatistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import csv

class ScanStatistics:
def __init__(self, filename="/home/pi/OpenScan/statistics/statistics.csv"):
self.filename = filename
self.header = ["arch", "shield", "date_init", "date_end", "num_photos", "done-photos", "camera", "aborted"]

def write_statistics(self, arch, shield, date_init, date_end, num_photos, done_photos, camera, aborted):
data = [arch, shield, date_init, date_end, num_photos, done_photos, camera, aborted]

with open(self.filename, "a", newline='') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=';')

# Write header if file is empty
if csv_file.tell() == 0:
csv_writer.writerow(self.header)

csv_writer.writerow(data)
34 changes: 34 additions & 0 deletions update/2024-11S/beta/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# Additional overlays and parameters are documented /boot/overlays/README

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=1

# Disable compensation for displays with overscan
disable_overscan=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[pi4]
# Run as fast as firmware / board allows
arm_boost=1
dtoverlay=imx519,cma-512

[all]
camera_auto_detect=0
gpu_mem=256
dtoverlay=imx519
7 changes: 7 additions & 0 deletions update/2024-11S/beta/expand_root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
if test -f "/boot/expand_root"; then
echo "expanding root partition"
raspi-config --expand-rootfs
rm -fr /boot/expand_root
shutdown -r now
fi
Loading