Sets the left and right drive powers of the drive board.
121{
122
123 double dLeftSpeed = std::clamp(stDrivePowers.dLeftDrivePower, -1.0, 1.0);
124 double dRightSpeed = std::clamp(stDrivePowers.dRightDrivePower, -1.0, 1.0);
125
126
127 float fDriveBoardLeftPower =
numops::MapRange(
float(dLeftSpeed), -1.0f, 1.0f, m_fMinDriveEffort, m_fMaxDriveEffort);
128 float fDriveBoardRightPower =
numops::MapRange(
float(dRightSpeed), -1.0f, 1.0f, m_fMinDriveEffort, m_fMaxDriveEffort);
129
130 fDriveBoardLeftPower = std::clamp(float(fDriveBoardLeftPower), constants::DRIVE_MIN_POWER, constants::DRIVE_MAX_POWER);
131 fDriveBoardRightPower = std::clamp(float(fDriveBoardRightPower), constants::DRIVE_MIN_POWER, constants::DRIVE_MAX_POWER);
132
133
134 m_stDrivePowers.dLeftDrivePower = fDriveBoardLeftPower;
135 m_stDrivePowers.dRightDrivePower = fDriveBoardRightPower;
136
137
138 rovecomm::RoveCommPacket<float> stPacket;
139 stPacket.unDataId = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_ID;
140 stPacket.unDataCount = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_COUNT;
141 stPacket.eDataType = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_TYPE;
142 stPacket.vData.emplace_back(fDriveBoardLeftPower);
143 stPacket.vData.emplace_back(fDriveBoardRightPower);
144
145 const char* cIPAddress = constants::MODE_SIM ? constants::SIM_IP_ADDRESS.c_str() : manifest::Core::IP_ADDRESS.IP_STR.c_str();
146
147 if (network::g_pRoveCommUDPNode)
148 {
149 network::g_pRoveCommUDPNode->SendUDPPacket(stPacket, cIPAddress, constants::ROVECOMM_OUTGOING_UDP_PORT);
150 }
151
152 LOG_DEBUG(logging::g_qSharedLogger, "Driving at: ({}, {})", fDriveBoardLeftPower, fDriveBoardRightPower);
153}
constexpr T MapRange(const T tValue, const T tOldMinimum, const T tOldMaximum, const T tNewMinimum, const T tNewMaximum)
Maps a value to a new range given the old range.
Definition NumberOperations.hpp:131