Skip to content
Snippets Groups Projects
Commit 6f464e5d authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added two buttons to increase and decrease the maximum speed.

parent cc3f764b
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,8 @@ class CArmControl
void move(unsigned int axis_id,double torque);
void stop(void);
// stored poses
void set_poses_max_speed(double max);
void increase_max_speed(void);
void decrease_max_speed(void);
void load_poses(const std::string &filename);
void save_poses(const std::string &filename);
void update_pose(unsigned int pose_id);
......
......@@ -19,6 +19,12 @@ void button_callback(void *param,unsigned int button_id,bool level)
try{
switch(button_id)
{
case 4: if(level)
arm->increase_max_speed();
break;
case 6: if(level)
arm->decrease_max_speed();
break;
case 8: if(level)
arm->enable_torque(false);
else
......@@ -126,6 +132,8 @@ CArmControl::CArmControl(const std::string &joy_device,std::string &dyn_serial,
for(unsigned int i=0;i<this->joy.get_num_buttons();i++)
this->current_button_state[i]=this->joy.get_button_state(i);
// assign callbacks
this->joy.enable_button_callback(4,button_callback,this);
this->joy.enable_button_callback(6,button_callback,this);
this->joy.enable_button_callback(8,button_callback,this);
this->joy.enable_button_callback(10,button_callback,this);
this->joy.enable_button_callback(12,button_callback,this);
......@@ -345,13 +353,20 @@ void CArmControl::stop(void)
this->motors[ROLL]->move_absolute_angle(pos,50.0);
}
void CArmControl::set_poses_max_speed(double max)
void CArmControl::increase_max_speed(void)
{
if(max>100.0)
max=0.0;
else if(max<10.0)
max=10.0;
this->max_speed=max;
this->max_speed+=10.0;
if(this->max_speed>100.0)
this->max_speed=100.0;
std::cout << "speed: " << this->max_speed << std::endl;
}
void CArmControl::decrease_max_speed(void)
{
this->max_speed-=10.0;
if(this->max_speed<10.0)
this->max_speed=10.0;
std::cout << "speed: " << this->max_speed << std::endl;
}
void CArmControl::load_poses(const std::string &filename)
......
......@@ -11,7 +11,6 @@ int main(int argc, char *argv[])
CArmControl arm(joy_device,dyn_serial,1000000,6,5,4);
arm.load_poses("/home/sergi/Downloads/arm_control/src/xml/poses.xml");
arm.set_poses_max_speed(50.0);
arm.set_max_angles(PAN,90.0,-90.0);
arm.set_max_angles(TILT,90.0,-90.0);
arm.set_max_angles(ROLL,90.0,-90.0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment