Skip to content

Commit

Permalink
max output 30, seitpoint 0 on poweroff
Browse files Browse the repository at this point in the history
  • Loading branch information
missxa committed Jan 20, 2021
1 parent 5e097f3 commit 7912911
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
6 changes: 5 additions & 1 deletion include/roboy_plexus/roboyPlexus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ class RoboyPlexus {
*/
void RoboyStatePublisher();

/**
* Checks if any of the motors were turned off and resets its setpoint to 0 if yes.
*/
void MotorPowerTracker();
/**
* Service for system check
* @param req
Expand Down Expand Up @@ -232,7 +236,7 @@ class RoboyPlexus {
int32_t *power_control, *power_sense, *switches, *led;
vector<A1335Ptr> a1335_elbow, a1335_knee;
boost::shared_ptr<std::thread> elbowJointAngleThread, kneeJointAngleThread,
magneticsThread, motorInfoThread, motorStateThread, roboyStateThread;
magneticsThread, motorInfoThread, motorStateThread, roboyStateThread, powerTrackerThread;
bool keep_publishing = true;
vector<TLE493DPtr> balljoints;
bool emergency_stop = false;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/iCEbusControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void IcebusControl::GetDefaultControlParams(control_Parameters_t *params, int co
params->Ki = 1;
params->Kd = 0;
params->deadband = 0;
params->PWMLimit = 50; // 10% of max pwm
params->PWMLimit = 30; // 30% of max pwm
}else if(muscleType=="m3"){
params->IntegralLimit = 100;
params->Kp = 10;
Expand Down
32 changes: 31 additions & 1 deletion src/roboyPlexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ RoboyPlexus::RoboyPlexus(string robot_name, IcebusControlPtr icebusControl,
roboyStateThread = boost::shared_ptr<std::thread>(new std::thread(&RoboyPlexus::RoboyStatePublisher, this));
roboyStateThread->detach();


neopixel_sub = nh->subscribe(robot_name + "middleware/Neopixel", 1, &RoboyPlexus::Neopixel, this);
emergencyStop_srv = nh->advertiseService(robot_name + "middleware/EmergencyStop",
&RoboyPlexus::EmergencyStopService,
Expand Down Expand Up @@ -139,6 +140,9 @@ RoboyPlexus::RoboyPlexus(string robot_name, IcebusControlPtr icebusControl,
tli4970.reset(new TLI4970(tli4970_base));
}

powerTrackerThread = boost::shared_ptr<std::thread>(new std::thread(&RoboyPlexus::MotorPowerTracker, this));
powerTrackerThread->detach();

ROS_INFO("roboy plexus initialized");
}

Expand All @@ -147,6 +151,8 @@ RoboyPlexus::~RoboyPlexus() {
motorStateThread->join();
if (motorInfoThread->joinable())
motorInfoThread->join();
if (powerTrackerThread->joinable())
powerTrackerThread->join();
}

void RoboyPlexus::MotorStatePublisher() {
Expand All @@ -167,7 +173,9 @@ void RoboyPlexus::MotorStatePublisher() {
msg.encoder1_pos.push_back(bus->GetEncoderPosition(m.first,ENCODER1_POSITION)*m.second->encoder1_conversion_factor);
msg.displacement.push_back(bus->GetDisplacement(m.first));
// msg.displacement.push_back(msg.encoder0_pos.back()-msg.encoder1_pos.back());
msg.current.push_back(bus->GetCurrent(m.first));
auto current = bus->GetCurrent(m.first);
msg.current.push_back(current);

}
}
}
Expand Down Expand Up @@ -252,6 +260,28 @@ void RoboyPlexus::RoboyStatePublisher(){
}
}

void RoboyPlexus::MotorPowerTracker(){
ros::Rate rate(200);
while(ros::ok()) {

for(auto &bus:motorControl){
for(auto motor:bus->motor_config->motor) {
if(bus->MyMotor(motor.first)) {
if (bus->GetCommunicationQuality(motor.first) > 0) {
motor.second->is_on = true;
}
if (motor.second->is_on && bus->GetCommunicationQuality(motor.first) <= 0) {
bus->SetPoint(motor.first, 0);
motor.second->is_on = false;
ROS_INFO("motor %d on %s is off - resetting setpoint to 0.", motor.second->motor_id_global, bus->whoami().c_str());
}
}
}
}
rate.sleep();
}
}

void RoboyPlexus::Neopixel(const roboy_middleware_msgs::Neopixel::ConstPtr &msg){
uint i = 0;
external_led_control = true;
Expand Down

0 comments on commit 7912911

Please sign in to comment.