2015/08/11
Dependents: Cansat_program3 Cansat_program4
Fork of CanSat_aoki by
cansat.cpp@5:534a54a44b22, 2015-08-10 (annotated)
- Committer:
- s1210160
- Date:
- Mon Aug 10 10:01:15 2015 +0000
- Revision:
- 5:534a54a44b22
- Parent:
- 4:8713fff9e20d
- Child:
- 6:601cac49d4b1
2015/08/10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kityann | 2:0f76226be922 | 1 | #include "cansat.h" |
kityann | 2:0f76226be922 | 2 | |
kityann | 2:0f76226be922 | 3 | |
kityann | 2:0f76226be922 | 4 | ////////////////////////////// |
kityann | 2:0f76226be922 | 5 | // Init // |
kityann | 2:0f76226be922 | 6 | ////////////////////////////// |
kityann | 2:0f76226be922 | 7 | CanSat::CanSat(VNH5019 agzSheild):_agzSheild(agzSheild){ |
kityann | 2:0f76226be922 | 8 | |
kityann | 2:0f76226be922 | 9 | } |
kityann | 2:0f76226be922 | 10 | |
kityann | 2:0f76226be922 | 11 | |
kityann | 2:0f76226be922 | 12 | |
kityann | 2:0f76226be922 | 13 | void CanSat::control_Motor(int flag,int speed){ |
kityann | 2:0f76226be922 | 14 | |
kityann | 2:0f76226be922 | 15 | if(flag == 0){ |
kityann | 2:0f76226be922 | 16 | _agzSheild.changeSpeed(1, speed, 1, speed); //straight |
kityann | 2:0f76226be922 | 17 | motor_command = 'f'; |
kityann | 2:0f76226be922 | 18 | } |
kityann | 2:0f76226be922 | 19 | if(flag == 1){ |
kityann | 2:0f76226be922 | 20 | _agzSheild.changeSpeed(0, speed, 0, speed); |
kityann | 2:0f76226be922 | 21 | motor_command = 's'; |
kityann | 2:0f76226be922 | 22 | } |
kityann | 2:0f76226be922 | 23 | if(flag == 2){ |
kityann | 2:0f76226be922 | 24 | _agzSheild.changeSpeed(1, speed, 2, speed); //Turn Right |
kityann | 2:0f76226be922 | 25 | motor_command = 'r'; |
kityann | 2:0f76226be922 | 26 | } |
kityann | 2:0f76226be922 | 27 | if(flag == 3){ |
kityann | 2:0f76226be922 | 28 | _agzSheild.changeSpeed(2, speed, 1, speed); //Turn Right |
kityann | 2:0f76226be922 | 29 | motor_command = 'l'; |
kityann | 2:0f76226be922 | 30 | } |
kityann | 2:0f76226be922 | 31 | if(flag == 4){ |
kityann | 2:0f76226be922 | 32 | _agzSheild.changeSpeed(2, speed, 2, speed); |
kityann | 2:0f76226be922 | 33 | motor_command = 'b'; |
kityann | 2:0f76226be922 | 34 | } |
kityann | 2:0f76226be922 | 35 | } |
kityann | 2:0f76226be922 | 36 | |
kityann | 2:0f76226be922 | 37 | |
kityann | 2:0f76226be922 | 38 | ////////////////////////////// |
kityann | 2:0f76226be922 | 39 | // Get // |
kityann | 2:0f76226be922 | 40 | ////////////////////////////// |
kityann | 2:0f76226be922 | 41 | double CanSat::get_robot_x(){ |
kityann | 2:0f76226be922 | 42 | return robot_x; |
kityann | 2:0f76226be922 | 43 | } |
kityann | 2:0f76226be922 | 44 | double CanSat::get_robot_y(){ |
kityann | 2:0f76226be922 | 45 | return robot_y; |
kityann | 2:0f76226be922 | 46 | } |
kityann | 2:0f76226be922 | 47 | double CanSat::get_robotKalman_x(){ |
kityann | 2:0f76226be922 | 48 | return robotK_x; |
kityann | 2:0f76226be922 | 49 | } |
kityann | 2:0f76226be922 | 50 | double CanSat::get_robotKalman_y(){ |
kityann | 2:0f76226be922 | 51 | return robotK_y; |
kityann | 2:0f76226be922 | 52 | } |
s1210160 | 5:534a54a44b22 | 53 | int16_t CanSat::get_compass_x(){ |
s1210160 | 5:534a54a44b22 | 54 | return compass_x; |
s1210160 | 5:534a54a44b22 | 55 | } |
s1210160 | 5:534a54a44b22 | 56 | int16_t CanSat::get_compass_y(){ |
s1210160 | 5:534a54a44b22 | 57 | return compass_y; |
s1210160 | 5:534a54a44b22 | 58 | } |
s1210160 | 5:534a54a44b22 | 59 | int16_t CanSat::get_compass_z(){ |
s1200058 | 4:8713fff9e20d | 60 | return compass_z; |
s1200058 | 4:8713fff9e20d | 61 | } |
s1210160 | 5:534a54a44b22 | 62 | double CanSat::get_compass_angle(){ |
s1210160 | 5:534a54a44b22 | 63 | return compass_angle; |
s1210160 | 5:534a54a44b22 | 64 | } |
s1200058 | 4:8713fff9e20d | 65 | double CanSat::get_target_distance(){ |
s1200058 | 4:8713fff9e20d | 66 | return target_distance; |
s1200058 | 4:8713fff9e20d | 67 | } |
s1200058 | 4:8713fff9e20d | 68 | double CanSat::get_target_x(){ |
s1200058 | 4:8713fff9e20d | 69 | return target_x; |
s1200058 | 4:8713fff9e20d | 70 | } |
s1200058 | 4:8713fff9e20d | 71 | double CanSat::get_target_y(){ |
s1200058 | 4:8713fff9e20d | 72 | return target_y; |
s1200058 | 4:8713fff9e20d | 73 | } |
s1200058 | 4:8713fff9e20d | 74 | int CanSat::get_speed(){ |
s1200058 | 4:8713fff9e20d | 75 | return speed; |
s1200058 | 4:8713fff9e20d | 76 | } |
s1200058 | 4:8713fff9e20d | 77 | int CanSat::get_robot_angle(){ |
s1200058 | 4:8713fff9e20d | 78 | return robot_angle; |
s1200058 | 4:8713fff9e20d | 79 | } |
s1200058 | 4:8713fff9e20d | 80 | int CanSat::get_target_angle(){ |
s1200058 | 4:8713fff9e20d | 81 | return target_angle; |
s1200058 | 4:8713fff9e20d | 82 | } |
s1200058 | 4:8713fff9e20d | 83 | double CanSat::get_pressure(){ |
s1200058 | 4:8713fff9e20d | 84 | return pressure; |
s1200058 | 4:8713fff9e20d | 85 | } |
s1200058 | 4:8713fff9e20d | 86 | double CanSat::get_temperature(){ |
s1200058 | 4:8713fff9e20d | 87 | return temperature; |
s1200058 | 4:8713fff9e20d | 88 | } |
s1200058 | 4:8713fff9e20d | 89 | double CanSat::get_humidity(){ |
s1200058 | 4:8713fff9e20d | 90 | return humidity; |
s1200058 | 4:8713fff9e20d | 91 | } |
kityann | 2:0f76226be922 | 92 | ////////////////////////////// |
kityann | 2:0f76226be922 | 93 | // Set // |
kityann | 2:0f76226be922 | 94 | ////////////////////////////// |
kityann | 2:0f76226be922 | 95 | void CanSat::set_robot_x(double x){ |
kityann | 2:0f76226be922 | 96 | robot_x = x; |
kityann | 2:0f76226be922 | 97 | } |
kityann | 2:0f76226be922 | 98 | void CanSat::set_robot_y(double y){ |
kityann | 2:0f76226be922 | 99 | robot_y = y; |
kityann | 2:0f76226be922 | 100 | } |
kityann | 2:0f76226be922 | 101 | |
kityann | 2:0f76226be922 | 102 | void CanSat::set_robotKalman_x(double cur_x){ |
kityann | 2:0f76226be922 | 103 | robotK_x = cur_x; |
kityann | 2:0f76226be922 | 104 | } |
kityann | 2:0f76226be922 | 105 | void CanSat::set_robotKalman_y(double cur_y){ |
kityann | 2:0f76226be922 | 106 | robotK_y = cur_y; |
kityann | 2:0f76226be922 | 107 | } |
kityann | 2:0f76226be922 | 108 | void CanSat::set_gyro(double x, double y, double z){ |
kityann | 2:0f76226be922 | 109 | CanSat::gyro_x = x; |
kityann | 2:0f76226be922 | 110 | CanSat::gyro_y = y; |
kityann | 2:0f76226be922 | 111 | CanSat::gyro_z = z; |
kityann | 2:0f76226be922 | 112 | } |
s1210160 | 5:534a54a44b22 | 113 | void CanSat::set_compass(int16_t x, int16_t y, int16_t z, double angle){ |
kityann | 2:0f76226be922 | 114 | CanSat::compass_x = x; |
kityann | 2:0f76226be922 | 115 | CanSat::compass_y = y; |
kityann | 2:0f76226be922 | 116 | CanSat::compass_z = z; |
s1210160 | 5:534a54a44b22 | 117 | CanSat::compass_angle = angle; |
kityann | 2:0f76226be922 | 118 | } |
kityann | 2:0f76226be922 | 119 | void CanSat::set_pressure(double p){ |
kityann | 2:0f76226be922 | 120 | CanSat::pressure = p; |
kityann | 2:0f76226be922 | 121 | } |
kityann | 2:0f76226be922 | 122 | void CanSat::set_temperature(double t){ |
kityann | 2:0f76226be922 | 123 | CanSat::temperature = t; |
kityann | 2:0f76226be922 | 124 | } |
kityann | 2:0f76226be922 | 125 | void CanSat::set_humidity(double h){ |
kityann | 2:0f76226be922 | 126 | CanSat::humidity = h; |
kityann | 2:0f76226be922 | 127 | } |
kityann | 2:0f76226be922 | 128 | void CanSat::set_acceleration(double x, double y, double z){ |
kityann | 2:0f76226be922 | 129 | CanSat::acceleration_x = x; |
kityann | 2:0f76226be922 | 130 | CanSat::acceleration_y = y; |
kityann | 2:0f76226be922 | 131 | CanSat::acceleration_z = z; |
s1200058 | 4:8713fff9e20d | 132 | } |
s1200058 | 4:8713fff9e20d | 133 | void CanSat::set_target_distance(double distance){ |
s1200058 | 4:8713fff9e20d | 134 | CanSat::target_distance = distance; |
s1200058 | 4:8713fff9e20d | 135 | } |
s1200058 | 4:8713fff9e20d | 136 | void CanSat::set_speed(int new_speed){ |
s1200058 | 4:8713fff9e20d | 137 | CanSat::speed = new_speed; |
s1200058 | 4:8713fff9e20d | 138 | } |
s1200058 | 4:8713fff9e20d | 139 | void CanSat::set_robot_angle(int new_robot_angle){ |
s1200058 | 4:8713fff9e20d | 140 | CanSat::robot_angle = new_robot_angle; |
s1200058 | 4:8713fff9e20d | 141 | } |
s1200058 | 4:8713fff9e20d | 142 | void CanSat::set_target_angle(int new_target_angle){ |
s1200058 | 4:8713fff9e20d | 143 | CanSat::target_angle = new_target_angle; |
kityann | 2:0f76226be922 | 144 | } |