Skip to content

Commit

Permalink
[Neuron][Servo][Inialize] introduce a new variable to check the connn…
Browse files Browse the repository at this point in the history
…ection between spinal and neuron
  • Loading branch information
tongtybj authored and Moju Zhao committed Nov 17, 2024
1 parent 71d746f commit feb5e2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void Initializer::receiveDataCallback(uint8_t message_id, uint32_t DLC, uint8_t*
case CAN::MESSAGEID_RECEIVE_INITIAL_CONFIG_REQUEST:
{
sendBoardConfig();
servo_.setConnect(true);
}
break;
case CAN::MESSAGEID_RECEIVE_BOARD_CONFIG_REQUEST:
Expand Down
3 changes: 3 additions & 0 deletions aerial_robot_nerve/neuron/neuronlib/Servo/servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
void Servo::init(UART_HandleTypeDef* huart, I2C_HandleTypeDef* hi2c, osMutexId* mutex = NULL)
{
servo_handler_.init(huart, hi2c, mutex);
connect_ = false;
}

void Servo::update()
Expand All @@ -35,6 +36,8 @@ void Servo::sendData()

void Servo::receiveDataCallback(uint8_t message_id, uint32_t DLC, uint8_t* data)
{
if (!connect_) return;

switch (message_id) {
case CAN::MESSAGEID_RECEIVE_SERVO_ANGLE:
{
Expand Down
4 changes: 4 additions & 0 deletions aerial_robot_nerve/neuron/neuronlib/Servo/servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Servo : public CANDevice
void sendData() override;
void receiveDataCallback(uint8_t message_id, uint32_t DLC, uint8_t* data) override;

bool getConnect() {return connect_;}
void setConnect(bool connect) {connect_ = connect;}

private:
struct CANServoData{
int16_t angle;
Expand All @@ -35,6 +38,7 @@ class Servo : public CANDevice
:angle(angle), temperature(temperature), moving(moving), current(current), error(error){}
};

bool connect_;
DynamixelSerial servo_handler_;
friend class Initializer;
};
Expand Down

0 comments on commit feb5e2a

Please sign in to comment.