Browse Source

WIP: projection surface

Thorsten Riess 1 year ago
parent
commit
bcaf287c26
2 changed files with 45 additions and 7 deletions
  1. 43
    6
      main/laserpong_main.c
  2. 2
    1
      sdkconfig

+ 43
- 6
main/laserpong_main.c View File

@@ -7,12 +7,42 @@
7 7
    CONDITIONS OF ANY KIND, either express or implied.
8 8
 */
9 9
 #include <stdio.h>
10
+#include <math.h>
10 11
 #include "freertos/FreeRTOS.h"
11 12
 #include "freertos/task.h"
12 13
 #include "esp_system.h"
13 14
 #include "esp_spi_flash.h"
14 15
 #include "driver/ledc.h"
15 16
 
17
+// some servo-specific constants, those also depend on the way the servos are attached to the horns
18
+#define UPDOWN_STRAIGHT  2550
19
+#define UPDOWN_DOWN      1280
20
+#define LEFTRIGHT_LEFT   3200 // 3276
21
+#define LEFTRIGHT_MIDDLE 1920
22
+#define LEFTRIGHT_RIGHT   900
23
+
24
+/*
25
+ * The position of the laser relative to the projection surface is such that the laser is centered horizontally,
26
+ * but sits on the top edge of the surface, so a LEFTRIGHT_MIDDLE and UPDOWN_STRAIGHT point is in the center of
27
+ * the top edge
28
+ * The values that follow here are the dimensions of the surface and the distance of the laser (same unit)
29
+ * such that the corresponding angles for the corners can easily be computed.
30
+ */
31
+// distance to the projection surface (all units are cm)
32
+#define SCREEN_DISTANCE 100
33
+#define SCREEN_WIDTH    100
34
+#define SCREEN_HEIGHT    50
35
+
36
+#define LEFTRIGHT_LEFT_ANGLE  atan2(SCREEN_DISTANCE, SCREEN_WIDTH/2)
37
+#define LEFTRIGHT_RIGHT_ANGLE (-LEFTRIGHT_LEFT_ANGLE)
38
+#define UPDOWN_UP_ANGLE   0
39
+#define UPDOWN_DOWN_ANGLE atan2(SCREEN_DISTANCE, SCREEN_HEIGHT)
40
+
41
+void draw_line()
42
+{
43
+//atan2()
44
+}
45
+
16 46
 void app_main()
17 47
 {
18 48
     printf("Hello world!\n");
@@ -32,25 +62,30 @@ void app_main()
32 62
     timer_conf.timer_num = LEDC_TIMER_0;
33 63
     ledc_timer_config(&timer_conf);
34 64
 
65
+    // 2nd servo up/down
66
+    // 2550 - straight
67
+    // 1280 - down
35 68
     ledc_channel_config_t ledc_conf;
36 69
     ledc_conf.channel = LEDC_CHANNEL_0;
37
-    ledc_conf.duty = 3276; //900; //3276; //1638; // to 3276  // 0 - 2088 (actually a bit less than that)
38
-    ledc_conf.gpio_num = 15;
70
+    ledc_conf.duty = UPDOWN_STRAIGHT; //900; //3276; //1638; // to 3276  // 0 - 2088 (actually a bit less than that)
71
+    ledc_conf.gpio_num = 13;
39 72
     ledc_conf.intr_type = LEDC_INTR_DISABLE;
40 73
     ledc_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
41 74
     ledc_conf.timer_sel = LEDC_TIMER_0;
42 75
     ledc_channel_config(&ledc_conf);
43 76
 
77
+    // first servo connected to ground
78
+    // left-right
79
+    // 3276 - 2000 - 900
44 80
     ledc_channel_config_t ledc_conf2;
45 81
     ledc_conf2.channel = LEDC_CHANNEL_1;
46
-    ledc_conf2.duty = 3276; //900; //3276; //1638; // to 3276  // 0 - 2088 (actually a bit less than that)
47
-    ledc_conf2.gpio_num = 13;
82
+    ledc_conf2.duty = LEFTRIGHT_LEFT; //900; //3276; //1638; // to 3276  // 0 - 2088 (actually a bit less than that)
83
+    ledc_conf2.gpio_num = 15;
48 84
     ledc_conf2.intr_type = LEDC_INTR_DISABLE;
49 85
     ledc_conf2.speed_mode = LEDC_HIGH_SPEED_MODE;
50 86
     ledc_conf2.timer_sel = LEDC_TIMER_0;
51 87
     ledc_channel_config(&ledc_conf2);
52 88
 
53
-    //LEDC_CHANNEL_1
54 89
 
55 90
     /* Print chip information */
56 91
     esp_chip_info_t chip_info;
@@ -65,9 +100,11 @@ void app_main()
65 100
     printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
66 101
             (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
67 102
 
68
-    for (int i = 10; i >= 0; i--) {
103
+    for (int i = 0; i < 6; i++) {
69 104
         printf("Restarting in %d seconds...\n", i);
70 105
         vTaskDelay(1000 / portTICK_PERIOD_MS);
106
+        ledc_conf2.duty = LEFTRIGHT_LEFT - (i+1) * (LEFTRIGHT_LEFT - LEFTRIGHT_MIDDLE) / 6;
107
+        //ledc_channel_config(&ledc_conf2);
71 108
         //if(ledc_conf.duty > 1000) {
72 109
         //    ledc_conf.duty = 800;
73 110
         //} else {

+ 2
- 1
sdkconfig View File

@@ -20,7 +20,8 @@ CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
20 20
 CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG=
21 21
 CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE=
22 22
 CONFIG_LOG_BOOTLOADER_LEVEL=3
23
-CONFIG_BOOTLOADER_VDDSDIO_BOOST=y
23
+CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V=
24
+CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
24 25
 
25 26
 #
26 27
 # Security features

Loading…
Cancel
Save