|
| 1 | +/* |
| 2 | +回读所有舵机反馈参数:位置、速度、负载、电压、温度、移动状态、电流; |
| 3 | +FeedBack函数回读舵机参数于缓冲区,Readxxx(-1)函数返回缓冲区中相应的舵机状态; |
| 4 | +函数Readxxx(ID),ID=-1返回FeedBack缓冲区参数;ID>=0,通过读指令直接返回指定ID舵机状态, |
| 5 | +无需调用FeedBack函数。 |
| 6 | +*/ |
| 7 | + |
| 8 | +#include <SCServo.h> |
| 9 | + |
| 10 | +HLSCL hlscl; |
| 11 | +int LEDpin = 13; |
| 12 | + |
| 13 | +void setup() |
| 14 | +{ |
| 15 | + pinMode(LEDpin,OUTPUT); |
| 16 | + digitalWrite(LEDpin, HIGH); |
| 17 | + Serial1.begin(1000000);//mega2560 |
| 18 | + //Serial1.begin(1000000, SERIAL_8N1, 18, 17);//esp32-s32 |
| 19 | + Serial.begin(115200); |
| 20 | + hlscl.pSerial = &Serial1; |
| 21 | + delay(1000); |
| 22 | +} |
| 23 | + |
| 24 | +void loop() |
| 25 | +{ |
| 26 | + int Pos; |
| 27 | + int Speed; |
| 28 | + int Load; |
| 29 | + int Voltage; |
| 30 | + int Temper; |
| 31 | + int Move; |
| 32 | + int Current; |
| 33 | + hlscl.FeedBack(1); |
| 34 | + if(!hlscl.getLastError()){ |
| 35 | + digitalWrite(LEDpin, LOW); |
| 36 | + Pos = hlscl.ReadPos(-1); |
| 37 | + Speed = hlscl.ReadSpeed(-1); |
| 38 | + Load = hlscl.ReadLoad(-1); |
| 39 | + Voltage = hlscl.ReadVoltage(-1); |
| 40 | + Temper = hlscl.ReadTemper(-1); |
| 41 | + Move = hlscl.ReadMove(-1); |
| 42 | + Current = hlscl.ReadCurrent(-1); |
| 43 | + Serial.print("Position:"); |
| 44 | + Serial.println(Pos); |
| 45 | + Serial.print("Speed:"); |
| 46 | + Serial.println(Speed); |
| 47 | + Serial.print("Load:"); |
| 48 | + Serial.println(Load); |
| 49 | + Serial.print("Voltage:"); |
| 50 | + Serial.println(Voltage); |
| 51 | + Serial.print("Temper:"); |
| 52 | + Serial.println(Temper); |
| 53 | + Serial.print("Move:"); |
| 54 | + Serial.println(Move); |
| 55 | + Serial.print("Current:"); |
| 56 | + Serial.println(Current); |
| 57 | + delay(10); |
| 58 | + }else{ |
| 59 | + digitalWrite(LEDpin, HIGH); |
| 60 | + Serial.println("FeedBack err"); |
| 61 | + delay(500); |
| 62 | + } |
| 63 | + |
| 64 | + Pos = hlscl.ReadPos(1); |
| 65 | + if(!hlscl.getLastError()){ |
| 66 | + digitalWrite(LEDpin, LOW); |
| 67 | + Serial.print("Servo position:"); |
| 68 | + Serial.println(Pos, DEC); |
| 69 | + delay(10); |
| 70 | + }else{ |
| 71 | + Serial.println("read position err"); |
| 72 | + digitalWrite(LEDpin, HIGH); |
| 73 | + delay(500); |
| 74 | + } |
| 75 | + |
| 76 | + Voltage = hlscl.ReadVoltage(1); |
| 77 | + if(!hlscl.getLastError()){ |
| 78 | + digitalWrite(LEDpin, LOW); |
| 79 | + Serial.print("Servo Voltage:"); |
| 80 | + Serial.println(Voltage, DEC); |
| 81 | + delay(10); |
| 82 | + }else{ |
| 83 | + Serial.println("read Voltage err"); |
| 84 | + digitalWrite(LEDpin, HIGH); |
| 85 | + delay(500); |
| 86 | + } |
| 87 | + |
| 88 | + Temper = hlscl.ReadTemper(1); |
| 89 | + if(!hlscl.getLastError()){ |
| 90 | + digitalWrite(LEDpin, LOW); |
| 91 | + Serial.print("Servo temperature:"); |
| 92 | + Serial.println(Temper, DEC); |
| 93 | + delay(10); |
| 94 | + }else{ |
| 95 | + Serial.println("read temperature err"); |
| 96 | + digitalWrite(LEDpin, HIGH); |
| 97 | + delay(500); |
| 98 | + } |
| 99 | + |
| 100 | + Speed = hlscl.ReadSpeed(1); |
| 101 | + if(!hlscl.getLastError()){ |
| 102 | + digitalWrite(LEDpin, LOW); |
| 103 | + Serial.print("Servo Speed:"); |
| 104 | + Serial.println(Speed, DEC); |
| 105 | + delay(10); |
| 106 | + }else{ |
| 107 | + Serial.println("read Speed err"); |
| 108 | + digitalWrite(LEDpin, HIGH); |
| 109 | + delay(500); |
| 110 | + } |
| 111 | + |
| 112 | + Load = hlscl.ReadLoad(1); |
| 113 | + if(!hlscl.getLastError()){ |
| 114 | + digitalWrite(LEDpin, LOW); |
| 115 | + Serial.print("Servo Load:"); |
| 116 | + Serial.println(Load, DEC); |
| 117 | + delay(10); |
| 118 | + }else{ |
| 119 | + Serial.println("read Load err"); |
| 120 | + digitalWrite(LEDpin, HIGH); |
| 121 | + delay(500); |
| 122 | + } |
| 123 | + |
| 124 | + Current = hlscl.ReadCurrent(1); |
| 125 | + if(!hlscl.getLastError()){ |
| 126 | + digitalWrite(LEDpin, LOW); |
| 127 | + Serial.print("Servo Current:"); |
| 128 | + Serial.println(Current, DEC); |
| 129 | + delay(10); |
| 130 | + }else{ |
| 131 | + Serial.println("read Current err"); |
| 132 | + digitalWrite(LEDpin, HIGH); |
| 133 | + delay(500); |
| 134 | + } |
| 135 | + |
| 136 | + Move = hlscl.ReadMove(1); |
| 137 | + if(!hlscl.getLastError()){ |
| 138 | + digitalWrite(LEDpin, LOW); |
| 139 | + Serial.print("Servo Move:"); |
| 140 | + Serial.println(Move, DEC); |
| 141 | + delay(10); |
| 142 | + }else{ |
| 143 | + Serial.println("read Move err"); |
| 144 | + digitalWrite(LEDpin, HIGH); |
| 145 | + delay(500); |
| 146 | + } |
| 147 | + Serial.println(); |
| 148 | +} |
0 commit comments