![](/media/cache/profiles/altb_JGUSAOG.jpg.50x50_q85.jpg)
SPI read Pixi Cam V1
Pixy.cpp@4:478d4d9193a1, 2021-08-23 (annotated)
- Committer:
- altb2
- Date:
- Mon Aug 23 11:26:37 2021 +0000
- Revision:
- 4:478d4d9193a1
- Parent:
- 0:ef0e3c67dc5b
1st commit, reading pixi cam via SPI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
swilkins8 | 0:ef0e3c67dc5b | 1 | #include "Pixy.h" |
swilkins8 | 0:ef0e3c67dc5b | 2 | |
swilkins8 | 0:ef0e3c67dc5b | 3 | ServoLoop::ServoLoop(int32_t pgain, int32_t dgain) |
swilkins8 | 0:ef0e3c67dc5b | 4 | { |
swilkins8 | 0:ef0e3c67dc5b | 5 | m_pos = PIXY_RCS_CENTER_POS; |
swilkins8 | 0:ef0e3c67dc5b | 6 | m_pgain = pgain; |
swilkins8 | 0:ef0e3c67dc5b | 7 | m_dgain = dgain; |
swilkins8 | 0:ef0e3c67dc5b | 8 | m_prevError = 0x80000000L; |
swilkins8 | 0:ef0e3c67dc5b | 9 | } |
swilkins8 | 0:ef0e3c67dc5b | 10 | |
swilkins8 | 0:ef0e3c67dc5b | 11 | void ServoLoop::update(int32_t error) |
swilkins8 | 0:ef0e3c67dc5b | 12 | { |
swilkins8 | 0:ef0e3c67dc5b | 13 | long int vel; |
swilkins8 | 0:ef0e3c67dc5b | 14 | if (m_prevError != 0x80000000) { |
swilkins8 | 0:ef0e3c67dc5b | 15 | vel = (error*m_pgain + (error - m_prevError)*m_dgain) >> 10; |
swilkins8 | 0:ef0e3c67dc5b | 16 | m_pos += vel; |
swilkins8 | 0:ef0e3c67dc5b | 17 | if (m_pos > PIXY_RCS_MAX_POS) { |
swilkins8 | 0:ef0e3c67dc5b | 18 | m_pos = PIXY_RCS_MAX_POS; |
swilkins8 | 0:ef0e3c67dc5b | 19 | } else if (m_pos < PIXY_RCS_MIN_POS) { |
swilkins8 | 0:ef0e3c67dc5b | 20 | m_pos = PIXY_RCS_MIN_POS; |
swilkins8 | 0:ef0e3c67dc5b | 21 | } |
swilkins8 | 0:ef0e3c67dc5b | 22 | } |
swilkins8 | 0:ef0e3c67dc5b | 23 | m_prevError = error; |
swilkins8 | 0:ef0e3c67dc5b | 24 | } |
swilkins8 | 0:ef0e3c67dc5b | 25 |