Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rickxu2/engineer2024 #77

Open
wants to merge 175 commits into
base: main
Choose a base branch
from
Open

Rickxu2/engineer2024 #77

wants to merge 175 commits into from

Conversation

Andd54
Copy link
Member

@Andd54 Andd54 commented Oct 4, 2024

Pull Request for Engineering Codes

@Andd54 Andd54 requested review from rickxu2 and ywh114 October 4, 2024 21:55
Comment on lines +262 to +264
// elbow_rotate_motor->Control(ELBOW_MOTOR_ID, 0.0, 0.0, PI/8, 0.03, 0.03);

// elbow_rotate_motor->Control(ELBOW_MOTOR_ID, 0.0, 0.0, PI/4, 0.01, 0.01);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove

Comment on lines +37 to +85
void RM_RTOS_Init(void) {
print_use_uart(&huart6);
bsp::SetHighresClockTimer(&htim5);

sbus = new remote::SBUS(&huart3);

can = new bsp::CAN(&hcan1);

A1 = new CustomUART(A1_UART);
A1->SetupRx(300);
A1->SetupTx(300);
base_vert_rotate_motor = new control::UnitreeMotor();
base_hor_rotate_motor = new control::UnitreeMotor();
elbow_rotate_motor = new control::UnitreeMotor();
}

static joint_state_t last_targets = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
//static joint_state_t target_state = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};

#define DEBUG_MODE

void RM_RTOS_Default_Task(const void* args) {
UNUSED(args);
// A1 init state
base_hor_rotate_motor->Stop( BASE_YAW_ID);
base_vert_rotate_motor->Stop(BASE_PITCH_ID);
elbow_rotate_motor->Stop(ELBOW_PITCH_ID);
ArmTransmitOutput();

// turn each motor for PI/16 degree every 2 seconds.
// Should stop at defined limitation, see arm_config.h
while (true) {
#ifdef DEBUG_MODE
print("CH0: %-4d CH1: %-4d CH2: %-4d CH3: %-4d ", sbus->ch[0], sbus->ch[1], sbus->ch[2], sbus->ch[3]);
print("CH4: %-4d CH5: %-4d CH6: %-4d CH7: %-4d ", sbus->ch[4], sbus->ch[5], sbus->ch[6], sbus->ch[7]);
print("CH8: %-4d CH9: %-4d CH10: %-4d CH11: %-4d ", sbus->ch[8], sbus->ch[9], sbus->ch[10], sbus->ch[11]);
print("CH12: %-4d CH13: %-4d CH14: %-4d CH15: %-4d ", sbus->ch[12], sbus->ch[13], sbus->ch[14], sbus->ch[15]);
osDelay(100);
#else
if (sbus->ch[6] > 0) {
target_state = {0.0, sbus->ch[0] / sbus->CHANNEL_MAX, sbus->ch[1] / sbus->CHANNEL_MAX, sbus->ch[2] / sbus->CHANNEL_MAX, 0.0, 0.0, 0.0};
ArmTurnRelative(&target_state);
ArmPrintData();
ArmTransmitOutput();
} else
osDelay(100);
#endif
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inconsistent indent size. Use 2.


/* Usage:
* The 'key' is the white button on TypeC boards
**/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: */

Comment on lines +107 to +109
/**
* define params ends
**/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: /* */

control::steering_t steering_data;
motor1 = new control::Motor3508(can1, 0x201);

// TODO assign a GPIO pin to the PE sensor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still nessecary?

steering_data.motor = motor1;
steering_data.max_speed = RUN_SPEED;
steering_data.max_acceleration = ACCELERATION;
// TODO make sure the gear ratio is correct
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

steering_data.omega_pid_param = new float[3]{140, 1.2, 25};
steering_data.max_iout = 1000;
steering_data.max_out = 13000;
// TODO measure the calibrate offset for base translate motor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

}

base_translate_motor->ReAlign();
//base_translate_motor->SetMaxSpeed(RUN_SPEED);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

#endif

#ifdef ELBOW_ROTATE_MOTOR_ENABLE
// elbow_rotate_motor->Control(ELBOW_MOTOR_ID, 0.0, 0.0, 0, 0.003, 0.003);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still nessecary?

Comment on lines +96 to +101
// float impulse_filtered[6] = {0, 0, 0, 0, 0, 0};
// float sbus_derivative[6] = {0, 0, 0, 0, 0, 0};
// std::vector<float> filtered_signal;
// std::deque<int> filter_window;
// float filtered_output = 0;
// int window_size = 5; // Example window size
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indents

}

