Skip to content

Commit

Permalink
[Spinal][Servo] fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sugihara-16 committed Mar 6, 2024
1 parent bfcabad commit 0adcf56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions aerial_robot_nerve/spinal/mcu_project/lib/Jsk_Lib/servo/servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,27 @@ void DirectServo::servoTorqueControlCallback(const spinal::ServoTorqueCmd& contr

void DirectServo::servoConfigCallback(const spinal::SetDirectServoConfig::Request& req, spinal::SetDirectServoConfig::Response& res)
{

uint8_t command = req.command;

/* special case : data[0] is flag value */
if(command == spinal::SetDirectServoConfig::Request::SET_DYNAMIXEL_TTL_RS485_MIXED)
{
servo_handler_.setTTLRS485Mixed(req.data[0]);
FlashMemory::erase();
FlashMemory::write();
res.success = true;
return;
}

uint8_t servo_index = req.data[0];
ServoData& s = servo_handler_.getOneServo(servo_index);
if(s == servo_handler_.getOneServo(0)){
nh_->logerror("Invalid Servo ID!");
return;
}

switch (req.command) {
switch (command) {
case spinal::SetDirectServoConfig::Request::SET_SERVO_HOMING_OFFSET:
{
int32_t calib_value = req.data[1];
Expand Down Expand Up @@ -169,13 +182,6 @@ void DirectServo::servoConfigCallback(const spinal::SetDirectServoConfig::Reques
servo_handler_.setCurrentLimit(servo_index);
break;
}
case spinal::SetDirectServoConfig::Request::SET_DYNAMIXEL_TTL_RS485_MIXED:
{
servo_handler_.setTTLRS485Mixed(req.data[0]); // special case -> data[0] is flag value
FlashMemory::erase();
FlashMemory::write();
break;
}
case spinal::SetDirectServoConfig::Request::SET_SERVO_EXTERNAL_ENCODER_FLAG:
{
if(!s.torque_enable_){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DirectServo
void setGoalAngle(const std::map<uint8_t, float>& servo_map);

uint32_t rad2Pos(float angle, float scale, uint32_t zero_point_pos){
return static_cast<uint32_t>(zero_point_pos - angle /scale);
return static_cast<uint32_t>(angle /scale + zero_point_pos);
}

private:
Expand Down

0 comments on commit 0adcf56

Please sign in to comment.