Skip to content

Commit 659047f

Browse files
committed
2 parents 14f2546 + c4df64c commit 659047f

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

examples/firmware_01/firmware_01.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void loop(){
231231
break;
232232
case 3:
233233
if (tof.update_rois()){
234-
msg_size = packeter.packetC7I('f', tof.getLeft(), tof.getCenterLeft(), tof.getCenter(), tof.getCenterRight(), tof.getRight(), tof.get_min_range_top_mm(), tof.get_max_range_bottom_mm());
234+
msg_size = packeter.packetC7I('f', tof.getLeft(), tof.getCenterLeft(), tof.getCenter(), tof.getCenterRight(), tof.getRight(), tof.getTop(), tof.getBottom());
235235
alvik.serial->write(packeter.msg,msg_size);
236236
}
237237
break;
@@ -247,7 +247,7 @@ void loop(){
247247
}
248248

249249
// motors update & publish
250-
if (millis()-tmotor>20){
250+
if (millis()-tmotor>=20){
251251
tmotor=millis();
252252
alvik.updateMotors();
253253
alvik.updateKinematics();

src/motor_control/motor_control.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ MotorControl::MotorControl(DCmotor * _motor, Encoder * _encoder, const float _kp
4242
angle = 0.0;
4343
reference = 0.0;
4444

45+
return_flag = false;
46+
4547
trip = 0.0;
4648
iterations = 0.0;
4749
start_value = 0.0;
@@ -111,22 +113,28 @@ float MotorControl::getRPM(){
111113

112114

113115
bool MotorControl::setRPM(const float ref){
114-
if ((ref<=MOTOR_LIMIT)&&(ref>=-MOTOR_LIMIT)){
115-
reference = ref;
116-
if (control_mode==CONTROL_MODE_LINEAR){
117-
start_value=interpolation;
118-
end_value=reference;
119-
trip=0.0;
120-
iterations=abs(end_value-start_value)/step_size;
121-
step=1.0/iterations;
122-
step_index=0;
123-
}
124-
else if(control_mode==CONTROL_MODE_NORMAL){
125-
vel_pid->setReference(reference);
126-
}
127-
return true;
116+
reference = ref;
117+
return_flag = true;
118+
if (ref>MOTOR_LIMIT){
119+
reference=MOTOR_LIMIT;
120+
return_flag = false;
121+
}
122+
if (ref<-MOTOR_LIMIT){
123+
reference=-MOTOR_LIMIT;
124+
return_flag = false;
125+
}
126+
if (control_mode==CONTROL_MODE_LINEAR){
127+
start_value=interpolation;
128+
end_value=reference;
129+
trip=0.0;
130+
iterations=abs(end_value-start_value)/step_size;
131+
step=1.0/iterations;
132+
step_index=0;
133+
}
134+
else if(control_mode==CONTROL_MODE_NORMAL){
135+
vel_pid->setReference(reference);
128136
}
129-
return false;
137+
return return_flag;
130138
}
131139

132140
void MotorControl::update(){

src/motor_control/motor_control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class MotorControl{
2929
private:
3030

3131
uint8_t control_mode;
32+
bool return_flag;
33+
3234

3335
float kp;
3436
float ki;

src/sensor_tof_matrix.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class SensorTofMatrix{
133133
bool update_rois() {
134134
bool out = update();
135135
top = get_avg_range_top_mm();
136-
bottom = get_max_range_bottom_mm();
136+
bottom = get_avg_range_bottom_mm();
137137
left = get_avg_range_left_mm();
138138
right = get_avg_range_right_mm();
139139
center_left = get_avg_range_center_left_mm();
@@ -168,7 +168,7 @@ class SensorTofMatrix{
168168

169169
int get_max_range_bottom_mm() {
170170

171-
int16_t bottom_max = results.distance_mm[0];
171+
int16_t bottom_max = results.distance_mm[4?12:48];
172172

173173
for (int i=(_size==4?12:48); i < (_size==4?15:63) ;i++) {
174174
bottom_max = max(bottom_max, results.distance_mm[i]);
@@ -206,7 +206,7 @@ class SensorTofMatrix{
206206

207207
int get_min_range_right_mm() {
208208

209-
int16_t _min = results.distance_mm[0];
209+
int16_t _min = results.distance_mm[4?3:6];
210210

211211
for (int i=(_size==4?3:6); i < (_size==4?16:64) ;i+=_size) {
212212
_min = min(_min, results.distance_mm[i]);
@@ -220,7 +220,7 @@ class SensorTofMatrix{
220220

221221
int get_min_range_center_left_mm() {
222222

223-
int16_t _min = results.distance_mm[0];
223+
int16_t _min = results.distance_mm[4?5:18];
224224

225225
for (int i=(_size==4?5:18); i < (_size==4?13:50) ;i+=_size) {
226226
_min = min(_min, results.distance_mm[i]);
@@ -234,7 +234,7 @@ class SensorTofMatrix{
234234

235235
int get_min_range_center_right_mm() {
236236

237-
int16_t _min = results.distance_mm[0];
237+
int16_t _min = results.distance_mm[4?6:20];
238238

239239
for (int i=(_size==4?6:20); i < (_size==4?14:52) ;i+=_size) {
240240
_min = min(_min, results.distance_mm[i]);
@@ -248,7 +248,7 @@ class SensorTofMatrix{
248248

249249
int get_min_range_center_mm() {
250250

251-
int16_t _min = results.distance_mm[0];
251+
int16_t _min = results.distance_mm[5?6:19];
252252

253253
for (int i=(_size==5?6:19); i < (_size==4?13:51) ;i+=_size) {
254254
_min = min(_min, results.distance_mm[i]);

0 commit comments

Comments
 (0)