Skip to content

Commit

Permalink
Merge pull request #8 from Mapy542/master
Browse files Browse the repository at this point in the history
Use F string for RAM use optimization
  • Loading branch information
samuelsadok authored Jan 7, 2025
2 parents 64c4445 + a1f7082 commit 0f89eab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/ODriveCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ bool ODriveCAN::getPower(Get_Powers_msg_t& msg, uint16_t timeout_ms) {
void ODriveCAN::onReceive(uint32_t id, uint8_t length, const uint8_t* data) {
#ifdef DEBUG
int byte_index = length - 1;
Serial.println("received:");
Serial.print(" id: 0x");
Serial.println(F("received:"));
Serial.print(F(" id: 0x"));
Serial.println(id, HEX);
Serial.print(" data: 0x");
Serial.print(F(" data: 0x"));
while (byte_index >= 0)
Serial.print(msg.data[byte_index--], HEX);
Serial.println("");
Serial.println(F(""));
#endif // DEBUG
if (node_id_ != (id >> ODriveCAN::kNodeIdShift))
return;
Expand All @@ -161,14 +161,14 @@ void ODriveCAN::onReceive(uint32_t id, uint8_t length, const uint8_t* data) {
if (axis_state_callback_ != nullptr)
axis_state_callback_(status, axis_state_user_data_);
else
Serial.println("missing callback");
Serial.println(F("missing callback"));
break;
}
default: {
if (requested_msg_id_ == REQUEST_PENDING)
return;
#ifdef DEBUG
Serial.print("waiting for: 0x");
Serial.print(F("waiting for: 0x"));
Serial.println(requested_msg_id_, HEX);
#endif // DEBUG
if ((id & ODriveCAN::kCmdIdBits) != requested_msg_id_)
Expand Down
20 changes: 10 additions & 10 deletions src/ODriveUART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ODriveUART::ODriveUART(Stream& serial)
: serial_(serial) {}

void ODriveUART::clearErrors() {
serial_ << "sc\n";
serial_ << F("sc\n");
}

void ODriveUART::setPosition(float position) {
Expand All @@ -27,23 +27,23 @@ void ODriveUART::setPosition(float position, float velocity_feedforward) {
}

void ODriveUART::setPosition(float position, float velocity_feedforward, float torque_feedforward) {
serial_ << "p " << kMotorNumber << " " << position << " " << velocity_feedforward << " " << torque_feedforward << "\n";
serial_ << F("p ") << kMotorNumber << F(" ") << position << F(" ") << velocity_feedforward << F(" ") << torque_feedforward << F("\n");
}

void ODriveUART::setVelocity(float velocity) {
setVelocity(velocity, 0.0f);
}

void ODriveUART::setVelocity(float velocity, float torque_feedforward) {
serial_ << "v " << kMotorNumber << " " << velocity << " " << torque_feedforward << "\n";
serial_ << F("v ") << kMotorNumber << F(" ") << velocity << F(" ") << torque_feedforward << F("\n");
}

void ODriveUART::setTorque(float torque) {
serial_ << "c " << kMotorNumber << " " << torque << "\n";
serial_ << F("c ") << kMotorNumber << F(" ") << torque << F("\n");
}

void ODriveUART::trapezoidalMove(float position) {
serial_ << "t " << kMotorNumber << " " << position << "\n";
serial_ << F("t ") << kMotorNumber << F(" ") << position << F("\n");
}

ODriveFeedback ODriveUART::getFeedback() {
Expand All @@ -52,7 +52,7 @@ ODriveFeedback ODriveUART::getFeedback() {
serial_.read();
}

serial_ << "f " << kMotorNumber << "\n";
serial_ << F("f ") << kMotorNumber << F("\n");

String response = readLine();

Expand All @@ -68,20 +68,20 @@ ODriveFeedback ODriveUART::getFeedback() {
}

String ODriveUART::getParameterAsString(const String& path) {
serial_ << "r " << path << "\n";
serial_ << F("r ") << path << F("\n");
return readLine();
}

void ODriveUART::setParameter(const String& path, const String& value) {
serial_ << "w " << path << " " << value << "\n";
serial_ << F("w ") << path << F(" ") << value << F("\n");
}

void ODriveUART::setState(ODriveAxisState requested_state) {
setParameter("axis0.requested_state", String((long)requested_state));
setParameter(F("axis0.requested_state"), String((long)requested_state));
}

ODriveAxisState ODriveUART::getState() {
return (ODriveAxisState)getParameterAsInt("axis0.current_state");
return (ODriveAxisState)getParameterAsInt(F("axis0.current_state"));
}

String ODriveUART::readLine(unsigned long timeout_ms) {
Expand Down

0 comments on commit 0f89eab

Please sign in to comment.