diff --git a/depthrushConfig/calibration.cpp b/depthrushConfig/calibration.cpp index cc98065..c2fa0ef 100644 --- a/depthrushConfig/calibration.cpp +++ b/depthrushConfig/calibration.cpp @@ -1,6 +1,7 @@ #include "includes.h" Vector4 leftLegPos = { 1.5F, 1.5F, 1.5F, 1.5F }; Vector4 rightLegPos = { 1.5F, 1.5F, 1.5F, 1.5F }; +bool kinectScanning = true; int calibration() { @@ -55,6 +56,18 @@ int calibration() { //Y calibration float yGrad = (yMax - yMin) / (zMax - zMin); float yOffset = (yMin - yGrad * zMin); + + + // Clean up and proceed to kinect test + kinectScanning = false; + std::cout << std::to_string(xGrad) << " "; + std::cout << std::to_string(xOffset) << " "; + std::cout << std::to_string(yGrad) << " "; + std::cout << std::to_string(yOffset) << " "; + std::cout << std::to_string(zGrad) << " "; + std::cout << std::to_string(zOffset) << "\n"; + std::cout << "Proceeding to Kinect Preview..\n"; + kinectTest(xGrad, xOffset, yGrad, yOffset, zGrad, zOffset); }); @@ -62,7 +75,7 @@ int calibration() { // main loop to read and process skeleton data NUI_SKELETON_FRAME skeletonFrame = { 0 }; - while (true) { + while (kinectScanning) { // get the latest skeleton frame hr = NuiSkeletonGetNextFrame(0, &skeletonFrame); if (FAILED(hr)) { @@ -82,5 +95,6 @@ int calibration() { // Clean up and exit NuiSkeletonTrackingDisable(); NuiShutdown(); + std::this_thread::sleep_for(std::chrono::hours(1000)); return 0; } \ No newline at end of file diff --git a/depthrushConfig/depthrushConfig.cpp b/depthrushConfig/depthrushConfig.cpp index d61cd54..917944f 100644 --- a/depthrushConfig/depthrushConfig.cpp +++ b/depthrushConfig/depthrushConfig.cpp @@ -13,7 +13,7 @@ int main() return 0; } else if (choice == 2) { - std::cout << "okay 2"; + kinectTest(1, 1, 1, 1, 1, 1); return 0; } else { diff --git a/depthrushConfig/depthrushConfig.vcxproj b/depthrushConfig/depthrushConfig.vcxproj index bca088f..ecb007a 100644 --- a/depthrushConfig/depthrushConfig.vcxproj +++ b/depthrushConfig/depthrushConfig.vcxproj @@ -134,10 +134,12 @@ + + diff --git a/depthrushConfig/depthrushConfig.vcxproj.filters b/depthrushConfig/depthrushConfig.vcxproj.filters index 6a20e07..917980d 100644 --- a/depthrushConfig/depthrushConfig.vcxproj.filters +++ b/depthrushConfig/depthrushConfig.vcxproj.filters @@ -21,6 +21,9 @@ Source Files + + Source Files + @@ -29,5 +32,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/depthrushConfig/depthrushConfig.vcxproj.user b/depthrushConfig/depthrushConfig.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/depthrushConfig/depthrushConfig.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/depthrushConfig/includes.h b/depthrushConfig/includes.h index 7b5daaf..a699c4d 100644 --- a/depthrushConfig/includes.h +++ b/depthrushConfig/includes.h @@ -4,4 +4,7 @@ #include #include #include -#include "calibration.h" \ No newline at end of file +#include "calibration.h" +#include "kinectTest.h" + + diff --git a/depthrushConfig/kinectTest.cpp b/depthrushConfig/kinectTest.cpp new file mode 100644 index 0000000..223d984 --- /dev/null +++ b/depthrushConfig/kinectTest.cpp @@ -0,0 +1,111 @@ +#include "includes.h" +Vector4 leftLegPosPreview = { 1.5F, 1.5F, 1.5F, 1.5F }; +Vector4 rightLegPosPreview = { 1.5F, 1.5F, 1.5F, 1.5F }; + +int kinectTest(float xGrad, float xOffset, float yGrad, float yOffset, float zGrad, float zOffset) { + //std::cout << "Kinect Preview\n"; + //std::cin >> xGrad; + //std::cin >> xOffset; + // Wait 10 secs for kinect shutdown + // Sleep(10000); + // initialize Kinect + HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON); + if (FAILED(hr)) { + std::cout << "Failed to initialize Kinect." << std::endl; + return 1; + } + + // open the skeleton stream + HANDLE skeletonStream = nullptr; + hr = NuiSkeletonTrackingEnable(nullptr, 0); + if (FAILED(hr)) { + std::cout << "Failed to open the skeleton stream." << std::endl; + NuiShutdown(); + return 1; + } + + // main loop to read and process skeleton data + NUI_SKELETON_FRAME skeletonFrame = { 0 }; + CONSOLE_SCREEN_BUFFER_INFO csbi; + int width = 0; + float drsLeft = 0; + float drsRight = 0; + int toolLeft = 0; + int toolRight = 0; + int toolWidth = 0; + bool leftTouch = false; + bool rightTouch = false; + + while (true) { + // get the latest skeleton frame + hr = NuiSkeletonGetNextFrame(0, &skeletonFrame); + if (FAILED(hr)) { + continue; + } + + // Process each tracked skeleton + for (int i = 0; i < NUI_SKELETON_COUNT; ++i) { + if (skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED) { + // get the position of both legs + leftLegPosPreview = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_LEFT]; + rightLegPosPreview = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_RIGHT]; + } + } + + // keep updating screen width for fancy + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); + width = (int)(csbi.srWindow.Right - csbi.srWindow.Left + 1); + + // fetch calibrated feet + drsLeft = xGrad * leftLegPosPreview.x + xOffset; + drsRight = xGrad * rightLegPosPreview.x + xOffset; + + // translate to console window width + toolLeft = width * drsLeft; + toolRight = width * drsRight; + toolWidth = width * 0.05; + + // foot lifting detection + // see how far foot currently is from known ground value + float fixedLeft = leftLegPosPreview.y - (yGrad * leftLegPosPreview.z + yOffset); + float fixedRight = rightLegPosPreview.y - (yGrad * rightLegPosPreview.z + yOffset); + + // check for stepping + float errorMargin = 0.05; + if (fixedLeft > (fixedRight + errorMargin)) { + rightTouch = true; + leftTouch = false; + // std::cout << "right step\n"; + } + else if (fixedLeft > (fixedRight + errorMargin)) { + leftTouch = true; + rightTouch = false; + // std::cout << "left step \n"; + } + else { + leftTouch = true; + rightTouch = true; + // std::cout << "both step\n"; + } + /* + // print feet + for (int i = 0; i < width; i++) { + if ((i <= (toolLeft + toolWidth)) && (i >= (toolLeft - toolWidth)) && leftTouch) { + std::cout << "L"; + } + else if ((i <= (toolRight + toolWidth)) && (i >= (toolRight - toolWidth)) && rightTouch) { + std::cout << "R"; + } + else { + std::cout << " "; + } + } + */ + std::cout << std::to_string(fixedLeft) << " " << std::to_string(fixedRight) << std::endl; + } + + // Clean up and exit + NuiSkeletonTrackingDisable(); + NuiShutdown(); + return 0; +} \ No newline at end of file diff --git a/depthrushConfig/kinectTest.h b/depthrushConfig/kinectTest.h new file mode 100644 index 0000000..22da6ab --- /dev/null +++ b/depthrushConfig/kinectTest.h @@ -0,0 +1,2 @@ +#pragma once +int kinectTest(float xGrad, float xOffset, float yGrad, float yOffset, float zGrad, float zOffset); \ No newline at end of file