attempt to make robot rotate

This commit is contained in:
2024-10-09 14:24:23 +02:00
parent c38491ce20
commit b5e619ac0a
4 changed files with 33 additions and 3 deletions

1
.gitignore vendored
View File

@@ -17,3 +17,4 @@ src/C++/Driver/vgcore*
src/C++/Driver/cmake_install.cmake
src/C++/Driver/Makefile
src/C++/Driver/log
build/

View File

@@ -613,3 +613,30 @@ message[10] = message[2] ^ message[3] ^ message[4] ^ message[5] ^ message[6] ^
uint32_t pocet;
pocet = write(HCom, &message, 11);
}
void CKobuki::Rotate(int degrees) {
//w is rotation speed of the robot, in [rad/s].
long double b = 0.23; // wheelbase distance in meters, from kobuki manual https://yujinrobot.github.io/kobuki/doxygen/enAppendixProtocolSpecification.html
int calculatedRotation = ((degrees * PI / 180) * b) / 2;
int actual_speed = 0; // Pure rotation
unsigned char message[11] = {
0xaa, // Start byte 1
0x55, // Start byte 2
0x08, // Payload length (the first 2 bytes dont count)
0x01, // payload type (0x01 = control command)
0x04, // Control byte or additional identifier
actual_speed % 256, // Lower byte of speed value
actual_speed >> 8, // Upper byte of speed value
calculatedRotation % 256, // Placeholder for radius
calculatedRotation >> 8, // Placeholder for radius
0x00 // Placeholder for checksum
};
// Calculate checksum
message[10] = message[2] ^ message[3] ^ message[4] ^ message[5] ^ message[6] ^
message[7] ^ message[8] ^ message[9];
// Send the message
uint32_t pocet;
pocet = write(HCom, &message, 11);
}

View File

@@ -74,6 +74,7 @@ public:
void forward(int speedvalue, long double distance);
void doRotation(long double th);
void goToXy(long double xx, long double yy);
void Rotate(int degrees);
std::ofstream odometry_log;
KobukiParser parser;

View File

@@ -17,9 +17,10 @@ int main()
// thread mv(movement);
// mv.join(); //only exit once thread one is done running
// checkCenterCliff();
logToFile();
// logToFile();
//seperate thread so sleep doesnt block main thread
thread logger(logToFile);
// thread logger(logToFile);
robot.Rotate(120);
return 0;
}
@@ -27,7 +28,7 @@ int checkCenterCliff()
{
while (true)
{
std::cout << robot.parser.data.CliffCenter << endl;
std::cout << robot.parser.data.CliffSensorRight << endl;
}
}