JM9 XRCU Board 0.1.0
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
48 union {
49 Vl53l0x *lidar_ptr;
50 Uts_i2c *uts_i2c_ptr;
51 Uts_uart *uts_uart_ptr;
52 Uts_gpio *uts_gpio_ptr;
53 };
54 uint8_t uts_mode;
55};
56
63 union {
64 Qmc5883l *qmc_ptr;
65 Mpu_6050_dmp *mpu_ptr;
66 };
67 uint8_t heading_use_mpu;
68};
69
76 HardwareSerial *uart_ptr;
77 uint32_t uart_baud;
78};
79
80// JM9 UART packet:
81// start-byte
82// length-byte (sum of amount of cmd/reg-byte and data-bytes)
83// (cmd/reg-byte)
84// data-bytes (variable length)
85// xor-byte (xor of start-byte and length-byte and cmd/reg-byte and data-bytes)
86//
87// reject entire packet if xor-byte is not matched
88
97 private:
101 const uint8_t start_byte;
102
103 public:
108
115 JM9_packer (HardwareSerial &init_uart, const uint8_t init_start_byte);
116
124 bool send (const uint8_t * const tx_buf, const uint8_t tx_buf_len);
125};
126
133 private:
137 const uint8_t start_byte;
138
142 enum state_t {
147 idle,
148
153 start_byte_received,
154
159 len_byte_received,
160
165 data_bytes_rx_done
166 };
167
171 state_t status;
172
176 uint8_t *buf_arr;
177
181 uint8_t buf_arr_idx;
182
186 uint8_t buf_arr_len;
187
191 uint8_t my_xor_byte;
192
193 public:
204 JM9_unpacker (HardwareSerial &init_uart, const uint8_t init_start_byte);
205
210 ~JM9_unpacker ();
211
216 bool update ();
217
227 uint8_t *get_packet_ptr ();
228
237 uint8_t get_packet_len ();
238};
239
245class Jason : public Print {
246 private:
247 //
248 protected:
249 //
250 #define EEPROM_IMG_OFFSET 0x50
251 //
252 uint8_t eeprom_img [32];
253 // motor pointers
254 Mtr *mtrs [4];
255 // compoi pointers
256 CompoI *compois [2];
257 // uts pointers
258 uts_aio_ptr_t utss [4];
259 // heading pointer
260 heading_ptr_t heading;
261 // cam pointer
262 uart_conn_ptr_t cam;
263 // kicker pin
264 uint32_t kicker_pin;
265 // dribbler pin
266 uint32_t dribbler_pin;
267 // comm pointer
268 uart_conn_ptr_t comm;
269 // display printing coordinates
270 uint16_t xc, yc;
271
272 public:
273 // basic functions
277 Jason ();
281 ~Jason ();
282 // library setup functions
283 //
284 void load_saved_info ();
285 //
286 void store_saved_info ();
287 //
288 void set_motor_port (const uint8_t mtr_idx, const uint8_t port);
289 //
290 uint8_t get_motor_port (const uint8_t mtr_idx);
291 //
292 void set_compoi_port (const uint8_t idx, const uint8_t port);
293 //
294 uint8_t get_compoi_port (const uint8_t idx);
295 //
296 void set_compoi_addr (const uint8_t idx, const uint8_t addr);
297 //
298 uint8_t get_compoi_addr (const uint8_t idx);
299 //
300 void set_uts_mode (const uint8_t side, const uint8_t mode);
301 //
302 uint8_t get_uts_mode (const uint8_t side);
303 //
304 void set_uts_port (const uint8_t side, const uint8_t port);
305 //
306 uint8_t get_uts_port (const uint8_t side);
307 //
308 void set_heading_port (const uint8_t port);
309 //
310 uint8_t get_heading_port ();
311 //
312 void set_heading_addr (const uint8_t addr);
313 //
314 uint8_t get_heading_addr ();
315 //
316 void set_cam_port (const uint8_t port);
317 //
318 uint8_t get_cam_port ();
319 //
320 void set_cam_baud (const uint32_t baud);
321 //
322 uint32_t get_cam_baud ();
323 //
324 void set_kicker_pin (const uint32_t pin);
325 //
326 uint32_t get_kicker_pin ();
327 //
328 void set_dribbler_pin (const uint32_t pin);
329 //
330 uint32_t get_dribbler_pin ();
331 //
332 void set_comm_port (const uint8_t port);
333 //
334 uint8_t get_comm_port ();
335 //
336 void set_comm_baud (const uint32_t baud);
337 //
338 uint32_t get_comm_baud ();
339
340 // advanced functions
341
345 void begin ();
346
350 void end ();
351
352 // motors
353
361 void set_motor_spd (const uint8_t mtr_idx, int16_t spd);
362
373 void polar_ctrl (int16_t angle, int16_t spd, int16_t rotation);
374
385 void rect_ctrl (int16_t spd_x, int16_t spd_y, int16_t rotation);
386
407 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);
408
409 // grayscales
410
416 virtual void gs ();
417
418 // compound-eye
419
428 int16_t get_ir_max_val ();
429
438 int16_t get_ir_avg_val ();
439
459 int8_t get_ir_max_idx ();
460
469 int16_t get_ir_ball_angle ();
470
471 // ultrasonics
472
480 int16_t get_uts_dist (const uint8_t side);
481
488 void disable_uts (const uint8_t side);
489
496 void enable_uts (const uint8_t side);
497
498 // heading
499
505 int16_t get_heading ();
506
512 void reset_heading ();
513
521 int16_t get_rotation_spd (const int16_t target_heading = 0);
522
523 // camera
524
531 virtual int16_t get_orange_ball_dist ();
532
539 virtual int16_t get_orange_ball_angle ();
540
547 virtual int16_t get_opponent_goal_dist ();
548
555 virtual int16_t get_opponent_goal_angle ();
556
563 virtual int16_t get_my_goal_dist ();
564
571 virtual int16_t get_my_goal_angle ();
572
573 // kicker
574
581 virtual void set_kicker_state (const bool state);
582
589 virtual bool get_kicker_state ();
590
591 // dribbler
592
599 virtual void set_dribbler_spd (const int16_t spd);
600
601 // monitor
602
606 void clear_mon ();
607
614 void set_cursor (int16_t x, int16_t y);
615 //
616 size_t print(const __FlashStringHelper *);
617 size_t print(const String &);
618 size_t print(const char[]);
619 size_t print(char);
620 size_t print(unsigned char, int = DEC);
621 size_t print(int, int = DEC);
622 size_t print(unsigned int, int = DEC);
623 size_t print(long, int = DEC);
624 size_t print(unsigned long, int = DEC);
625 size_t print(double, int = 2);
626 size_t print(const Printable&);
627 //
628 size_t write(uint8_t);
629
630 // communication : TO-DO
631};
632
636extern Jason robot;
637
647 LF = 0,
648
652 RF = 1,
653
657 RB = 2,
658
662 LB = 3
663};
664
670enum side_t {
674 front = 0,
675
679 left = 1,
680
684 right = 2,
685
690};
691
692#endif // #ifndef JASON_H
side_t
4 sides.
Definition Jason.h:670
@ back
Back side.
Definition Jason.h:689
@ left
Left side.
Definition Jason.h:679
@ front
Front side.
Definition Jason.h:674
@ right
Right side.
Definition Jason.h:684
mtr_idx_t
Motor indices.
Definition Jason.h:643
@ RB
Right-Back motor.
Definition Jason.h:657
@ LF
Left-Front motor.
Definition Jason.h:647
@ RF
Right-Front motor.
Definition Jason.h:652
@ LB
Left-Back motor.
Definition Jason.h:662
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.
Definition Jason.cpp:45
bool send(const uint8_t *const tx_buf, const uint8_t tx_buf_len)
Creates and sends a packet.
Definition Jason.cpp:52
HardwareSerial & uart
The underlying UART object.
Definition Jason.h:107
HardwareSerial & uart
The underlying UART object.
Definition Jason.h:197
uint8_t get_packet_len()
Gets the length of the received data.
Definition Jason.cpp:157
bool update()
Checks if a new packet is received.
Definition Jason.cpp:89
JM9_unpacker(HardwareSerial &init_uart, const uint8_t init_start_byte)
Creates an unpacker.
Definition Jason.cpp:65
~JM9_unpacker()
Destroys this unpacker.
Definition Jason.cpp:77
uint8_t * get_packet_ptr()
Gets the pointer to the received data.
Definition Jason.cpp:153
Jason Driver for XRCU.
Definition Jason.h:245
int16_t get_ir_max_val()
Gets the maximum value read by all IR channels.
Definition Jason.cpp:683
void set_motor_spd(const uint8_t mtr_idx, int16_t spd)
Sets the speed of a motor.
Definition Jason.cpp:592
virtual void set_kicker_state(const bool state)
Sets whether the kicker is "kicked" (extended) or retracted.
Definition Jason.cpp:882
void end()
Deactivates the robot and releases all occupied resources.
Definition Jason.cpp:588
int16_t get_heading()
Gets the heading of the robot.
Definition Jason.cpp:825
int16_t get_ir_avg_val()
Gets the average value read by all IR channels.
Definition Jason.cpp:689
int16_t get_rotation_spd(const int16_t target_heading=0)
Gets the rotation speed of the robot.
Definition Jason.cpp:847
virtual bool get_kicker_state()
Gets whether the kicker is "kicked" (extended) or retracted.
Definition Jason.cpp:886
void enable_uts(const uint8_t side)
Enables an ultrasonic sensor of one side.
Definition Jason.cpp:799
virtual void set_dribbler_spd(const int16_t spd)
Sets the spinning speed of the dribbler.
Definition Jason.cpp:890
virtual int16_t get_opponent_goal_dist()
Gets the distance to the opponent's goal.
Definition Jason.cpp:866
virtual int16_t get_my_goal_dist()
Gets the distance to my goal.
Definition Jason.cpp:874
virtual int16_t get_my_goal_angle()
Gets the angle to my goal (in degrees).
Definition Jason.cpp:878
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.
Definition Jason.cpp:626
void clear_mon()
Clears everything on the monitor.
Definition Jason.cpp:894
~Jason()
Destroys a robot object.
Definition Jason.cpp:208
void begin()
Activates the robot and configure the peripherals.
Definition Jason.cpp:461
virtual void gs()
Do something about the grayscales.
Definition Jason.cpp:679
void reset_heading()
Resets the heading of the robot.
Definition Jason.cpp:837
virtual int16_t get_opponent_goal_angle()
Gets the angle to the opponent's goal (in degrees).
Definition Jason.cpp:870
int8_t get_ir_max_idx()
Gets the channel number of the maximum valued IR channel.
Definition Jason.cpp:705
virtual int16_t get_orange_ball_angle()
Gets the angle to the orange ball (in degrees).
Definition Jason.cpp:862
int16_t get_ir_ball_angle()
Gets the IR ball angle (in degrees).
Definition Jason.cpp:725
void rect_ctrl(int16_t spd_x, int16_t spd_y, int16_t rotation)
Sets the rectangular (cartesian) speed of the robot.
Definition Jason.cpp:617
virtual int16_t get_orange_ball_dist()
Gets the distance to the orange ball.
Definition Jason.cpp:858
Jason()
Creates a robot object.
Definition Jason.cpp:161
void set_cursor(int16_t x, int16_t y)
Sets the cursor to print text on the monitor.
Definition Jason.cpp:898
int16_t get_uts_dist(const uint8_t side)
Gets the ultrasonic sensor distance of one side.
Definition Jason.cpp:743
void polar_ctrl(int16_t angle, int16_t spd, int16_t rotation)
Sets the polar speed of the robot.
Definition Jason.cpp:603
void disable_uts(const uint8_t side)
Disables an ultrasonic sensor of one side.
Definition Jason.cpp:773
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
Ultrasonic Sensor Driver (TRIG-ECHO Polling) for XRCU.
Definition Uts_gpio.h:26
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:62
UART connection pointer type.
Definition Jason.h:75
Ultrasonics all-in-one pointer type.
Definition Jason.h:47