JM9 XRCU Board 0.1.4
Libraries API Reference
Loading...
Searching...
No Matches
Jason.h
Go to the documentation of this file.
1
22
23#ifndef JASON_H
24#define JASON_H
25
26#include <Arduino.h>
27
28#include <Ain.h>
29#include <Buttons.h>
30#include <CompoI.h>
31#include <EEPROM.h>
32#include <Monitor.h>
33#include <Motors.h>
34#include <Mpu_6050_dmp.h>
35#include <Qmc5883l.h>
36#include <Saved_data.h>
37#include <Uts_gpio.h>
38#include <Uts_i2c.h>
39#include <Uts_uart.h>
40#include <Vl53l0x.h>
41#include <Serial_packer.h>
42#include <Serial_unpacker.h>
43
50 union {
51 Vl53l0x *lidar_ptr;
52 Uts_i2c *uts_i2c_ptr;
53 Uts_uart *uts_uart_ptr;
54 Uts_gpio *uts_gpio_ptr;
55 };
56 uint8_t uts_mode;
57};
58
65 union {
66 Qmc5883l *qmc_ptr;
67 Mpu_6050_dmp *mpu_ptr;
68 };
69 uint8_t heading_use_mpu;
70};
71
78 HardwareSerial *uart_ptr;
79 uint32_t uart_baud;
80};
81
82// JM9 UART packet:
83// start-byte
84// length-byte (sum of amount of cmd/reg-byte and data-bytes)
85// (cmd/reg-byte)
86// data-bytes (variable length)
87// xor-byte (xor of start-byte and length-byte and cmd/reg-byte and data-bytes)
88//
89// reject entire packet if xor-byte is not matched
90
99class JM9_packer : public Serial_packer {
100 public:
107 JM9_packer (HardwareSerial &init_uart, const uint8_t init_start_byte);
108};
109
117 public:
124 JM9_unpacker (HardwareSerial &init_uart, const uint8_t init_start_byte);
125};
126
132class Jason : public Print {
133 private:
134 //
135 protected:
136 //
137 static const uint8_t EEPROM_IMG_OFFSET;
138 //
139 uint8_t eeprom_img [32];
140 // motor pointers
141 Mtr *mtrs [4];
142 // compoi pointers
143 CompoI *compois [2];
144 // whether the compound eyes are daisy chained
145 // If this is the case,
146 // then we get data from
147 // only the forward compound eye
148 // to get 360 degree data.
149 bool are_compois_daisy_chained;
150 // uts pointers
151 uts_aio_ptr_t utss [4];
152 // heading pointer
153 heading_ptr_t heading;
154 // cam pointer
155 uart_conn_ptr_t cam;
156 // kicker pin
157 uint32_t kicker_pin;
158 // dribbler pin
159 uint32_t dribbler_pin;
160 // comm pointer
161 uart_conn_ptr_t comm;
162 // display printing coordinates
163 uint16_t xc, yc;
164
165 public:
166 // basic functions
175 // library setup functions
176 //
177 void load_saved_info ();
178 //
179 void store_saved_info ();
180 //
181 void set_motor_port (const uint8_t mtr_idx, const uint8_t port);
182 //
183 uint8_t get_motor_port (const uint8_t mtr_idx);
184 //
185 void set_compoi_port (const uint8_t idx, const uint8_t port);
186 //
187 uint8_t get_compoi_port (const uint8_t idx);
188 //
189 void set_compoi_addr (const uint8_t idx, const uint8_t addr);
190 //
191 uint8_t get_compoi_addr (const uint8_t idx);
192 //
193 void set_uts_mode (const uint8_t side, const uint8_t mode);
194 //
195 uint8_t get_uts_mode (const uint8_t side);
196 //
197 void set_uts_port (const uint8_t side, const uint8_t port);
198 //
199 uint8_t get_uts_port (const uint8_t side);
200 //
201 void set_heading_port (const uint8_t port);
202 //
203 uint8_t get_heading_port ();
204 //
205 void set_heading_addr (const uint8_t addr);
206 //
207 uint8_t get_heading_addr ();
208 //
209 void set_cam_port (const uint8_t port);
210 //
211 uint8_t get_cam_port ();
212 //
213 void set_cam_baud (const uint32_t baud);
214 //
215 uint32_t get_cam_baud ();
216 //
217 void set_kicker_pin (const uint32_t pin);
218 //
219 uint32_t get_kicker_pin ();
220 //
221 void set_dribbler_pin (const uint32_t pin);
222 //
223 uint32_t get_dribbler_pin ();
224 //
225 void set_comm_port (const uint8_t port);
226 //
227 uint8_t get_comm_port ();
228 //
229 void set_comm_baud (const uint32_t baud);
230 //
231 uint32_t get_comm_baud ();
232
233 // advanced functions
234
238 void begin ();
239
243 void end ();
244
245 // motors
246
254 void set_motor_spd (const uint8_t mtr_idx, int16_t spd);
255
266 void polar_ctrl (int16_t angle, int16_t spd, int16_t rotation);
267
278 void rect_ctrl (int16_t spd_x, int16_t spd_y, int16_t rotation);
279
300 bool move_to (const uint8_t side1, const int16_t dist1, const uint8_t side2, const int16_t dist2, const int16_t target_heading = 0, const double rotation_kp = 1.2, const int16_t spd = 100, const int16_t threshold = 1);
301
302 // grayscales
303
309 virtual void gs ();
310
311 // compound-eye
312
321 int16_t get_ir_max_val ();
322
331 int16_t get_ir_avg_val ();
332
352 int8_t get_ir_max_idx ();
353
363
364 // ultrasonics
365
373 int16_t get_uts_dist (const uint8_t side);
374
381 void disable_uts (const uint8_t side);
382
389 void enable_uts (const uint8_t side);
390
391 // heading
392
398 int16_t get_heading ();
399
406
414 int16_t get_rotation_spd (const int16_t target_heading = 0);
415
416 // camera
417
424 virtual int16_t get_orange_ball_dist ();
425
432 virtual int16_t get_orange_ball_angle ();
433
440 virtual int16_t get_opponent_goal_dist ();
441
448 virtual int16_t get_opponent_goal_angle ();
449
456 virtual int16_t get_my_goal_dist ();
457
464 virtual int16_t get_my_goal_angle ();
465
466 // kicker
467
474 virtual void set_kicker_state (const bool state);
475
482 virtual bool get_kicker_state ();
483
484 // dribbler
485
492 virtual void set_dribbler_spd (const int16_t spd);
493
494 // monitor
495
499 void clear_mon ();
500
507 void set_cursor (int16_t x, int16_t y);
508 //
509 size_t print(const __FlashStringHelper *);
510 size_t print(const String &);
511 size_t print(const char[]);
512 size_t print(char);
513 size_t print(unsigned char, int = DEC);
514 size_t print(int, int = DEC);
515 size_t print(unsigned int, int = DEC);
516 size_t print(long, int = DEC);
517 size_t print(unsigned long, int = DEC);
518 size_t print(double, int = 2);
519 size_t print(const Printable&);
520 //
521 size_t write(uint8_t);
522
523 // communication : TO-DO
524};
525
529extern Jason robot;
530
540 LF = 0,
541
545 RF = 1,
546
550 RB = 2,
551
555 LB = 3
556};
557
563enum side_t {
567 front = 0,
568
572 left = 1,
573
577 right = 2,
578
583};
584
585#endif // #ifndef JASON_H
Jason robot
The robot object.
side_t
4 sides.
Definition Jason.h:563
@ back
Back side.
Definition Jason.h:582
@ left
Left side.
Definition Jason.h:572
@ front
Front side.
Definition Jason.h:567
@ right
Right side.
Definition Jason.h:577
mtr_idx_t
Motor indices.
Definition Jason.h:536
@ RB
Right-Back motor.
Definition Jason.h:550
@ LF
Left-Front motor.
Definition Jason.h:540
@ RF
Right-Front motor.
Definition Jason.h:545
@ LB
Left-Back motor.
Definition Jason.h:555
Compound Eye Driver for XRCU.
Definition CompoI.h:21
Definition HardwareSerial.h:99
JM9_packer(HardwareSerial &init_uart, const uint8_t init_start_byte)
Creates a packer.
JM9_unpacker(HardwareSerial &init_uart, const uint8_t init_start_byte)
Creates an unpacker.
Jason Driver for XRCU.
Definition Jason.h:132
int16_t get_ir_max_val()
Gets the maximum value read by all IR channels.
void set_motor_spd(const uint8_t mtr_idx, int16_t spd)
Sets the speed of a motor.
virtual int16_t get_opponent_goal_angle()
Gets the angle to the opponent's goal (in degrees).
void end()
Deactivates the robot and releases all occupied resources.
virtual int16_t get_orange_ball_angle()
Gets the angle to the orange ball (in degrees).
int16_t get_heading()
Gets the heading of the robot.
int16_t get_ir_avg_val()
Gets the average value read by all IR channels.
int16_t get_rotation_spd(const int16_t target_heading=0)
Gets the rotation speed of the robot.
virtual void gs()
Do something about the grayscales.
void enable_uts(const uint8_t side)
Enables an ultrasonic sensor of one side.
virtual int16_t get_my_goal_dist()
Gets the distance to my goal.
virtual int16_t get_my_goal_angle()
Gets the angle to my goal (in degrees).
virtual void set_dribbler_spd(const int16_t spd)
Sets the spinning speed of the dribbler.
bool move_to(const uint8_t side1, const int16_t dist1, const uint8_t side2, const int16_t dist2, const int16_t target_heading=0, const double rotation_kp=1.2, const int16_t spd=100, const int16_t threshold=1)
Moves the robot to a specific position.
void clear_mon()
Clears everything on the monitor.
~Jason()
Destroys a robot object.
void begin()
Activates the robot and configure the peripherals.
void reset_heading()
Resets the heading of the robot.
virtual int16_t get_orange_ball_dist()
Gets the distance to the orange ball.
int8_t get_ir_max_idx()
Gets the channel number of the maximum valued IR channel.
virtual bool get_kicker_state()
Gets whether the kicker is "kicked" (extended) or retracted.
int16_t get_ir_ball_angle()
Gets the IR ball angle (in degrees).
void rect_ctrl(int16_t spd_x, int16_t spd_y, int16_t rotation)
Sets the rectangular (cartesian) speed of the robot.
virtual void set_kicker_state(const bool state)
Sets whether the kicker is "kicked" (extended) or retracted.
Jason()
Creates a robot object.
void set_cursor(int16_t x, int16_t y)
Sets the cursor to print text on the monitor.
int16_t get_uts_dist(const uint8_t side)
Gets the ultrasonic sensor distance of one side.
void polar_ctrl(int16_t angle, int16_t spd, int16_t rotation)
Sets the polar speed of the robot.
void disable_uts(const uint8_t side)
Disables an ultrasonic sensor of one side.
virtual int16_t get_opponent_goal_dist()
Gets the distance to the opponent's goal.
MPU-6050 Accel and Gyro with DMP Driver for XRCU.
Definition Mpu_6050_dmp.h:75
Motor Driver for XRCU.
Definition Motors.h:20
Definition Printable.h:33
QMC5883L Compass Driver for XRCU.
Definition Qmc5883l.h:21
Serial_packer(HardwareSerial &init_uart, const uint8_t init_start_byte)
Creates a packer.
Serial_unpacker(HardwareSerial &init_uart, const uint8_t init_start_byte)
Creates an unpacker.
Ultrasonic Sensor Driver (TRIG-ECHO Polling) for XRCU.
Definition Uts_gpio.h:31
Ultrasonic Sensor Driver (I2C) for XRCU.
Definition Uts_i2c.h:24
Ultrasonic Sensor Driver (UART) for XRCU.
Definition Uts_uart.h:26
VL53L0X LiDAR Driver for XRCU.
Definition Vl53l0x.h:30
Heading pointer type.
Definition Jason.h:64
UART connection pointer type.
Definition Jason.h:77
Ultrasonics all-in-one pointer type.
Definition Jason.h:49