Arduino编码

未找到结果
监控线性执行器的电流
<

此示例代码使用Megamoto PlusArduino Uno.监控线性执行器的电流。

/ *代码监控执行器的当前放大器绘制,如果它上升到一定数量超过一定量,则缩小电源。逐步自动化撰写2015必威betway网页版年8月19日硬件: -  RobotPower Megamoto控制板 -  Arduino Uno  -  2按钮* / Const Int enablePin = 8;Const int pwmpina = 11;const int pwmpinb = 3;// Megamoto const int buttonleft = 4;Const int ButtonRight = 5; //按钮移动电机Const CPIn1 = A5;//电机反馈int Leftlatch =低;intratileLatch = low; //电机锁存器(用于代码逻辑)int hitlimits = 0; //从0 int hitlimitsmax = 10开始; //要知道旅行限制是否达到Lend LastFeedBackTime = 0;//必须长,否则它溢出int firstfedbacktimedelay = 750;//首先延迟忽略当前峰值int反馈timedelay = 50; //delay between feedback cycles, how often you want the motor to be checked long currentTimefeedback = 0; // must be long, else it overflows int debounceTime = 300; //amount to debounce buttons, lower values makes the buttons more sensitive long lastButtonpress = 0; // timer for debouncing long currentTimedebounce = 0; int CRaw = 0; // input value for current readings int maxAmps = 0; // trip limit bool dontExtend = false; bool firstRun = true; bool fullyRetracted = false;//program logic void setup() { Serial.begin(9600); pinMode(EnablePin, OUTPUT); pinMode(PWMPinA, OUTPUT); pinMode(PWMPinB, OUTPUT);//Set motor outputs pinMode(buttonLeft, INPUT); pinMode(buttonRight, INPUT);//buttons digitalWrite(buttonLeft, HIGH); digitalWrite(buttonRight, HIGH);//enable internal pullups pinMode(CPin1, INPUT);//set feedback input currentTimedebounce = millis(); currentTimefeedback = 0;//Set initial times maxAmps = 15;// SET MAX CURRENT HERE }//end setup void loop() { latchButtons();//check buttons, see if we need to move moveMotor();//check latches, move motor in or out }//end main loop void latchButtons() { if (digitalRead(buttonLeft)==LOW)//left is forwards { currentTimedebounce = millis() - lastButtonpress;// check time since last press if (currentTimedebounce > debounceTime && dontExtend == false)//once you've tripped dontExtend, ignore all forwards presses { leftlatch = !leftlatch;// if motor is moving, stop, if stopped, start moving firstRun = true;// set firstRun flag to ignore current spike fullyRetracted = false; // once you move forwards, you are not fully retracted lastButtonpress = millis();//store time of last button press return; }//end if }//end btnLEFT if (digitalRead(buttonRight)==LOW)//right is backwards { currentTimedebounce = millis() - lastButtonpress;// check time since last press if (currentTimedebounce > debounceTime) { rightlatch = !rightlatch;// if motor is moving, stop, if stopped, start moving firstRun = true;// set firstRun flag to ignore current spike lastButtonpress = millis();//store time of last button press return; }//end if }//end btnRIGHT }//end latchButtons void moveMotor() { if (leftlatch == HIGH) motorForward(255); //speed = 0-255 if (leftlatch == LOW) motorStop(); if (rightlatch == HIGH) motorBack(255); //speed = 0-255 if (rightlatch == LOW) motorStop(); }//end moveMotor void motorForward(int speeed) { while (dontExtend == false && leftlatch == HIGH) { digitalWrite(EnablePin, HIGH); analogWrite(PWMPinA, speeed); analogWrite(PWMPinB, 0);//move motor if (firstRun == true) delay(firstfeedbacktimedelay); // bigger delay to ignore current spike else delay(feedbacktimedelay); //small delay to get to speed getFeedback(); firstRun = false; latchButtons();//check buttons again }//end while }//end motorForward void motorBack (int speeed) { while (rightlatch == HIGH) { digitalWrite(EnablePin, HIGH); analogWrite(PWMPinA, 0); analogWrite(PWMPinB, speeed);//move motor if (firstRun == true) delay(firstfeedbacktimedelay);// bigger delay to ignore current spike else delay(feedbacktimedelay); //small delay to get to speed getFeedback(); firstRun = false; latchButtons();//check buttons again }//end while dontExtend = false;//allow motor to extend again, after it has been retracted }//end motorBack void motorStop() { analogWrite(PWMPinA, 0); analogWrite(PWMPinB, 0); digitalWrite(EnablePin, LOW); firstRun = true;//once the motor has stopped, reenable firstRun to account for startup current spikes }//end stopMotor void getFeedback() { CRaw = analogRead(CPin1); // Read current if (CRaw == 0 && hitLimits < hitLimitsmax) hitLimits = hitLimits + 1; else hitLimits = 0; // check to see if the motor is at the limits and the current has stopped if (hitLimits == hitLimitsmax && rightlatch == HIGH) { rightlatch = LOW; // stop motor fullyRetracted = true; }//end if else if (hitLimits == hitLimitsmax && leftlatch == HIGH) { leftlatch = LOW;//stop motor hitLimits = 0; }//end if if (CRaw > maxAmps) { dontExtend = true; leftlatch = LOW; //stop if feedback is over maximum }//end if lastfeedbacktime = millis();//store previous time for receiving feedback }//end getFeedback
用多电动机arduino屏蔽控制多个执行器
<

