Skip to content

Commit 4ec20fa

Browse files
committed
/* update to move the car on boundary of the shop */
1 parent 33fdc23 commit 4ec20fa

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

Basic_Development/Car_Control/3.0/CarControl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
CarControl* CarControl::instance = nullptr;
1919

2020
const float speed_cm_per_sec_forward_backward = 26.0; // Car's speed in cm/s (30 dc motor speed)
21-
const float speed_deg_per_sec_turn = 47.0; // Car's turning speed in degrees per second
21+
const float speed_deg_per_sec_turn = 50.0; // Car's turning speed in degrees per second
2222

2323
// Constructor is private to enforce singleton pattern
24-
CarControl::CarControl() : _motorAiPn1(5), _motorAPin2(13), _motorBPin1(26), _motorBPin2(16),
24+
CarControl::CarControl() : _motorAPin1(5), _motorAPin2(13), _motorBPin1(26), _motorBPin2(16),
2525
_encoderPinA(20), _encoderPinB(21), _ppr(360), _wheelCircumference(31.4),
2626
_xPos(0.0), _yPos(0.0), _heading(0.0), _pulseCountA(0), _pulseCountB(0),
2727
_forwardBackwardSpeed(30), _turnSpeed(40) {
@@ -55,7 +55,7 @@ void CarControl::initialize() {
5555
void CarControl::setupServo() {
5656
_MS.begin(50);
5757
_servo = _MS.getServo(1);
58-
_servo->writeServo(83); // Center servo position is 80 not 90
58+
_servo->writeServo(81); // Center servo position is 80 not 90
5959
}
6060

6161
// Setup DC motors
@@ -150,7 +150,7 @@ void CarControl::turnRight(int degrees, std::function<void()> callback) {
150150
std::this_thread::sleep_for(std::chrono::milliseconds(int(degrees / speed_deg_per_sec_turn * 1000)));
151151

152152
if (_servo) {
153-
_servo->writeServo(83); // Reset to center position after the turn
153+
_servo->writeServo(81); // Reset to center position after the turn
154154
}
155155

156156
stopDCMotors();
@@ -205,7 +205,7 @@ void CarControl::turnLeft(int degrees, std::function<void()> callback) {
205205
std::this_thread::sleep_for(std::chrono::milliseconds(int(degrees / speed_deg_per_sec_turn * 1000)));
206206

207207
if (_servo) {
208-
_servo->writeServo(83); // Reset to center position after the turn
208+
_servo->writeServo(81); // Reset to center position after the turn
209209
}
210210

211211
stopDCMotors();
@@ -251,4 +251,4 @@ float CarControl::getYPosition() const {
251251
// Get current heading
252252
float CarControl::getCurrentAngle() const {
253253
return _heading;
254-
}
254+
}

Basic_Development/Car_Control/3.0/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main() {
1919
car->initialize();
2020

2121
//boundary of the shop
22-
car->moveForward(155, []() {
22+
car->moveForward(160, []() {
2323
std::cout << "Moved 180 cm forward.\n";
2424
});
2525

@@ -31,19 +31,19 @@ int main() {
3131
std::cout << "Moved 100 cm forward.\n";
3232
});
3333

34-
car->turnRight(90, []() {
34+
car->turnRight(87, []() {
3535
std::cout << "Turned right by 90 degrees.\n";
3636
});
3737

38-
car->moveForward(133, []() {
38+
car->moveForward(130, []() {
3939
std::cout << "Moved 100 cm forward.\n";
4040
});
4141

42-
car->turnRight(90, []() {
42+
car->turnRight(85, []() {
4343
std::cout << "Turned right by 90 degrees.\n";
4444
});
4545

46-
car->moveForward(57, []() {
46+
car->moveForward(45, []() {
4747
std::cout << "Moved 100 cm forward.\n";
4848
});
4949

src/qt/ssc_widget.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ void SSC_Widget::on_pushButton_3_clicked()
343343
void SSC_Widget::on_pushButton_4_clicked()
344344
{
345345
//boundary of the shop
346-
carControl->moveForward(155, []() {
347-
std::cout << "Moved 155 cm forward.\n";
346+
carControl->moveForward(160, []() {
347+
std::cout << "Moved 160 cm forward.\n";
348348
});
349349

350350
carControl->turnRight(90, []() {
@@ -355,20 +355,20 @@ void SSC_Widget::on_pushButton_4_clicked()
355355
std::cout << "Moved 35 cm forward.\n";
356356
});
357357

358-
carControl->turnRight(90, []() {
358+
carControl->turnRight(87, []() {
359359
std::cout << "Turned right by 90 degrees.\n";
360360
});
361361

362-
carControl->moveForward(133, []() {
363-
std::cout << "Moved 133 cm forward.\n";
362+
carControl->moveForward(130, []() {
363+
std::cout << "Moved 130 cm forward.\n";
364364
});
365365

366-
carControl->turnRight(90, []() {
366+
carControl->turnRight(85, []() {
367367
std::cout << "Turned right by 90 degrees.\n";
368368
});
369369

370-
carControl->moveForward(57, []() {
371-
std::cout << "Moved 57 cm forward.\n";
370+
carControl->moveForward(45, []() {
371+
std::cout << "Moved 45 cm forward.\n";
372372
});
373373

374374
/* carControl->moveForward(100, []() {

src/sys/CarControl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void CarControl::initialize() {
5555
void CarControl::setupServo() {
5656
_MS.begin(50);
5757
_servo = _MS.getServo(1);
58-
_servo->writeServo(83); // Center servo position is 80 not 90
58+
_servo->writeServo(81); // Center servo position is 80 not 90
5959
}
6060

6161
// Setup DC motors
@@ -150,7 +150,7 @@ void CarControl::turnRight(int degrees, std::function<void()> callback) {
150150
std::this_thread::sleep_for(std::chrono::milliseconds(int(degrees / speed_deg_per_sec_turn * 1000)));
151151

152152
if (_servo) {
153-
_servo->writeServo(83); // Reset to center position after the turn
153+
_servo->writeServo(81); // Reset to center position after the turn
154154
}
155155

156156
stopDCMotors();
@@ -205,7 +205,7 @@ void CarControl::turnLeft(int degrees, std::function<void()> callback) {
205205
std::this_thread::sleep_for(std::chrono::milliseconds(int(degrees / speed_deg_per_sec_turn * 1000)));
206206

207207
if (_servo) {
208-
_servo->writeServo(83); // Reset to center position after the turn
208+
_servo->writeServo(81); // Reset to center position after the turn
209209
}
210210

211211
stopDCMotors();

0 commit comments

Comments
 (0)