etrobocon2018 feat.KatLab  770af34cce41ae9c30c41303275e1add2daae0c3 (with uncommitted changes)
 全て クラス 名前空間 ファイル 関数 変数 列挙型 列挙値 フレンド マクロ定義 ページ
Lifter.cpp
[詳解]
1 #include "Lifter.h"
2 
3 void Lifter::terminate()
4 {
5  // msg_f("Stopped.", 1);
6  controller.liftMotor.stop();
7 }
8 
9 void Lifter::reset()
10 {
11  controller.liftMotor.reset();
12  controller.liftMotor.setBrake(true);
13  default_count = controller.liftMotor.getCount();
14 }
15 
17 {
18  std::int32_t current_angle = controller.liftMotor.getCount();
19  return current_angle - default_count;
20 }
21 
22 std::int8_t Lifter::limitPwm(std::int8_t pwm)
23 {
24  if(pwm > 100) {
25  return 100;
26  } else if(pwm < 1) {
27  return pwm = 1;
28  } else {
29  return pwm;
30  }
31 }
32 
33 void Lifter::liftUp(std::uint8_t angle, std::int8_t pwm)
34 {
35  while(1) {
36  if(getCurrentAngle() > angle) {
37  break;
38  }
39  controller.liftMotor.setPWM(limitPwm(pwm));
40  controller.tslpTsk(4);
41  }
42  controller.liftMotor.setPWM(0);
43 }
44 
45 void Lifter::liftDown(std::uint8_t angle, std::int8_t pwm)
46 {
47  while(1) {
48  if(getCurrentAngle() < -angle) {
49  break;
50  }
51  controller.liftMotor.setPWM(-limitPwm(pwm));
52  controller.tslpTsk(4);
53  }
54  controller.liftMotor.setPWM(0);
55 }
56 
57 void Lifter::defaultSet(std::int8_t pwm)
58 {
59  std::int8_t sign;
60  if(getCurrentAngle() < 0) {
61  sign = 1;
62  } else {
63  sign = -1;
64  }
65 
66  while(1) {
67  if((sign == 1 && getCurrentAngle() >= 0) || (sign == -1 && getCurrentAngle() <= 0)) {
68  break;
69  }
70  controller.liftMotor.setPWM(sign * limitPwm(pwm));
71  controller.tslpTsk(4);
72  }
73  controller.liftMotor.setPWM(0);
74 }
void setPWM(int pwm)
Definition: Motor.cpp:31
void tslpTsk(int16_t time)
Definition: Controller.cpp:74
Motor liftMotor
Definition: Controller.h:44
void setBrake(bool brake)
Definition: Motor.cpp:47
void reset(void)
Definition: Motor.h:55
void defaultSet(std::int8_t pwm=20)
Definition: Lifter.cpp:57
void liftDown(std::uint8_t angle, std::int8_t pwm=20)
Definition: Lifter.cpp:45
std::int8_t getCurrentAngle()
Definition: Lifter.cpp:16
void stop()
Definition: Motor.h:97
走行体のアームを操作するクラス。
void liftUp(std::uint8_t angle, std::int8_t pwm=20)
Definition: Lifter.cpp:33
int32_t getCount(void) const
Definition: Motor.h:67