此示例代码显示了如何控制多达4个线性执行器betway亚洲登陆LC-82 Multimoto Arduino ShieldLC-066.。由于多MultMoto的每个通道上的当前限制,此代码仅适用于我们的PA-14.PA-14P., 和PA-11.执行器模型。

/ *使用机器人电源多电源驱动程序来控制最多4个执行器的示例代码。硬件: - 机器人电源多电机 -  Arduino Uno接线: - 将执行器连接到Multmoto板上的M1,M2,M3,M4连接。- 将负(黑色)连接到右连接,向左向右侧(红色)。- 连接12伏源(如果卸载,每电动机8A,如果完全装入)到蝙蝠端子,则连接12伏源。确保将正面和负面放置在正确的斑点中。由渐进式自动化从机器人电源提供的示必威betway网页版例代码修改的代码 http://www.robotpower.com/downloads/ 机器人电源multimoto v1.0演示该软件将发布到公共域* ///包括SPI库:#include  // l9958从属SPI #define SS_M4 14 #define SS_M3 13#define ss_m2 12 #define ss_m1 11 // l9958方向销#define dir_m1 2 #define dir_m2 3 #define dir_m3 4 #define dir_m4 7 // l9958 pwm pins #define pwm_m1 9 #define pwm_m2 10 // timer1 #define pwm_m3 5#定义PWM_M4 6 // TIMER0 // L9958为所有4电机启用#define Enable_Motors 8 int PWM1,PWM2,PWM3,PWM4;布尔DIR1,DIR2,DIR3,DIR4;void setup(){unsigned int configword; // put your setup code here, to run once: pinMode(SS_M1, OUTPUT); digitalWrite(SS_M1, LOW); // HIGH = not selected pinMode(SS_M2, OUTPUT); digitalWrite(SS_M2, LOW); pinMode(SS_M3, OUTPUT); digitalWrite(SS_M3, LOW); pinMode(SS_M4, OUTPUT); digitalWrite(SS_M4, LOW); // L9958 DIRection pins pinMode(DIR_M1, OUTPUT); pinMode(DIR_M2, OUTPUT); pinMode(DIR_M3, OUTPUT); pinMode(DIR_M4, OUTPUT); // L9958 PWM pins pinMode(PWM_M1, OUTPUT); digitalWrite(PWM_M1, LOW); pinMode(PWM_M2, OUTPUT); digitalWrite(PWM_M2, LOW); // Timer1 pinMode(PWM_M3, OUTPUT); digitalWrite(PWM_M3, LOW); pinMode(PWM_M4, OUTPUT); digitalWrite(PWM_M4, LOW); // Timer0 // L9958 Enable for all 4 motors pinMode(ENABLE_MOTORS, OUTPUT); digitalWrite(ENABLE_MOTORS, HIGH); // HIGH = disabled / /******* Set up L9958 chips ********* ' L9958 Config Register ' Bit '0 - RES '1 - DR - reset '2 - CL_1 - curr limit '3 - CL_2 - curr_limit '4 - RES '5 - RES '6 - RES '7 - RES '8 - VSR - voltage slew rate (1 enables slew limit, 0 disables) '9 - ISR - current slew rate (1 enables slew limit, 0 disables) '10 - ISR_DIS - current slew disable '11 - OL_ON - open load enable '12 - RES '13 - RES '14 - 0 - always zero '15 - 0 - always zero */ // set to max current limit and disable ISR slew limiting configWord = 0b0000010000001100; SPI.begin(); SPI.setBitOrder(LSBFIRST); SPI.setDataMode(SPI_MODE1); // clock pol = low, phase = high // Motor 1 digitalWrite(SS_M1, LOW); SPI.transfer(lowByte(configWord)); SPI.transfer(highByte(configWord)); digitalWrite(SS_M1, HIGH); // Motor 2 digitalWrite(SS_M2, LOW); SPI.transfer(lowByte(configWord)); SPI.transfer(highByte(configWord)); digitalWrite(SS_M2, HIGH); // Motor 3 digitalWrite(SS_M3, LOW); SPI.transfer(lowByte(configWord)); SPI.transfer(highByte(configWord)); digitalWrite(SS_M3, HIGH); // Motor 4 digitalWrite(SS_M4, LOW); SPI.transfer(lowByte(configWord)); SPI.transfer(highByte(configWord)); digitalWrite(SS_M4, HIGH); //Set initial actuator settings to pull at 0 speed for safety dir1 = 0; dir2 = 0; dir3 = 0; dir4 = 0; // Set direction pwm1 = 0; pwm2 = 0; pwm3 = 0; pwm4 = 0; // Set speed (0-255) digitalWrite(ENABLE_MOTORS, LOW);// LOW = enabled } // End setup void loop() { dir1 = 1; pwm1 = 255; //set direction and speed digitalWrite(DIR_M1, dir1); analogWrite(PWM_M1, pwm1); // write to pins dir2 = 0; pwm2 = 128; digitalWrite(DIR_M2, dir2); analogWrite(PWM_M2, pwm2); dir3 = 1; pwm3 = 255; digitalWrite(DIR_M3, dir3); analogWrite(PWM_M3, pwm3); dir4 = 0; pwm4 = 128; digitalWrite(DIR_M4, dir4); analogWrite(PWM_M4, pwm4); delay(5000); // wait once all four motors are set dir1 = 0; pwm1 = 128; digitalWrite(DIR_M1, dir1); analogWrite(PWM_M1, pwm1); dir2 = 1; pwm2 = 255; digitalWrite(DIR_M2, dir2); analogWrite(PWM_M2, pwm2); dir3 = 0; pwm3 = 128; digitalWrite(DIR_M3, dir3); analogWrite(PWM_M3, pwm3); dir4 = 1; pwm4 = 255; digitalWrite(DIR_M4, dir4); analogWrite(PWM_M4, pwm4); delay(5000); }//end void loop
用于线性执行器控制的WASP电机控制器
<

