![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
XBusServoの設定を行うプログラムです。
main.cpp
- Committer:
- YusukeWakuta
- Date:
- 2017-01-11
- Revision:
- 2:32aba462e4df
- Parent:
- 0:301100d3469a
- Child:
- 3:db5a2f683282
File content as of revision 2:32aba462e4df:
#include "mbed.h" #include "XBusServo.h" #include <string> //#define DEBUGmain #ifdef DEBUGmain #define DBG(fmt) printf(fmt) #define DBGF(fmt, ...) printf(fmt, __VA_ARGS__) #else #define DBG(...) #define DBGF(...) #endif // // defines // #define kXBusTx p9 #define kMaxServoNum 1 // 1 - 50 #define kMaxServoPause (sizeof(motionData) / sizeof(pauseRec)) #define kMotionInterval 10 // flame / sec #define kMotionMinMark 0x1249 #define kMotionEndMark 0xED86 AnalogIn analog(p20); Serial pc(USBTX,USBRX); DigitalOut Led(LED1); // // typedefs // typedef enum poseDataType { dataType_Pose, numOfDataType } poseDataType; typedef struct poseRec { poseDataType poseType; uint16_t nextPoseIndex; int32_t servoPosition[kMaxServoNum]; uint16_t frameFromBeforePause; } poseRec; static const uint8_t servoChannel = 0x01; // // global vars // XBusServo gXBus(kXBusTx, NC, NC, kMaxServoNum); Ticker gTimer; //============================================================= // XbusIntervalHandler() // play motion ! //============================================================= void XbusIntervalHandler() { uint16_t value; uint16_t diff = kMotionEndMark - kMotionMinMark; value = (uint16_t)(diff * analog.read()) + kMotionMinMark; gXBus.setServo(servoChannel, value); gXBus.sendChannelDataPacket(); } //============================================================= // init() // initialize all setup //============================================================= XBusError init() { XBusError result; // initialize XBus result = gXBus.start(); if (result != kXBusError_NoError) { gXBus.stop(); return result; } // initialize XBus Servos result = gXBus.addServo(servoChannel, kXbusServoNeutral); if (result != kXBusError_NoError) { gXBus.stop(); return result; } int16_t index = 0x1D; int16_t value = 0x01; // int16_t Angle = 0x0011; result = gXBus.setCommand(kXBusOrder_1_Angle_180,&value); // result = gXBus.setCommand(kX); // result = gXBus.setCommand(kXBusOrder_2_ParamWrite,&index); return kXBusError_NoError; } //============================================================= // main() // //============================================================= int main() { if (init() != kXBusError_NoError) { return -1; Led = 1; wait(2); Led = 0; } // start motion gTimer.attach_us(&XbusIntervalHandler, 1000000 / kMotionInterval); while(1) { } }