JM9 XRCU Board 0.1.3a
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
116class JM9_unpacker : public Serial_unpacker {
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 // uts pointers
145 uts_aio_ptr_t utss [4];
146 // heading pointer
147 heading_ptr_t heading;
148 // cam pointer
149 uart_conn_ptr_t cam;
150 // kicker pin
151 uint32_t kicker_pin;
152 // dribbler pin
153 uint32_t dribbler_pin;
154 // comm pointer
155 uart_conn_ptr_t comm;
156 // display printing coordinates
157 uint16_t xc, yc;
158
159 public:
160 // basic functions
164 Jason ();
168 ~Jason ();
169 // library setup functions
170 //
171 void load_saved_info ();
172 //
173 void store_saved_info ();
174 //
175 void set_motor_port (const uint8_t mtr_idx, const uint8_t port);
176 //
177 uint8_t get_motor_port (const uint8_t mtr_idx);
178 //
179 void set_compoi_port (const uint8_t idx, const uint8_t port);
180 //
181 uint8_t get_compoi_port (const uint8_t idx);
182 //
183 void set_compoi_addr (const uint8_t idx, const uint8_t addr);
184 //
185 uint8_t get_compoi_addr (const uint8_t idx);
186 //
187 void set_uts_mode (const uint8_t side, const uint8_t mode);
188 //
189 uint8_t get_uts_mode (const uint8_t side);
190 //
191 void set_uts_port (const uint8_t side, const uint8_t port);
192 //
193 uint8_t get_uts_port (const uint8_t side);
194 //
195 void set_heading_port (const uint8_t port);
196 //
197 uint8_t get_heading_port ();
198 //
199 void set_heading_addr (const uint8_t addr);
200 //
201 uint8_t get_heading_addr ();
202 //
203 void set_cam_port (const uint8_t port);
204 //
205 uint8_t get_cam_port ();
206 //
207 void set_cam_baud (const uint32_t baud);
208 //
209 uint32_t get_cam_baud ();
210 //
211 void set_kicker_pin (const uint32_t pin);
212 //
213 uint32_t get_kicker_pin ();
214 //
215 void set_dribbler_pin (const uint32_t pin);
216 //
217 uint32_t get_dribbler_pin ();
218 //
219 void set_comm_port (const uint8_t port);
220 //
221 uint8_t get_comm_port ();
222 //
223 void set_comm_baud (const uint32_t baud);
224 //
225 uint32_t get_comm_baud ();
226
227 // advanced functions
228
232 void begin ();
233
237 void end ();
238
239 // motors
240
248 void set_motor_spd (const uint8_t mtr_idx, int16_t spd);
249
260 void polar_ctrl (int16_t angle, int16_t spd, int16_t rotation);
261
272 void rect_ctrl (int16_t spd_x, int16_t spd_y, int16_t rotation);
273
294 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);
295
296 // grayscales
297
303 virtual void gs ();
304
305 // compound-eye
306
315 int16_t get_ir_max_val ();
316
325 int16_t get_ir_avg_val ();
326
346 int8_t get_ir_max_idx ();
347
356 int16_t get_ir_ball_angle ();
357
358 // ultrasonics
359
367 int16_t get_uts_dist (const uint8_t side);
368
375 void disable_uts (const uint8_t side);
376
383 void enable_uts (const uint8_t side);
384
385 // heading
386
392 int16_t get_heading ();
393
399 void reset_heading ();
400
408 int16_t get_rotation_spd (const int16_t target_heading = 0);
409
410 // camera
411
418 virtual int16_t get_orange_ball_dist ();
419
426 virtual int16_t get_orange_ball_angle ();
427
434 virtual int16_t get_opponent_goal_dist ();
435
442 virtual int16_t get_opponent_goal_angle ();
443
450 virtual int16_t get_my_goal_dist ();
451
458 virtual int16_t get_my_goal_angle ();
459
460 // kicker
461
468 virtual void set_kicker_state (const bool state);
469
476 virtual bool get_kicker_state ();
477
478 // dribbler
479
486 virtual void set_dribbler_spd (const int16_t spd);
487
488 // monitor
489
493 void clear_mon ();
494
501 void set_cursor (int16_t x, int16_t y);
502 //
503 size_t print(const __FlashStringHelper *);
504 size_t print(const String &);
505 size_t print(const char[]);
506 size_t print(char);
507 size_t print(unsigned char, int = DEC);
508 size_t print(int, int = DEC);
509 size_t print(unsigned int, int = DEC);
510 size_t print(long, int = DEC);
511 size_t print(unsigned long, int = DEC);
512 size_t print(double, int = 2);
513 size_t print(const Printable&);
514 //
515 size_t write(uint8_t);
516
517 // communication : TO-DO
518};
519
523extern Jason robot;
524
534 LF = 0,
535
539 RF = 1,
540
544 RB = 2,
545
549 LB = 3
550};
551
557enum side_t {
561 front = 0,
562
566 left = 1,
567
571 right = 2,
572
577};
578
579#endif // #ifndef JASON_H
side_t
4 sides.
Definition Jason.h:557
@ back
Back side.
Definition Jason.h:576
@ left
Left side.
Definition Jason.h:566
@ front
Front side.
Definition Jason.h:561
@ right
Right side.
Definition Jason.h:571
mtr_idx_t
Motor indices.
Definition Jason.h:530
@ RB
Right-Back motor.
Definition Jason.h:544
@ LF
Left-Front motor.
Definition Jason.h:534
@ RF
Right-Front motor.
Definition Jason.h:539
@ LB
Left-Back motor.
Definition Jason.h:549
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
JM9_unpacker(HardwareSerial &init_uart, const uint8_t init_start_byte)
Creates an unpacker.
Definition Jason.cpp:51
Jason Driver for XRCU.
Definition Jason.h:132
int16_t get_ir_max_val()
Gets the maximum value read by all IR channels.
Definition Jason.cpp:581
void set_motor_spd(const uint8_t mtr_idx, int16_t spd)
Sets the speed of a motor.
Definition Jason.cpp:490
virtual void set_kicker_state(const bool state)
Sets whether the kicker is "kicked" (extended) or retracted.
Definition Jason.cpp:780
void end()
Deactivates the robot and releases all occupied resources.
Definition Jason.cpp:486
int16_t get_heading()
Gets the heading of the robot.
Definition Jason.cpp:723
int16_t get_ir_avg_val()
Gets the average value read by all IR channels.
Definition Jason.cpp:587
int16_t get_rotation_spd(const int16_t target_heading=0)
Gets the rotation speed of the robot.
Definition Jason.cpp:745
virtual bool get_kicker_state()
Gets whether the kicker is "kicked" (extended) or retracted.
Definition Jason.cpp:784
void enable_uts(const uint8_t side)
Enables an ultrasonic sensor of one side.
Definition Jason.cpp:697
virtual void set_dribbler_spd(const int16_t spd)
Sets the spinning speed of the dribbler.
Definition Jason.cpp:788
virtual int16_t get_opponent_goal_dist()
Gets the distance to the opponent's goal.
Definition Jason.cpp:764
virtual int16_t get_my_goal_dist()
Gets the distance to my goal.
Definition Jason.cpp:772
virtual int16_t get_my_goal_angle()
Gets the angle to my goal (in degrees).
Definition Jason.cpp:776
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:524
void clear_mon()
Clears everything on the monitor.
Definition Jason.cpp:792
~Jason()
Destroys a robot object.
Definition Jason.cpp:104
void begin()
Activates the robot and configure the peripherals.
Definition Jason.cpp:359
virtual void gs()
Do something about the grayscales.
Definition Jason.cpp:577
void reset_heading()
Resets the heading of the robot.
Definition Jason.cpp:735
virtual int16_t get_opponent_goal_angle()
Gets the angle to the opponent's goal (in degrees).
Definition Jason.cpp:768
int8_t get_ir_max_idx()
Gets the channel number of the maximum valued IR channel.
Definition Jason.cpp:603
virtual int16_t get_orange_ball_angle()
Gets the angle to the orange ball (in degrees).
Definition Jason.cpp:760
int16_t get_ir_ball_angle()
Gets the IR ball angle (in degrees).
Definition Jason.cpp:623
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:515
virtual int16_t get_orange_ball_dist()
Gets the distance to the orange ball.
Definition Jason.cpp:756
Jason()
Creates a robot object.
Definition Jason.cpp:57
void set_cursor(int16_t x, int16_t y)
Sets the cursor to print text on the monitor.
Definition Jason.cpp:796
int16_t get_uts_dist(const uint8_t side)
Gets the ultrasonic sensor distance of one side.
Definition Jason.cpp:641
void polar_ctrl(int16_t angle, int16_t spd, int16_t rotation)
Sets the polar speed of the robot.
Definition Jason.cpp:501
void disable_uts(const uint8_t side)
Disables an ultrasonic sensor of one side.
Definition Jason.cpp:671
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: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