极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 33783|回复: 2

求助:编程报错invalid operands of types 'float' and 'int' to binary 'operator^'

[复制链接]
发表于 2015-7-8 10:15:46 | 显示全部楼层 |阅读模式
本帖最后由 凯风自北来 于 2015-7-8 10:17 编辑

之前编程的时候几个量都是整型的,后来为精确起见改成浮点型,但是就报错了,请大神帮忙看下问题在哪里
arduino IDE提示
_1.ino: In function 'void setup()':
_1:18: error: invalid operands of types 'float' and 'int' to binary 'operator^'
_1:20: error: invalid operands of types 'float' and 'int' to binary 'operator^'
invalid operands of types 'float' and 'int' to binary 'operator^'

  1. #include <AccelStepper.h>
  2. AccelStepper stepper1(1, 9, 8);
  3. AccelStepper stepper2(1, 7, 6);
  4. float  flowrate1=17;            
  5. float  diameter1=8.24;            
  6. int  pitch1=1;                  
  7. float area1;                       
  8. float velocity1;   
  9. float  flowrate2=17;              
  10. float diameter2=8.24;            
  11. int  pitch2=1;                  
  12. float area2;                     
  13. float velocity2;
  14. int pos1 = 3600;
  15. int pos2 = 5678;
  16. void setup()
  17. {  
  18.    area1=3.14*((diameter1/2)^2);   
  19.    velocity1=(flowrate1/area1)*80/3;
  20.     area2=3.14*((diameter2/2)^2);   
  21.    velocity2=(flowrate2/area2)*80/3;
  22.    stepper1.setMaxSpeed(velocity1);
  23.    stepper1.setAcceleration(1000);
  24.    stepper2.setMaxSpeed(velocity2);
  25.    stepper2.setAcceleration(1000);}
  26. void loop()
  27. {
  28.    if (stepper1.distanceToGo() == 0)
  29.    {
  30.      pos1 = -pos1;
  31.      stepper1.moveTo(pos1);
  32.    }
  33.    if (stepper2.distanceToGo() == 0)
  34.    {   
  35.      pos2 = -pos2;
  36.      stepper2.moveTo(pos2);
  37.    }
  38.     stepper1.run();
  39.   stepper2.run();
  40. }
  41.    
复制代码
回复

使用道具 举报

发表于 2015-7-8 13:02:52 | 显示全部楼层
int 跟 float不支持"^" 運算
換成下面方式試試:
#include <math.h>
...
area1=3.14*(pow((diameter1/2), 2));
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-7-8 15:19:04 | 显示全部楼层
alai2015 发表于 2015-7-8 13:02
int 跟 float不支持"^" 運算
換成下面方式試試:
#include

多谢,问题已解决
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 03:02 , Processed in 0.040814 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表