![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
bio robot
Dependencies: MPU6050-DMP QEI_hw mbed-rpc mbed
Fork of MPU6050_Example by
Comm/Comm.cpp@4:ebb882658c50, 2015-12-03 (annotated)
- Committer:
- amandaghassaei
- Date:
- Thu Dec 03 03:14:00 2015 +0000
- Revision:
- 4:ebb882658c50
- Parent:
- 2:17b18ea93551
- Child:
- 5:c3d671959ef3
added pc back to comm object;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
amandaghassaei | 2:17b18ea93551 | 1 | #include "Comm.h" |
amandaghassaei | 4:ebb882658c50 | 2 | #include "mbed_rpc.h" |
amandaghassaei | 2:17b18ea93551 | 3 | |
amandaghassaei | 2:17b18ea93551 | 4 | |
amandaghassaei | 4:ebb882658c50 | 5 | Comm::Comm(CommDelegate *gains, CommDelegate *target, CommDelegate *myMPU6050_1):_pc(USBTX, USBRX), _json(&_pc) |
amandaghassaei | 2:17b18ea93551 | 6 | { |
amandaghassaei | 2:17b18ea93551 | 7 | // _pc.baud(115200); |
amandaghassaei | 2:17b18ea93551 | 8 | _gains = gains; |
amandaghassaei | 2:17b18ea93551 | 9 | _target = target; |
amandaghassaei | 2:17b18ea93551 | 10 | _myMPU6050_1 = myMPU6050_1; |
amandaghassaei | 2:17b18ea93551 | 11 | } |
amandaghassaei | 2:17b18ea93551 | 12 | |
amandaghassaei | 2:17b18ea93551 | 13 | void Comm::openGripper1(){ |
amandaghassaei | 2:17b18ea93551 | 14 | printGripper1State(true); |
amandaghassaei | 2:17b18ea93551 | 15 | } |
amandaghassaei | 2:17b18ea93551 | 16 | |
amandaghassaei | 2:17b18ea93551 | 17 | void Comm::closeGripper1(){ |
amandaghassaei | 2:17b18ea93551 | 18 | printGripper1State(false); |
amandaghassaei | 2:17b18ea93551 | 19 | } |
amandaghassaei | 2:17b18ea93551 | 20 | |
amandaghassaei | 2:17b18ea93551 | 21 | void Comm::printGripper1State(bool state){ |
amandaghassaei | 2:17b18ea93551 | 22 | _json.open(); |
amandaghassaei | 2:17b18ea93551 | 23 | if (state) _json.print("gripper1", "true"); |
amandaghassaei | 2:17b18ea93551 | 24 | else _json.print("gripper1", "false"); |
amandaghassaei | 2:17b18ea93551 | 25 | _json.close(); |
amandaghassaei | 2:17b18ea93551 | 26 | } |
amandaghassaei | 2:17b18ea93551 | 27 | |
amandaghassaei | 2:17b18ea93551 | 28 | void Comm::openGripper2(){ |
amandaghassaei | 2:17b18ea93551 | 29 | printGripper2State(true); |
amandaghassaei | 2:17b18ea93551 | 30 | } |
amandaghassaei | 2:17b18ea93551 | 31 | |
amandaghassaei | 2:17b18ea93551 | 32 | void Comm::closeGripper2(){ |
amandaghassaei | 2:17b18ea93551 | 33 | printGripper2State(false); |
amandaghassaei | 2:17b18ea93551 | 34 | } |
amandaghassaei | 2:17b18ea93551 | 35 | |
amandaghassaei | 2:17b18ea93551 | 36 | void Comm::printGripper2State(bool state){ |
amandaghassaei | 2:17b18ea93551 | 37 | _json.open(); |
amandaghassaei | 2:17b18ea93551 | 38 | if (state) _json.print("gripper2", "true"); |
amandaghassaei | 2:17b18ea93551 | 39 | else _json.print("gripper2", "false"); |
amandaghassaei | 2:17b18ea93551 | 40 | _json.close(); |
amandaghassaei | 2:17b18ea93551 | 41 | } |
amandaghassaei | 2:17b18ea93551 | 42 | |
amandaghassaei | 2:17b18ea93551 | 43 | void Comm::setGains(float k1, float d1, float k2, float d2){ |
amandaghassaei | 2:17b18ea93551 | 44 | _gains->setGains(k1, d1, k2, d2); |
amandaghassaei | 2:17b18ea93551 | 45 | } |
amandaghassaei | 2:17b18ea93551 | 46 | |
amandaghassaei | 2:17b18ea93551 | 47 | void Comm::printGains(){ |
amandaghassaei | 2:17b18ea93551 | 48 | _json.open(); |
amandaghassaei | 2:17b18ea93551 | 49 | _json.print("k1", _gains->getK1()); |
amandaghassaei | 2:17b18ea93551 | 50 | _json.sepItem(); |
amandaghassaei | 2:17b18ea93551 | 51 | _json.print("d1", _gains->getD1()); |
amandaghassaei | 2:17b18ea93551 | 52 | _json.sepItem(); |
amandaghassaei | 2:17b18ea93551 | 53 | _json.print("k2", _gains->getK2()); |
amandaghassaei | 2:17b18ea93551 | 54 | _json.sepItem(); |
amandaghassaei | 2:17b18ea93551 | 55 | _json.print("d2", _gains->getD1()); |
amandaghassaei | 2:17b18ea93551 | 56 | _json.close(); |
amandaghassaei | 2:17b18ea93551 | 57 | } |
amandaghassaei | 2:17b18ea93551 | 58 | |
amandaghassaei | 2:17b18ea93551 | 59 | void Comm::setTarget(int targetPosition){ |
amandaghassaei | 2:17b18ea93551 | 60 | _target->setPosition(targetPosition); |
amandaghassaei | 2:17b18ea93551 | 61 | } |
amandaghassaei | 2:17b18ea93551 | 62 | |
amandaghassaei | 2:17b18ea93551 | 63 | void Comm::printTarget(){ |
amandaghassaei | 2:17b18ea93551 | 64 | _json.open(); |
amandaghassaei | 2:17b18ea93551 | 65 | _json.print("target", _target->getPosition()); |
amandaghassaei | 2:17b18ea93551 | 66 | _json.close(); |
amandaghassaei | 2:17b18ea93551 | 67 | } |
amandaghassaei | 2:17b18ea93551 | 68 | |
amandaghassaei | 2:17b18ea93551 | 69 | void Comm::printPosition(){ |
amandaghassaei | 2:17b18ea93551 | 70 | _json.open(); |
amandaghassaei | 2:17b18ea93551 | 71 | _json.print("th1", _myMPU6050_1->getTheta()); |
amandaghassaei | 2:17b18ea93551 | 72 | _json.sepItem(); |
amandaghassaei | 2:17b18ea93551 | 73 | _json.print("dth1", _myMPU6050_1->getDtheta()); |
amandaghassaei | 2:17b18ea93551 | 74 | _json.close(); |
amandaghassaei | 2:17b18ea93551 | 75 | } |
amandaghassaei | 2:17b18ea93551 | 76 | |
amandaghassaei | 4:ebb882658c50 | 77 | void Comm::check(){ |
amandaghassaei | 4:ebb882658c50 | 78 | _pc.gets(buf, 256); |
amandaghassaei | 4:ebb882658c50 | 79 | //Call the static call method on the RPC class |
amandaghassaei | 4:ebb882658c50 | 80 | RPC::call(buf, outbuf); |
amandaghassaei | 4:ebb882658c50 | 81 | _pc.printf("%s\n", outbuf); |
amandaghassaei | 4:ebb882658c50 | 82 | } |