Skip to content

Commit

Permalink
Unify CAN Motor implementation (#317)
Browse files Browse the repository at this point in the history
* RM unused CANMotor_AVR.cpp

* Merge CANMotor_PSOC into CANMotor

* Fixed function move

* Removed double function

* Removed unused CANMotor includes
  • Loading branch information
DrDab authored Apr 26, 2024
1 parent 1ece44b commit 1a46e00
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 94 deletions.
33 changes: 33 additions & 0 deletions src/CAN/CANMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,39 @@ using robot::types::LimitSwitchData;

namespace can::motor {

void initEncoder(deviceserial_t serial, bool invertEncoder, bool zeroEncoder,
int32_t pulsesPerJointRev,
std::optional<std::chrono::milliseconds> telemetryPeriod) {
auto motorGroupCode = static_cast<uint8_t>(devicegroup_t::motor);
CANPacket p;
AssembleEncoderInitializePacket(&p, motorGroupCode, serial, sensor_t::encoder,
invertEncoder, zeroEncoder);
sendCANPacket(p);
std::this_thread::sleep_for(1000us);
AssembleEncoderPPJRSetPacket(&p, motorGroupCode, serial, pulsesPerJointRev);
sendCANPacket(p);
std::this_thread::sleep_for(1000us);
if (telemetryPeriod) {
scheduleTelemetryPull(std::make_pair(devicegroup_t::motor, serial), telemtype_t::angle,
telemetryPeriod.value());
}
}

void initPotentiometer(deviceserial_t serial, int32_t posLo, int32_t posHi, uint16_t adcLo,
uint16_t adcHi,
std::optional<std::chrono::milliseconds> telemetryPeriod) {
CANPacket packet;
auto group = static_cast<uint8_t>(devicegroup_t::motor);
AssemblePotHiSetPacket(&packet, group, serial, adcHi, posHi);
sendCANPacket(packet);
AssemblePotLoSetPacket(&packet, group, serial, adcLo, posLo);
sendCANPacket(packet);
if (telemetryPeriod) {
scheduleTelemetryPull(std::make_pair(devicegroup_t::motor, serial), telemtype_t::angle,
telemetryPeriod.value());
}
}

void emergencyStopMotors() {
CANPacket p;
AssembleGroupBroadcastingEmergencyStopPacket(&p, static_cast<uint8_t>(0x0),
Expand Down
37 changes: 0 additions & 37 deletions src/CAN/CANMotor_AVR.cpp

This file was deleted.

56 changes: 0 additions & 56 deletions src/CAN/CANMotor_PSOC.cpp

This file was deleted.

1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ target_link_libraries(utils ${OpenCV_LIBS})
# No clue why but CAN I/O goes to shit. Don't do it.
add_library(can_interface STATIC)
target_sources(can_interface PRIVATE
CAN/CANMotor_PSOC.cpp
CAN/CANMotor.cpp
CAN/CANUtils.cpp
)
Expand Down

0 comments on commit 1a46e00

Please sign in to comment.