Skip to content

Commit

Permalink
userThread encapsulated
Browse files Browse the repository at this point in the history
  • Loading branch information
Raventhatfly committed Jul 11, 2023
1 parent 8ec8f85 commit 9cbdcb7
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 35 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ add_executable(DART
dev/interface/referee/referee_interface.cpp
dev/application/vehicles/dart/can_motor_config.cpp
dev/application/vehicles/dart/main_dart.cpp
dev/application/vehicles/dart/user_dart.cpp
)
target_include_directories(DART PRIVATE dev/application/vehicles/dart)
target_compile_definitions(DART PRIVATE DART)
Expand Down
72 changes: 37 additions & 35 deletions dev/application/vehicles/dart/main_dart.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Created by Wu Feiyang on 2023/76.
// Created by Wu Feiyang on 2023/7/6.
//
#include "ch.hpp"
#include "hal.h"
Expand All @@ -8,43 +8,44 @@
#include "chprintf.h"
#include "shell.h"
#include "remote_interpreter.h"
#include "user_dart.h"

CANInterface can1(&CAND1);
CANInterface can2(&CAND2);

class remoteThread:public BaseStaticThread<512>{
private:
void main() final;
CANMotorFeedback feedback;
}remote_thread;

void remoteThread::main(){
setName("RemoteControl");
static float angle;
feedback = CANMotorIF::motor_feedback[CANMotorCFG::MOTOR_ONE];
angle = feedback.accumulate_angle();
while(!shouldTerminate()){
chSysLock();
if(Remote::rc.s1 == Remote::S_UP){
CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = false;
CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = false;
CANMotorController::set_target_current(CANMotorCFG::MOTOR_ONE,0);
}else if(Remote::rc.s1 == Remote::S_MIDDLE){
CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = true;
CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = false;
CANMotorController::set_target_vel(CANMotorCFG::MOTOR_ONE, 200*Remote::rc.ch0);
}else if(Remote::rc.s1 == Remote::S_DOWN){
CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = true;
CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = true;
CANMotorController::set_target_angle(CANMotorCFG::MOTOR_ONE,angle);
}

chSysUnlock();
feedback = CANMotorIF::motor_feedback[CANMotorCFG::MOTOR_ONE];
LOG("initial angle: %f, current angle: %f\r\n",angle,feedback.accumulate_angle());
chThdSleepMilliseconds(100);
}
}
//class remoteThread:public BaseStaticThread<512>{
//private:
// void main() final;
// CANMotorFeedback feedback;
//}remote_thread;
//
//void remoteThread::main(){
// setName("RemoteControl");
// static float angle;
// feedback = CANMotorIF::motor_feedback[CANMotorCFG::MOTOR_ONE];
// angle = feedback.accumulate_angle();
// while(!shouldTerminate()){
// chSysLock();
// if(Remote::rc.s1 == Remote::S_UP){
// CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = false;
// CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = false;
// CANMotorController::set_target_current(CANMotorCFG::MOTOR_ONE,0);
// }else if(Remote::rc.s1 == Remote::S_MIDDLE){
// CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = true;
// CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = false;
// CANMotorController::set_target_vel(CANMotorCFG::MOTOR_ONE, 200*Remote::rc.ch0);
// }else if(Remote::rc.s1 == Remote::S_DOWN){
// CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = true;
// CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = true;
// CANMotorController::set_target_angle(CANMotorCFG::MOTOR_ONE,angle);
// }
//
// chSysUnlock();
// feedback = CANMotorIF::motor_feedback[CANMotorCFG::MOTOR_ONE];
// LOG("initial angle: %f, current angle: %f\r\n",angle,feedback.accumulate_angle());
// chThdSleepMilliseconds(100);
// }
//}

class printThread: public BaseStaticThread<512>{
private:
Expand All @@ -67,7 +68,8 @@ int main(){
Remote::start();
can1.start(NORMALPRIO+3);
can2.start(NORMALPRIO+4);
remote_thread.start(NORMALPRIO-1);
UserDart::start(NORMALPRIO-1);
// remote_thread.start(NORMALPRIO-1);
CANMotorController::start(HIGHPRIO-1,HIGHPRIO-2,&can1,&can2);
// print_thread.start(HIGHPRIO);
chThdSleepSeconds(5);
Expand Down
36 changes: 36 additions & 0 deletions dev/application/vehicles/dart/user_dart.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Created by Wu Feiyang on 2023/7/11.
//
#include "user_dart.h"
UserDart::UserThread UserDart::userThread;
void UserDart::start(tprio_t user_thd_prio) {
userThread.start(user_thd_prio);
}

void UserDart::UserThread::main(){
setName("RemoteControl");
static float angle;
feedback = CANMotorIF::motor_feedback[CANMotorCFG::MOTOR_ONE];
angle = feedback.accumulate_angle();
while(!shouldTerminate()){
chSysLock();
if(Remote::rc.s1 == Remote::S_UP){
CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = false;
CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = false;
CANMotorController::set_target_current(CANMotorCFG::MOTOR_ONE,0);
}else if(Remote::rc.s1 == Remote::S_MIDDLE){
CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = true;
CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = false;
CANMotorController::set_target_vel(CANMotorCFG::MOTOR_ONE, 200*Remote::rc.ch0);
}else if(Remote::rc.s1 == Remote::S_DOWN){
CANMotorCFG::enable_v2i[CANMotorCFG::MOTOR_ONE] = true;
CANMotorCFG::enable_a2v[CANMotorCFG::MOTOR_ONE] = true;
CANMotorController::set_target_angle(CANMotorCFG::MOTOR_ONE,angle);
}

chSysUnlock();
feedback = CANMotorIF::motor_feedback[CANMotorCFG::MOTOR_ONE];
LOG("initial angle: %f, current angle: %f\r\n",angle,feedback.accumulate_angle());
chThdSleepMilliseconds(100);
}
}
27 changes: 27 additions & 0 deletions dev/application/vehicles/dart/user_dart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by Wu Feiyang on 2023/7/11.
//
#ifndef META_EMBEDDED_USER_DART_H
#define META_EMBEDDED_USER_DART_H
#include "ch.hpp"
#include "can_interface.h"
#include "can_motor_interface.h"
#include "can_motor_feedback.h"
#include "can_motor_controller.h"
#include "remote_interpreter.h"


class UserDart{
public:
static void start(tprio_t user_thd_prio);
private:
class UserThread:public BaseStaticThread<512>{
private:
void main() final;
CANMotorFeedback feedback;
};
static UserThread userThread;
};


#endif //META_EMBEDDED_USER_DART_H

0 comments on commit 9cbdcb7

Please sign in to comment.