Browse Source

WIP: projection surface

master
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 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/ledc.h"

// some servo-specific constants, those also depend on the way the servos are attached to the horns
#define UPDOWN_STRAIGHT 2550
#define UPDOWN_DOWN 1280
#define LEFTRIGHT_LEFT 3200 // 3276
#define LEFTRIGHT_MIDDLE 1920
#define LEFTRIGHT_RIGHT 900

/*
* The position of the laser relative to the projection surface is such that the laser is centered horizontally,
* but sits on the top edge of the surface, so a LEFTRIGHT_MIDDLE and UPDOWN_STRAIGHT point is in the center of
* the top edge
* The values that follow here are the dimensions of the surface and the distance of the laser (same unit)
* such that the corresponding angles for the corners can easily be computed.
*/
// distance to the projection surface (all units are cm)
#define SCREEN_DISTANCE 100
#define SCREEN_WIDTH 100
#define SCREEN_HEIGHT 50

#define LEFTRIGHT_LEFT_ANGLE atan2(SCREEN_DISTANCE, SCREEN_WIDTH/2)
#define LEFTRIGHT_RIGHT_ANGLE (-LEFTRIGHT_LEFT_ANGLE)
#define UPDOWN_UP_ANGLE 0
#define UPDOWN_DOWN_ANGLE atan2(SCREEN_DISTANCE, SCREEN_HEIGHT)

void draw_line()
{
//atan2()
}

void app_main()
{
printf("Hello world!\n");
@@ -32,25 +62,30 @@ void app_main()
timer_conf.timer_num = LEDC_TIMER_0;
ledc_timer_config(&timer_conf);

// 2nd servo up/down
// 2550 - straight
// 1280 - down
ledc_channel_config_t ledc_conf;
ledc_conf.channel = LEDC_CHANNEL_0;
ledc_conf.duty = 3276; //900; //3276; //1638; // to 3276 // 0 - 2088 (actually a bit less than that)
ledc_conf.gpio_num = 15;
ledc_conf.duty = UPDOWN_STRAIGHT; //900; //3276; //1638; // to 3276 // 0 - 2088 (actually a bit less than that)
ledc_conf.gpio_num = 13;
ledc_conf.intr_type = LEDC_INTR_DISABLE;
ledc_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_conf.timer_sel = LEDC_TIMER_0;
ledc_channel_config(&ledc_conf);

// first servo connected to ground
// left-right
// 3276 - 2000 - 900
ledc_channel_config_t ledc_conf2;
ledc_conf2.channel = LEDC_CHANNEL_1;
ledc_conf2.duty = 3276; //900; //3276; //1638; // to 3276 // 0 - 2088 (actually a bit less than that)
ledc_conf2.gpio_num = 13;
ledc_conf2.duty = LEFTRIGHT_LEFT; //900; //3276; //1638; // to 3276 // 0 - 2088 (actually a bit less than that)
ledc_conf2.gpio_num = 15;
ledc_conf2.intr_type = LEDC_INTR_DISABLE;
ledc_conf2.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_conf2.timer_sel = LEDC_TIMER_0;
ledc_channel_config(&ledc_conf2);

//LEDC_CHANNEL_1

/* Print chip information */
esp_chip_info_t chip_info;
@@ -65,9 +100,11 @@ void app_main()
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

for (int i = 10; i >= 0; i--) {
for (int i = 0; i < 6; i++) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
ledc_conf2.duty = LEFTRIGHT_LEFT - (i+1) * (LEFTRIGHT_LEFT - LEFTRIGHT_MIDDLE) / 6;
//ledc_channel_config(&ledc_conf2);
//if(ledc_conf.duty > 1000) {
// ledc_conf.duty = 800;
//} else {

+ 2
- 1
sdkconfig View File

@@ -20,7 +20,8 @@ CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG=
CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE=
CONFIG_LOG_BOOTLOADER_LEVEL=3
CONFIG_BOOTLOADER_VDDSDIO_BOOST=y
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V=
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y

#
# Security features

Loading…
Cancel
Save