So I was browsing through the localization section and found this question and the code which answered it. https://robotics.stackexchange.com/a/7932/21145 but I have a follow-up question to this. So the code is exactly what I need but my "beacon" isn't in the middle but in the front (image following). Do I have to change the code or is the solution implemented general enough, I am not quite sure? The beacon is marked as point A.
Edit: Code and clarification better showcase of beacon location
So I chose the mathematical convection and I took the code from the previous question and modified it. The heading is alligned with the x-Axis. Is it theoratically right?
So new it would be:
A_x = M_x + cos(θ + (-25))*r
A_y = M_y + sin(θ + (-25))*r
//current points
float xc = -300;
float yc = 300;
//target points
float xt = -300;
float yt = -300;
//turning angle
float turnAngle;
//***************
float beaconHeading = -25;
float startingHeading = 0;
float currentHeading = startingHeading + beaconHeading;
//***************
//***************
float turnRight = 1;
float turnLeft = -1;
float wheelBase = 39.5;
float tireRadius = 7;
float speedModifier = 0;
float vRightMotor = 0;
float vLeftMotor = 0;
float vMotor = 0;
float theta = 0;
float distance = 0;
//**************
void setup() {
// pin setup
Serial.begin(9600);
}
void loop() {
//*************
destinationHeading = atan2((yt-yc), (xt-xc)); //calculate turning angle
destinationHeading = destinationHeading * 180/3.1415; //convert to
degrees
turnAngle = destinationHeading - currentHeading;
//*************
if (turnAngle > 180) {
turnAngle = turnAngle-360;
}
if (turnAngle < -180) {
turnAngle = turnAngle+360;
}
//***************
if (turnAngle < 0) {
speedModifier = turnRight;
}
if (turnAngle > 0) {
speedModifier = turnLeft
}
theta = 0;
while abs(abs(theta)-abs(turnAngle)) > 0
{
vRightMotor = speedModifier * <100 percent speed - varies by your
application>;
vLeftMotor = -speedModifier * <100 percent speed - varies by your
application>;
<send the vRightMotor/vLeftMotor speed commands to the motors>
vMotor = vRightMotor;
thetaDot = (tireRadius * vMotor) / (wheelBase/2);`
theta = theta + thetaDot*dT;
}
<send zero speed to the motors>
currentHeading = destinationHeading;
distance = sqrt((xt - xc)^2 + (yt - yc)^2);
if (distance > 0) {
// go forward
}
xc = xt;
yc = yt;
//****************
}
I feel like I only had to change one line or am I wrong? I mean if I change the currentheading so that beacon is on a straight line with the next point it works. Maybe I didn't clarify it but I want to reach the next point so that the point A is the same as the point I'm heading to. I did make the angular offset a negative number because if I compare the angle to x-Axis it does go cw and not ccw, I tested it with geogebra and it is fine if I do it like this.
The robot I use is a Arlo Complete Robot System so I could let the robot turn with other commands.