Skip to content

Commit

Permalink
Bumping version
Browse files Browse the repository at this point in the history
And also setting the default go speed back to what it was
  • Loading branch information
platisd committed Jan 16, 2017
1 parent 945414a commit c487e7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Smartcar shield
version=4.0.1
version=4.1.0
author=Dimitris Platis
maintainer=Dimitris Platis <dimitris@plat.is>
sentence=Arduino library for controlling the Smartcar platform
Expand Down
12 changes: 6 additions & 6 deletions src/Car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const unsigned short MAX_EFFORTS = 2; //amount of efforts to stop reversing the

const float MAX_BACK_CRUISE_SPEED = -3.0; //how fast the car can drive forward in cruise control mode (meters/sec)
const float MAX_FRONT_CRUISE_SPEED = 3.0; //how fast the car can drive backward in cruise control mode (meters/sec)
const float GO_CRUISE_SPEED = 0.4; //how fast car should move in go(int centimeters) and rotate(int degrees) while on cruise control
const float GO_CRUISE_SPEED = 1.3; //how fast car should move in go(int centimeters) and rotate(int degrees) while on cruise control
const int GO_RAW_SPEED = 70; //how fast car should move in go(int centimeters) and rotate(int degrees) while NOT on cruise control

Car::Car(const unsigned short shieldOrientation){
Expand Down Expand Up @@ -128,7 +128,7 @@ float Car::motorPIDcontrol(const float previousSpeed, const float targetSpeed, c
float correction = 0;
float error = targetSpeed - actualSpeed;
_integratedError += error;
correction = (_Kp * error) + (_Ki * _integratedError) + (_Kd * (error - _previousError));
correction = (_Kp * error) + (_Ki * _integratedError) + (_Kd * (error - _previousError));
_previousError = error;
return constrain(previousSpeed + correction, -100, 100);
}
Expand All @@ -139,12 +139,12 @@ float Car::getGroundSpeed(){ //the ground speed, as measured by the car. we use
_previousDistance = currentDistance;
unsigned long dT = millis() - _lastMotorUpdate;
float velocity = (float(dX) * 10)/ dT; //output in m/seconds, divide by 100 to turn cm into m and multiply by 1000, to turn ms to sec
return velocity;
return velocity;
}

void Car::stop(){
if (!_numOfEncoders || !cruiseControlEnabled()){ //if no encoders attached or not in cruise control mode
if (!almostEqual(_speed,0)){ //if the speed that we already have is NOT equal to 0 then
if (!almostEqual(_speed,0)){ //if the speed that we already have is NOT equal to 0 then
_throttle->setSpeed(-_speed); //move towards opposite direction at _speed (_speed in non cruise control is between -100,100)
delay(80); //go the opposite direction for a few milliseconds, to make sure we are stopped
}
Expand Down Expand Up @@ -240,7 +240,7 @@ void Car::go(int centimeters){
if (cruiseControlEnabled()) updateMotors(); //otherwise the pid for the motors won't work
}
setSpeed(initialSpeed); //restore to the initial speed
setAngle(initialAngle); //restore to the inital angle
setAngle(initialAngle); //restore to the inital angle
}
void Car::rotate(int targetDegrees){
targetDegrees %= 360; //put it on a (-360,360) scale
Expand All @@ -264,7 +264,7 @@ void Car::rotate(int targetDegrees){
_heading->update(); //update to integrate the latest heading sensor readings
int currentHeading = _heading->getAngularDisplacement(); //in the scale of 0 to 360
if (targetDegrees < 0 && currentHeading > initialHeading){ //if we are turning left and the current heading is larger than the
//initial one (e.g. started at 10 degrees and now we are at 350), we need to substract 360, so to eventually get a signed
//initial one (e.g. started at 10 degrees and now we are at 350), we need to substract 360, so to eventually get a signed
currentHeading -= 360; //displacement from the initial heading (-20)
}else if (targetDegrees > 0 && currentHeading < initialHeading){ //if we are turning right and the heading is smaller than the
//initial one (e.g. started at 350 degrees and now we are at 20), so to get a signed displacement (+30)
Expand Down

0 comments on commit c487e7b

Please sign in to comment.