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