while (true) {
print("test\r\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still nessecary?

Comment on lines +129 to +134
// for (int i = SBUS_START_IDX; i < SBUS_START_IDX + 6; i++) {
// int index = i - SBUS_START_IDX; // Adjust index for zero-based array indexing
// MedianFilter(sbus->ch[i], filtered_signal, 5);
// }

// updateFilter(sbus->ch[10], filter_window, window_size, filtered_output);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete?

//static remote::DBUS* dbus = nullptr;
static remote::SBUS* sbus = nullptr;
static bsp::GPIO* key = nullptr;
//static float sbus_prev[6] = {0, 0, 0, 0, 0, 0};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete?

Comment on lines +97 to +102
// float impulse_filtered[6] = {0, 0, 0, 0, 0, 0};
// float sbus_derivative[6] = {0, 0, 0, 0, 0, 0};
std::vector<float> filtered_signal;
std::deque<int> filter_window;
// float filtered_output = 0;
// int window_size = 5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete comments

Comment on lines +130 to +135
// for (int i = SBUS_START_IDX; i < SBUS_START_IDX + 6; i++) {
// int index = i - SBUS_START_IDX; // Adjust index for zero-based array indexing
// MedianFilter(sbus->ch[i], filtered_signal, 5);
// }

// updateFilter(sbus->ch[10], filter_window, window_size, filtered_output);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete

Comment on lines +143 to +148
// print("d: %-4d, %-4d, %-4d, %-4d, %-4d, %-4d\n", sbus->ch[10], sbus->ch[11], sbus->ch[12], sbus->ch[13], sbus->ch[14], sbus->ch[15]);
print("d: %-4d, %-4f, %-4f, %-4f\n", sbus->ch[10], J4_pos, J5_pos, J6_pos);
// print("d: %-4d, %-4d, %-4d\n", sbus->ch[0], sbus_actual, sbus_derivative);
// print("d: %-4d, %-4d, %-4d\n", sbus->ch[1], sbus_actual2, sbus_derivative2);

// print("Vel Get: %f, Pos Get: %f\n", vel_get, pos_get);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indents

if(!key->Read()){
angle += 10.0;
power -= 10;
keyEdgeDetector.input(!(key->Read()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: () around key->Read not nessecary

control::PDIHV* motor1;
//bsp::GPIO* pe = nullptr;

bool nintyDegree = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ninty -> ninety

Comment on lines 37 to +39
// motor1->SetOutput(1500);
osDelay(300);
// pe = new bsp::GPIO(IN1_GPIO_Port, IN1_Pin);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indents

Comment on lines 37 to +39
// motor1->SetOutput(1500);
osDelay(300);
// pe = new bsp::GPIO(IN1_GPIO_Port, IN1_Pin);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still nessecary? commented out below as well.

@@ -85,9 +85,9 @@ void RM_RTOS_Default_Task(const void* args) {

control::MotorCANBase* motors[] = {motor};
// bsp::GPIO key(KEY_GPIO_GROUP, KEY_GPIO_PIN);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete

Comment on lines +63 to 64
while(dbus->ch[4] < 100){} // flip swr t;
print("motor enabled\r\n" );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why {}? indent print.

@@ -41,6 +41,7 @@ void RM_RTOS_Init(void) {
gpio_green = new bsp::GPIO(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
gpio_red->High();
gpio_green->High();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants