shiyuu oguro
/
Daisen0
コントロールの前段階。姿勢制御の実験中。
Fork of rcj2015_CatPot_MotorTest by
wordString.cpp@0:617b63d4a532, 2016-02-27 (annotated)
- Committer:
- ryuna
- Date:
- Sat Feb 27 06:01:52 2016 +0000
- Revision:
- 0:617b63d4a532
???????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryuna | 0:617b63d4a532 | 1 | |
ryuna | 0:617b63d4a532 | 2 | #include <sstream> |
ryuna | 0:617b63d4a532 | 3 | #include "mbed.h" |
ryuna | 0:617b63d4a532 | 4 | |
ryuna | 0:617b63d4a532 | 5 | string StringFIN; |
ryuna | 0:617b63d4a532 | 6 | |
ryuna | 0:617b63d4a532 | 7 | using namespace std; |
ryuna | 0:617b63d4a532 | 8 | |
ryuna | 0:617b63d4a532 | 9 | |
ryuna | 0:617b63d4a532 | 10 | //extern Serial pc; // tx, rx |
ryuna | 0:617b63d4a532 | 11 | |
ryuna | 0:617b63d4a532 | 12 | string IntToString(int number) |
ryuna | 0:617b63d4a532 | 13 | { |
ryuna | 0:617b63d4a532 | 14 | stringstream ss; |
ryuna | 0:617b63d4a532 | 15 | ss << number; |
ryuna | 0:617b63d4a532 | 16 | return ss.str(); |
ryuna | 0:617b63d4a532 | 17 | } |
ryuna | 0:617b63d4a532 | 18 | |
ryuna | 0:617b63d4a532 | 19 | void array(int power1,int power2,int power3,int power4) |
ryuna | 0:617b63d4a532 | 20 | { |
ryuna | 0:617b63d4a532 | 21 | int input[4] = {power1,power2,power3,power4}; |
ryuna | 0:617b63d4a532 | 22 | int value = 0; |
ryuna | 0:617b63d4a532 | 23 | string StringA[4] = {"0","0","0","0"}; |
ryuna | 0:617b63d4a532 | 24 | |
ryuna | 0:617b63d4a532 | 25 | |
ryuna | 0:617b63d4a532 | 26 | string StringX = "0"; |
ryuna | 0:617b63d4a532 | 27 | string StringY = "0"; |
ryuna | 0:617b63d4a532 | 28 | string StringZ = "0"; |
ryuna | 0:617b63d4a532 | 29 | string String0 = "0"; |
ryuna | 0:617b63d4a532 | 30 | |
ryuna | 0:617b63d4a532 | 31 | StringFIN = "0"; |
ryuna | 0:617b63d4a532 | 32 | |
ryuna | 0:617b63d4a532 | 33 | for(uint8_t i = 0 ; i < 4; i++){ |
ryuna | 0:617b63d4a532 | 34 | |
ryuna | 0:617b63d4a532 | 35 | value = input[i]; |
ryuna | 0:617b63d4a532 | 36 | |
ryuna | 0:617b63d4a532 | 37 | StringX = IntToString(i+1); |
ryuna | 0:617b63d4a532 | 38 | |
ryuna | 0:617b63d4a532 | 39 | if( (value < 0) && (value >= -100) ){ |
ryuna | 0:617b63d4a532 | 40 | StringY = "R"; |
ryuna | 0:617b63d4a532 | 41 | value = abs(value); |
ryuna | 0:617b63d4a532 | 42 | StringZ = IntToString(value); |
ryuna | 0:617b63d4a532 | 43 | }else if( (value >= 0) && (value <= 100) ){ |
ryuna | 0:617b63d4a532 | 44 | StringY = "F"; |
ryuna | 0:617b63d4a532 | 45 | StringZ = IntToString(value); |
ryuna | 0:617b63d4a532 | 46 | }else{ |
ryuna | 0:617b63d4a532 | 47 | value = abs(value); |
ryuna | 0:617b63d4a532 | 48 | StringY = "F"; |
ryuna | 0:617b63d4a532 | 49 | StringZ = "000"; |
ryuna | 0:617b63d4a532 | 50 | } |
ryuna | 0:617b63d4a532 | 51 | |
ryuna | 0:617b63d4a532 | 52 | if(value < 10){ |
ryuna | 0:617b63d4a532 | 53 | String0 = "00"; |
ryuna | 0:617b63d4a532 | 54 | StringZ = String0 + StringZ; |
ryuna | 0:617b63d4a532 | 55 | }else if(value < 100) |
ryuna | 0:617b63d4a532 | 56 | { |
ryuna | 0:617b63d4a532 | 57 | String0 = "0"; |
ryuna | 0:617b63d4a532 | 58 | StringZ = String0 + StringZ; |
ryuna | 0:617b63d4a532 | 59 | }else{ |
ryuna | 0:617b63d4a532 | 60 | |
ryuna | 0:617b63d4a532 | 61 | } |
ryuna | 0:617b63d4a532 | 62 | |
ryuna | 0:617b63d4a532 | 63 | StringA[i] = (StringX + StringY + StringZ); |
ryuna | 0:617b63d4a532 | 64 | |
ryuna | 0:617b63d4a532 | 65 | if(i == 0)StringFIN = StringA[i]; |
ryuna | 0:617b63d4a532 | 66 | else StringFIN += StringA[i]; |
ryuna | 0:617b63d4a532 | 67 | |
ryuna | 0:617b63d4a532 | 68 | } |
ryuna | 0:617b63d4a532 | 69 | |
ryuna | 0:617b63d4a532 | 70 | StringFIN += "\r\n"; |
ryuna | 0:617b63d4a532 | 71 | } |