Python步进电机最短路​​径

时间:2019-11-12 12:39:48

标签: python raspberry-pi

我正在尝试控制步进电机,并且试图找出如何计算使用最短方向从一个位置移动到另一个位置的最短方向。 enter image description here

我有一个功能,可以控制电机旋转的方向和坡度。 RotMotor(度数,速度)为正数,沿顺时针方向移动,而负数为逆时针方向。

我正在尝试创建一个以原始度和目标度为参数的函数(例如15到345)并返回-30

2 个答案:

答案 0 :(得分:0)

这应该很好

  

diff = lambda x,y : (y-x if x>y else x-y) if abs(x-y)<180 else (abs(x-y-360) if x>y else abs(x-y)-360)

示例-

  

print(diff(15,345))

     

>-30

简化版本-

def diff_fun(x,y): if abs(x-y) < 180: if x>y: return y-x else: return x-y else: if x>y: return abs(x-y-360) else: return abs(x-y)-360

  

print(diff_fun(30,15))

     

-15

abs用于查找绝对值

答案 1 :(得分:0)

最后,我用这个功能自己弄清楚了。我认为是正确的。

def calcPath(origin,destination):

/usr/local/bin/cmake -S/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters -B/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build/CMakeFiles /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build'
make -f CMakeFiles/helloEigen.dir/build.make CMakeFiles/helloEigen.dir/depend
make[2]: Entering directory '/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build'
cd /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build /home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build/CMakeFiles/helloEigen.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build'
make -f CMakeFiles/helloEigen.dir/build.make CMakeFiles/helloEigen.dir/build
make[2]: Entering directory '/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build'
[ 25%] Linking CXX executable helloEigen
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/helloEigen.dir/link.txt --verbose=1
/home/atmadeep/.conda/envs/AI/bin/x86_64-conda_cos6-linux-gnu-c++  -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe  -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections CMakeFiles/helloEigen.dir/helloEigen.cpp.o  -o helloEigen -leigen3/Eigen 
/home/atmadeep/.conda/envs/AI/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -leigen3/Eigen
collect2: error: ld returned 1 exit status
CMakeFiles/helloEigen.dir/build.make:83: recipe for target 'helloEigen' failed
make[2]: *** [helloEigen] Error 1
make[2]: Leaving directory '/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build'
CMakeFiles/Makefile2:77: recipe for target 'CMakeFiles/helloEigen.dir/all' failed
make[1]: *** [CMakeFiles/helloEigen.dir/all] Error 2
make[1]: Leaving directory '/home/atmadeep/Projects/Stereo_vision_based_navigation_for_quadcopters/build'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2