此示例代码用于组合我们的LC-85 WASP跟我们LC-066.控制一个动作线性执行器

/ *机器人电源WASP的示例代码。该ESC使用RC信号控制,脉冲范围为1000-2000微秒。该程序的主循环保持静止器仍为1秒,延伸2秒,停止1秒,缩回2秒,并重复。由渐进式自动化修改,使用必威betway网页版来自Arduino示例库的原始示例代码“扫描”。硬件: -  1 WASP控制器 -  Arduino Uno接线:控制侧: - 将红色/黑到+ 5V和GND连接 - 将黄色电线连接到Arduino(在此示例中,引脚9)电源侧: -  Connect电机电源到WASP上的+/-连接 - 将执行器的+/-连接到剩余的两个连接,此示例代码位于公共领域。* / #include  servo myservo;//创建伺服对象来控制伺服电脑// 12个伺服对象可以在大多数板INT POS = 0上创建;//变量存储伺服位置void setup(){myservo.attach(9);//将PIN 9上的伺服连接到伺服对象} void循环(){myservo.writemicroseconds(1500); // stop signal delay(1000); //1 second myservo.writeMicroseconds(2000); // full speed forwards signal delay(2000); //2 seconds myservo.writeMicroseconds(1500); // stop signal delay(1000); // 1 second myservo.writeMicroseconds(1000); // full speed reverse signal delay(2000); //2 seconds }
使用继电器控制线性执行器betway亚洲登陆
<

此示例代码利用我们的中继和我们的LC-066.控制线性执行器。你可以读完我们的完整博客文章有关更多详细信息。

