Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 7_21_17_FSG 7_26_17_FSG
Fork of Battery_Linear_Actuator_ by
Diff: Battery_Linear_Actuator.cpp
- Revision:
- 2:627fd46c2b99
- Parent:
- 1:ca2454ef80d9
- Child:
- 3:9181d42863cd
--- a/Battery_Linear_Actuator.cpp Fri Jun 30 18:32:40 2017 +0000
+++ b/Battery_Linear_Actuator.cpp Mon Jul 17 14:23:34 2017 +0000
@@ -51,24 +51,22 @@
string Battery_Linear_Actuator::MC_readable_redux()
{
string bla_string = "";
-
- //MC.printf("pos\r");
- wait(0.1); //THIS SHOULD WORK!
+ wait(0.1); //THIS WORKS (based on testing)!
- if(MC.readable()) //if you can read the motor controller do this...
- {
- //bla_string += "\nMC readable\n";
-
+ if(MC.readable()) //if you can read the LA motor controller do this...
+ {
while(MC.readable())
- {
- //strcat(bla_array, MC.getc()); //this is a pass-through of the MC (getc) to the PC (putc)
-
+ {
bla_string += MC.getc();
wait_ms(1); //1000, 10, 20, 100 (needed at least 1 ms, verified through testing)
}
+
+ return bla_string; //return the character array as a string
}
-
- return bla_string; //return the character array as a string
+ else
+ {
+ return ""; //return the empty string because you didn't read anything
+ }
}
string Battery_Linear_Actuator::Keyboard_O()
@@ -125,7 +123,7 @@
MC.printf("V%d\r", velocity);
char velocity_string[80];
- sprintf(velocity_string, "\nVELOCITY COMMAND: V%d.\n", velocity);
+ sprintf(velocity_string, "\nVELOCITY COMMAND: V%d\n", velocity);
return velocity_string;
}
@@ -139,12 +137,15 @@
//this uses the position record saved in the object
if (actual_position >= 0 && actual_position <= 175000)
{
+ //send velocity command and get the return value
MC.printf("en\r");
MC.printf("V%d\r", velocity);
+ MC.printf("GV\r", velocity);
+ string velocity_return_string = Battery_Linear_Actuator::MC_readable_redux();
- char velocity_string[80];
- sprintf(velocity_string, "\nVELOCITY COMMAND: V%d.\n", velocity);
-
+ char velocity_string[80];
+ sprintf(velocity_string, "\nVELOCITY COMMAND: V%d\nRETURN VELOCITY gv%s\n", velocity, velocity_return_string.c_str());
+
return velocity_string;
}
@@ -199,7 +200,7 @@
if (linear_actuator_step_size <= 9800) //arbitrary stop at 10000
linear_actuator_step_size += 200;
char bla_string[80];
- sprintf(bla_string, "\n(MBED) Linear Actuator step size INCREASED\nLA_SZ: %d", linear_actuator_step_size);
+ sprintf(bla_string, "\n(MBED) Linear Actuator step size INCREASED\nLAM_SZ: %d", linear_actuator_step_size);
return bla_string;
}
@@ -209,7 +210,7 @@
if (linear_actuator_step_size >= 200)
linear_actuator_step_size -= 200;
char bla_string[80];
- sprintf(bla_string, "\n(MBED) Linear Actuator step size DECREASED\nLA_SZ: %d", linear_actuator_step_size);
+ sprintf(bla_string, "\n(MBED) Linear Actuator step size DECREASED\nLAM_SZ: %d", linear_actuator_step_size);
return bla_string;
}
@@ -271,7 +272,8 @@
MC.printf("m\r");
char position[80];
- sprintf(position, "\nA received! (MBED) motor_absolute_position\nMBED_m_a_p: %d\n", motor_absolute_position);
+ //sprintf(position, "\nA received! (MBED) motor_absolute_position\nMBED_m_a_p: %d\n", motor_absolute_position);
+ sprintf(position, "\nA received! (MBED) motor_absolute_position\nLAM_POS: %d\n", motor_absolute_position);
return position;
}
@@ -290,7 +292,8 @@
MC.printf("m\r");
char position[80];
- sprintf(position, "\nA received! (MBED) motor_absolute_position\nMBED_m_a_p: %d\n", motor_absolute_position);
+ //sprintf(position, "\nA received! (MBED) motor_absolute_position\nMBED_m_a_p: %d\n", motor_absolute_position);
+ sprintf(position, "\nA received! (MBED) motor_absolute_position\nLAM_POS: %d\n", motor_absolute_position);
return position;
}
@@ -327,6 +330,17 @@
//char ioc_char; //linear actuator i/o configuration
//int ioc_array[28]; //http://stackoverflow.com/questions/439573/how-to-convert-a-single-char-into-an-int
+string Battery_Linear_Actuator::get_vel()
+{
+ string vel_string = "";
+
+ MC.printf("gv\r");
+ wait(0.1); //THIS SHOULD WORK!
+
+ vel_string = Battery_Linear_Actuator::MC_readable_redux();
+ return vel_string;
+}
+
string Battery_Linear_Actuator::get_pos()
{
string pos_string = "";
@@ -415,10 +429,11 @@
//TROY: This seems to work well. 6/19/17
int integer_output = int(la_output); //output converted to integer for the controller, only uses integer inputs in rev/min
- Battery_Linear_Actuator::velocity_only(integer_output);
+ string velocity_only_string = Battery_Linear_Actuator::velocity_only(integer_output);
//DEBUG
- sprintf(char_buffer, "DEBUG: la_error %3.3f, la_error_sum %3.3f, la_derivative_error %3.3f\n> DEBUG: la_output: %3.3f IMU PITCH ANGLE: %3.3f SETPOINT: %3.3f\n > integer_output: %d", la_error, la_error_sum, la_derivative_error, la_output, IMU_pitch_angle, la_setPoint, integer_output);
+ //sprintf(char_buffer, "DEBUG: la_error %3.3f, la_error_sum %3.3f, la_derivative_error %3.3f\n> DEBUG: la_output: %3.3f IMU PITCH ANGLE: %3.3f SETPOINT: %3.3f\n > integer_output: %d", la_error, la_error_sum, la_derivative_error, la_output, IMU_pitch_angle, la_setPoint, integer_output);
+ sprintf(char_buffer, "DEBUG: la_error %3.3f, la_error_sum %3.3f, la_derivative_error %3.3f\n> DEBUG: la_output: %3.3f IMU PITCH ANGLE: %3.3f SETPOINT: %3.3f\n > integer_output: %d\n%s\n", la_error, la_error_sum, la_derivative_error, la_output, IMU_pitch_angle, la_setPoint, integer_output, velocity_only_string);
return char_buffer;
}
//putting the functionality into the class
\ No newline at end of file