Const Int Forwards = 7;Const Int向后= 6; //将中继Inx引脚分配给Arduino引脚void Setup(){Pinmode(转发,输出); //将继电器设置为输出Pinmode(向后,输出); //将继电器设置为输出} void循环(){DigitalWrite(转发,低);DigitalWrite(向后,高); //激活继电器一个方向,它们必须不同,以移动电机延迟(2000);//等待2秒DigitalWrite(转发,高);DigitalWrite(向后,高); //停用继电器以制动电机延迟(2000); //等待2秒DigiteWrite(前进,高);DigitalWrite(向后,低); //激活继电器另一个方向,它们必须不同地移动电机延迟(2000); //等待2秒DigiteWrite(前进,高);DigitalWrite(向后,高); //停用继电器以制动电机延迟(2000); //等待2秒}
控制单个线性执行器运动的定时betway亚洲登陆
<

此示例代码使用我们的LC-80LC-066., 任何线性执行器和电源。您可以在代码上获得更多详细信息以及它在我们的代码中的内容博客文章

//使用电路板上的跳线来选择哪些引脚将使用int enablepin1 = 13;int pwmpina1 = 11;int pwmpinb1 = 3;int stemittime = 10 * 1000;// 10秒,次数1000转换为毫秒intretrattime = 10 * 1000;// 10秒,时间1000转换为毫秒int timetorun = 300 * 1000;// 300秒,次数1000转换为毫秒int;int elapsedtime;布尔守门器;void setup(){serial.begin(9600); pinMode(EnablePin1, OUTPUT);//Enable the board pinMode(PWMPinA1, OUTPUT); pinMode(PWMPinB1, OUTPUT);//Set motor outputs elapsedTime = 0; // Set time to 0 keepMoving = true; //The system will move }//end setup void loop() { if (keepMoving) { digitalWrite(EnablePin1, HIGH); // enable the motor pushActuator(); delay(extendtime); stopActuator(); delay(10);//small delay before retracting pullActuator(); delay(retracttime); stopActuator(); elapsedTime = millis();//how long has it been? if (elapsedTime > timetorun) {//if it's been 300 seconds, stop Serial.print("Elapsed time is over max run time. Max run time: "); Serial.println(timetorun); keepMoving = false; } }//end if }//end main loop void stopActuator() { analogWrite(PWMPinA1, 0); analogWrite(PWMPinB1, 0); // speed 0-255 } void pushActuator() { analogWrite(PWMPinA1, 255); analogWrite(PWMPinB1, 0); // speed 0-255 } void pullActuator() { analogWrite(PWMPinA1, 0); analogWrite(PWMPinB1, 255);//speed 0-255 }
用无刷直流电动机连续延伸和缩回线性执行器
<

该程序可用于连续延伸和缩回线性执行器的行程。

设置循环代码void setup(){serial.begin(9600);//初始化每秒9600位的串行通信Pinmode(Out_lim,Input_Pullup);//将引脚45配置为输入引脚PINMODE(IN_LIM,INPUT_PULLUP);//将引脚53配置为输入引脚Pinmode(Run_F,输出);//将引脚25配置为输出引脚PINMODE(RUN_R,输出);//将引脚30配置为输出引脚RETRACT();//在启动延迟时缩回笔划(500);void extend()//此功能使电机运行{digitwwrite(run_f,low);DigitalWrite(Run_R,高);void Retract()//此功能反转电机的方向{digitalwrite(run_f,low); digitalWrite(run_r, LOW); } void run_stop() // this function disables the motor { digitalWrite(run_f, HIGH); digitalWrite(run_r, HIGH); } void loop() { int out_lim_state = digitalRead(out_lim); // reads the limit switches and saves its value int in_lim_state = digitalRead(in_lim); Serial.print("outer limit switch value "), Serial.println(out_lim_state); // 0 -> limit switch is pressed Serial.print("inner limit switch value "), Serial.println(in_lim_state); // 1 -> limit switch is not pressed if (out_lim_state == 0 && in_lim_state == 1) // if outer limit switch is pressed and inner is not (extended all the way) { retract(); // retract the stroke } else if (out_lim_state == 1 && in_lim_state == 0) // if inner limit switch is pressed and outer is not (reracted all the way) { extend(); // extend the stroke } else // otherwise do nothing { } delay(5); // delay in between reads for stability }
PA-12微伺服执行器样品码
<
单击链接获取集合 示例代码 对于我们的PA-12微伺服执行器。
服务顶级品牌
苹果
谷歌
特斯拉
梅赛德斯
GE.
GM.
生命值
霍尼韦尔
英特尔
美国宇航局
Schnieder Electric.
三角洲
Cirque du Soleil.
麻省理工学院
波音

请稍等...

......