-
Notifications
You must be signed in to change notification settings - Fork 1
/
vex_triport.h
1252 lines (1118 loc) · 44.2 KB
/
vex_triport.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) Robomatter 2017, All rights reserved. */
/* */
/* Module: vex_triport.h */
/* Author: James Pearman */
/* Created: 10 Jan 2018 */
/* */
/* Revisions: */
/* V1.00 TBD - Initial release */
/* */
/*----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
/** @file vex_triport.h
* @brief Triport device class header
*//*---------------------------------------------------------------------------*/
#ifndef VCS_TRIPORT_CLASS_H
#define VCS_TRIPORT_CLASS_H
/*-----------------------------------------------------------------------------*/
/** @brief Triport device class */
/*-----------------------------------------------------------------------------*/
namespace vex {
/**
* @prog_lang{none}
* @brief Use this class to get and set information about devices on 3-wire ports.
*/
class triport : public device {
public:
enum class tEventType {
EVENT_DIN_HIGH = 0,
EVENT_DIN_LOW = 1,
EVENT_AIN_CHANGED = 2
};
private:
uint32_t _id = 0;
void _setport() {};
void _configPort( uint32_t id, triportType type );
template <typename first, typename... Args>
void _setport( first port, Args... args ) {
_configPort( _id++, port );
_setport( args... );
}
int32_t _getIndex();
// conversion from vcs enum to C API
V5_AdiPortConfiguration _internalType( triportType type );
triportType _externalType( V5_AdiPortConfiguration type );
public:
triport( int32_t index );
~triport();
template <typename... Args>
triport( int32_t index, Args... args) : triport(index) {
_setport( args... );
}
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Gets the status of what is installed on the port.
* @return Returns true if a 3-Wire Port device is installed in the port, otherwise false.
*/
bool installed();
/**
* @prog_lang{none}
* @brief Use this class to get access to port functions and members.
*/
class port {
friend class __tridevice;
private:
int32_t _id;
triportType _type;
triport *_parent;
int32_t _convertAnalog( analogUnits units );
public:
port() : _id( -1 ), _type(triportType::digitalInput), _parent(NULL) {};
port( const int32_t id, triport *parent );
port( const int32_t id, const triportType type, triport *parent );
~port() {};
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Sets the port to a specific port type.
* @param type A type of port that you want to set it to.
*/
void type( const triportType type );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Gets the current port type.
* @return Returns the Port Type.
*/
triportType type();
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Sets the port's value to the specified integer in the parameter.
* @param value An integer number that will be set to the port's value.
*/
void value( int32_t value );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Gets the value of a port.
* @return Returns an integer that represents the port's value.
*/
int32_t value();
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Sets the value of the port to a Boolean value.
* @param value A true or false Boolean value that the port will be set to.
*/
void set( bool value );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Calls back a function when the port is pressed.
* @param callback A reference to a function.
*/
void pressed( void (* callback)(void) );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Calls back a function when the port is released.
* @param callback A reference to a function.
*/
void released( void (* callback)(void) );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Calls back a function when the port has changed value.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
void operator()( const triportType type ) {
this->type( type );
}
void operator=( const int32_t value ) {
this->value( value );
}
operator int() {
return this->value();
}
operator bool() {
return (this->value() > 0) ? true : false;
}
// encoder specific
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Resets the rotation of the encoder to zero.
*/
void resetRotation( void );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Sets the rotation of the encoder to a specific value.
* @param val A double that represents the value to set the rotation to.
* @param units The unit type that the previous value should be treated as.
*/
void setRotation( double val, rotationUnits units );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Gets the rotation value of the encoder.
* @return Returns a double that represents the current rotation of the encoder.
* @param units A unit type that defines what value of rotation that should be returned.
*/
double rotation( rotationUnits units );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Gets the velocity of the encoder.
* @return Returns a double that represents the current velocity of the encoder.
* @param units A unit type that defines what value of velocity that should be returned.
*/
double velocity( velocityUnits units );
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Gets the value of the distance sensor.
* @return Returns a double that represents the current distance of the sensor.
* @param units A distance unit type that defines what value of distance that should be returned.
*/
double distance( distanceUnits units );
mevent PRESSED = { (uint32_t)_parent->_getIndex(), ((uint32_t)tEventType::EVENT_DIN_HIGH + (_id<<2)) };
mevent RELEASED = { (uint32_t)_parent->_getIndex(), ((uint32_t)tEventType::EVENT_DIN_LOW + (_id<<2)) };
mevent CHANGED = { (uint32_t)_parent->_getIndex(), ((uint32_t)tEventType::EVENT_AIN_CHANGED + (_id<<2)) };
mevent &HIGH = PRESSED;
mevent &LOW = RELEASED;
};
// A triport device has 8 ports
// This creates those instances and associates them with this triport
port Port[8] = { {0, this},
{1, this},
{2, this},
{3, this},
{4, this},
{5, this},
{6, this},
{7, this}
};
// These are the public named references to those ports
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[0].
*/
port &A = Port[0];
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[1].
*/
port &B = Port[1];
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[2].
*/
port &C = Port[2];
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[3].
*/
port &D = Port[3];
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[4].
*/
port &E = Port[4];
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[5].
*/
port &F = Port[5];
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[6].
*/
port &G = Port[6];
/**
* @prog_lang{none}
* @drawer_cat{none}
* @brief Port type that represents Port[7].
*/
port &H = Port[7];
};
/**
* @prog_lang{none}
* @brief Use this class to get access to Three Wire Port functions and members.
*/
class __tridevice {
friend class limit;
friend class bumper;
friend class digital_in;
friend class digital_out;
friend class pot;
friend class line;
friend class light;
friend class gyro;
friend class accelerometer;
friend class analog_in;
friend class encoder;
friend class sonar;
friend class pwm_out;
friend class servo;
friend class motor29;
friend class motor_victor;
private:
triport::port &_port;
int32_t _convertAnalog( analogUnits units );
mevent &_PRESSED = _port.PRESSED;
mevent &_RELEASED = _port.RELEASED;
mevent &_CHANGED = _port.CHANGED;
mevent &_HIGH = _port.HIGH;
mevent &_LOW = _port.LOW;
public:
__tridevice( triport::port &port, triportType type );
~__tridevice();
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with the limit switch
*/
class limit : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::limit Limit = vex::limit(Brain.ThreeWirePort.A);}
* @brief Creates a new limit object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
limit( triport::port &port );
~limit();
/**
* @prog_lang{none}
* @drawer_cat{none}
* @block_sig{Limit.value()}
* @brief Gets the value of the limit switch
* @return Returns an integer that represents the value of the limit device.
*/
int32_t value();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Limit.pressing()}
* @brief Gets the state of the limit device.
* @return Returns the state of the limit device.
*/
int32_t pressing() { return value(); };
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Limit.pressed(pressedFunction);}
* @brief Calls a function when the limit switch is pressed.
* @param callback A reference to a function.
*/
void pressed( void (* callback)(void) );
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Limit.released(releasedFunction);}
* @brief Calls a function when the limit switch is released.
* @param callback A reference to a function.
*/
void released( void (* callback)(void) );
operator int();
operator bool();
mevent &PRESSED = _PRESSED;
mevent &RELEASED = _RELEASED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with the bumper device
*/
class bumper : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::bumper Bumper = vex::bumper(Brain.ThreeWirePort.A);}
* @brief Creates a new bumper object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
bumper( triport::port &port );
~bumper();
/**
* @prog_lang{none}
* @drawer_cat{none}
* @block_sig{Bumper.value()}
* @brief Gets the value of the bumper device.
* @return Returns an integer that represents the value of the bumper device.
*/
int32_t value();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Bumper.pressing()}
* @brief Get the pressed status of the bumper device.
* @return Returns the state of the bumper device. If it is pressed it will return a one. If unpressed, it will return a zero.
*/
int32_t pressing() { return value(); };
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Bumper.pressed(pressedFunction);}
* @brief Calls a function when the bumper switch is pressed.
* @param callback A reference to a function.
*/
void pressed( void (* callback)(void) );
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Bumper.released(releasedFunction);}
* @brief Calls a function when the bumper switch is released.
* @param callback A reference to a function.
*/
void released( void (* callback)(void) );
operator int();
operator bool();
mevent &PRESSED = _PRESSED;
mevent &RELEASED = _RELEASED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with a digital-in device
*/
class digital_in : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::digital_in Digital_in = vex::digital_in(Brain.ThreeWirePort.A);}
* @brief Creates a new digital-in object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
digital_in( triport::port &port );
~digital_in();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{DigitalIn.value()}
* @brief Gets the value of the digital-in device.
* @return Returns an integer that represents the value of the digital-in device.
*/
int32_t value();
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{DigitalIn.high(pressedFunction);}
* @brief Calls a function when the digital input goes high.
* @param callback A reference to a function.
*/
void high( void (* callback)(void) );
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{DigitalIn.low(releasedFunction);}
* @brief Calls a function when the digital input goes low.
* @param callback A reference to a function.
*/
void low( void (* callback)(void) );
operator int();
operator bool();
// digital in needs inversion
// ADI inverts digital inputs so switch press is seen as high
mevent &HIGH = _LOW;
mevent &LOW = _HIGH;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with a digital-out device.
*/
class digital_out : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::digital_out Digital_out = vex::digital_out(Brain.ThreeWirePort.A);}
* @brief Creates a new digital-out object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
digital_out( triport::port &port );
~digital_out();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{DigitalOut.value()}
* @brief Gets the value of the digital-out device.
* @return Returns an integer that represents the value of the digital-out device.
*/
int32_t value();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{action}
* @block_sig{DigitalOut.set(true);}
* @brief Sets the digital-out device to a Boolean value.
* @param value A true or false Boolean value.
*/
void set( bool value );
operator int();
operator bool();
/**
* @prog_lang{none}
* @drawer_cat{none}
* @block_sig{DigitalOut.operator(1);}
* @brief Sets the output value of the digital-out device.
* @param value The value to set the digital-out device. Typically 1 or 0.
*/
void operator=( const int32_t value );
};
// Analog sensors
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with a potentiometer.
*/
class pot : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::pot Pot = vex::pot(Brain.ThreeWirePort.A);}
* @brief Creates a new pot object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
pot( triport::port &port );
~pot();
/**
* @prog_lang{cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Pot.value(vex::analogUnits::range8bit)}
* @brief Gets the value of the potentiometer in the units defined in the parameter.
* @return Returns an integer that represents the unit value specified by the parameter of the potentiometer device.
* @param units The measurement unit for the potentiometer device.
*/
int32_t value( analogUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Pot.value(percent)}
* @cpp_sig{Pot.value(vex::percentUnit::pct)}
* @brief Gets the value of the potentiometer in the units defined in the parameter.
* @return Returns an integer that represents the unit value specified by the parameter of the potentiometer device.
* @param units The measurement unit for the potentiometer device.
*/
int32_t value( percentUnits units ) {
return value( analogUnits::pct );
};
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Pot.value(degrees)}
* @cpp_sig{Pot.value(vex::rotationUnits::deg)}
* @brief Gets the value of the potentiometer in the units defined in the parameter.
* @return Returns an integer that represents the unit value specified by the parameter of the potentiometer device.
* @param units The measurement unit for the potentiometer device.
*/
double value( rotationUnits units );
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Pot.changed(changedFunction);}
* @brief Calls a function when the potentiometer value changes.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
mevent &CHANGED = _CHANGED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with a line follower.
*/
class line : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::line Line = vex::line(Brain.ThreeWirePort.A);}
* @brief Creates a new line object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
line( triport::port &port );
~line();
/**
* @prog_lang{cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Line.value(vex::analogUnits::range8bit)}
* @brief Gets the value of the line follower.
* @return Returns an integer that represents the unit value specified by the parameter of the line follower.
* @param units The measurement unit for the line device.
*/
int32_t value( analogUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Line.value(percent)}
* @cpp_sig{Line.value(vex::percentUnits::pct)}
* @brief Gets the value of the line follower.
* @return Returns an integer that represents the unit value specified by the parameter of the line follower.
* @param units The measurement unit for the line device.
*/
int32_t value( percentUnits units ) {
return value( analogUnits::pct );
};
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Line.changed(changedFunction);}
* @brief Calls a function when the line sensor value changes.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
mevent &CHANGED = _CHANGED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with a light sensor.
*/
class light : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::light Light = vex::light(Brain.ThreeWirePort.A);}
* @brief Creates a new light object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
light( triport::port &port );
~light();
/**
* @prog_lang{cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Light.value(vex::analogUnits::range8bit)}
* @brief Gets the value of the light sensor.
* @return Returns an integer that represents the unit value specified by the parameter of the light sensor.
* @param units The measurement unit for the light device.
*/
int32_t value( analogUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Light.value(percent)}
* @cpp_sig{Light.value(vex::percentUnits::pct)}
* @brief Gets the value of the light sensor.
* @return Returns an integer that represents the unit value specified by the parameter of the light sensor.
* @param units The measurement unit for the light device.
*/
int32_t value( percentUnits units ) {
return value( analogUnits::pct );
};
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Light.changed(changedFunction);}
* @brief Calls a function when the light sensor value changes.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
mevent &CHANGED = _CHANGED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with a gyro sensor.
*/
class gyro : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::gyro Gyro = vex::gyro(Brain.ThreeWirePort.A);}
* @brief Creates a new gyro object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
gyro( triport::port &port );
~gyro();
/**
* @prog_lang{cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Gyro.value(vex::analogUnits::range8bit)}
* @brief Gets the value of the gyro sensor.
* @return Returns an integer that represents the unit value specified by the parameter of the gyro sensor.
* @param units The measurement unit for the gyro device.
*/
int32_t value( analogUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Gyro.value(degrees)}
* @cpp_sig{Gyro.value(vex::rotationUnits::deg)}
* @brief Gets the value of the gyro sensor.
* @return Returns an integer that represents the unit value specified by the parameter of the gyro sensor.
* @param units The measurement unit for the gyro device.
*/
double value( rotationUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Gyro.value(percent)}
* @cpp_sig{Gyro.value(vex::percentUnits::pct)}
* @brief Gets the value of the gyro sensor.
* @return Returns an integer that represents the unit value specified by the parameter of the gyro sensor.
* @param units The measurement unit for the gyro device.
*/
int32_t value( percentUnits units ) {
return value( analogUnits::pct );
};
/**
* @prog_lang{pro}
* @drawer_cat{action}
* @block_sig{Gyro.startCalibration()}
* @brief Starts recalibration of the gyro.
* @param value (Optional) Sets the amount of calibration time.
*/
void startCalibration( int32_t value = 0 );
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Gyro.isCalibrating()}
* @brief Returns true while the gyro sensor is performing a requested recalibration, changing to false once recalibration has completed.
* @return Returns true if gyro is still calibrating.
*/
bool isCalibrating();
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Gyro.changed(changedFunction);}
* @brief Calls a function when the gyro sensor value changes.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
mevent &CHANGED = _CHANGED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with an accelerometer sensor.
*/
class accelerometer : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::accelerometer Accelerometer = vex::accelerometer(Brain.ThreeWirePort.A);}
* @brief Creates a new accelerometer object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
accelerometer( triport::port &port );
~accelerometer();
/**
* @prog_lang{cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Accelerometer.value(vex::analogUnits::range8bit)}
* @brief Gets the value of the accelerometer.
* @return Returns an integer that represents the unit value specified by the parameter of the accelerometer sensor.
* @param units The measurement unit for the accelerometer device.
*/
int32_t value( analogUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Accelerometer.value(percent)}
* @cpp_sig{Accelerometer.value(vex::percentUnits::pct)}
* @brief Gets the value of the accelerometer.
* @return Returns an integer that represents the unit value specified by the parameter of the accelerometer sensor.
* @param units The measurement unit for the accelerometer device.
*/
int32_t value( percentUnits units ) {
return value( analogUnits::pct );
};
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Accelerometer.changed(changedFunction);}
* @brief Calls a function when the accelerometer value changes.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
mevent &CHANGED = _CHANGED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with an analog-in device.
*/
class analog_in : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::analog_in Analog_in = vex::analog_in(Brain.ThreeWirePort.A);}
* @brief Creates a new analog-in object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
analog_in( triport::port &port );
~analog_in();
/**
* @prog_lang{cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Analog.value(vex::analogUnits::range8bit)}
* @brief Gets the value of the analog-in device.
* @return Returns an integer that represents the unit value specified by the parameter of the analog-in device.
* @param units The measurement unit for the analog-in device.
*/
int32_t value( analogUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Analog.value(percent)}
* @cpp_sig{Analog.value(vex::percentUnits::pct)}
* @brief Gets the value of the analog-in device.
* @return Returns an integer that represents the unit value specified by the parameter of the analog-in device.
* @param units The measurement unit for the analog-in device.
*/
int32_t value( percentUnits units ) {
return value( analogUnits::pct );
};
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Analog.changed(changedFunction);}
* @brief Calls a function when the analog input value changes.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
mevent &CHANGED = _CHANGED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with an encoder.
*/
class encoder : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::encoder Encoder = vex::encoder(Brain.ThreeWirePort.A);}
* @brief Creates a new encoder object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
encoder( triport::port &port );
~encoder();
/**
* @prog_lang{none}
* @drawer_cat{none}
* @block_sig{Encoder.value()}
* @brief Gets the value of the encoder.
* @return Returns an integer that represents the value of the encoder device.
*/
int32_t value();
operator int();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{setting}
* @block_sig{Encoder.resetRotation();}
* @brief Resets the rotation of the encoder to zero.
*/
void resetRotation( void );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{setting}
* @block_sig{Encoder.setRotation(90, degrees);}
* @cpp_sig{Encoder.setRotation(90, vex::rotationUnits::deg);}
* @brief Sets the rotation of the encoder to a specific value.
* @param val Sets the amount of rotation.
* @param units The measurement unit for the rotation value.
*/
void setRotation( double val, rotationUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Encoder.rotation(degrees)}
* @cpp_sig{Encoder.rotation(vex::rotationUnits::deg)}
* @brief Gets the rotation value of the encoder.
* @return Returns a double that represents the current rotation of the encoder.
* @param units The measurement unit for the encoder device.
*/
double rotation( rotationUnits units );
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Encoder.velocity(percent)}
* @cpp_sig{Encoder.velocity(vex::velocityUnits::rpm)}
* @brief Gets the velocity of the encoder.
* @return Returns a double that represents the current velocity of the encoder.
* @param units The measurement unit for the encoder device.
*/
double velocity( velocityUnits units );
/**
* @prog_lang{pro}
* @drawer_cat{sensing}
* @block_sig{Encoder.changed(changedFunction);}
* @brief Calls a function when the encoder value changes.
* @param callback A reference to a function.
*/
void changed( void (* callback)(void) );
mevent &CHANGED = _CHANGED;
};
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class when programming with a sonar sensor.
*/
class sonar : private __tridevice {
public:
/**
* @prog_lang{cpp|pro}
* @drawer_cat{constructor}
* @block_sig{vex::sonar Sonar = vex::sonar(Brain.ThreeWirePort.A);}
* @brief Creates a new sonar object on the port specified in the parameter.
* @param port A reference to a three wire port.
*/
sonar( triport::port &port );
~sonar();
/**
* @prog_lang{none}
* @drawer_cat{none}
* @block_sig{Sonar.value();}
* @brief Gets the value of the distance sensor.
* @return Returns an integer that represents the value of the sonar sensor.
*/
int32_t value();
operator int();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Sonar.distance(millimeters)}
* @cpp_sig{Sonar.distance(vex::distanceUnits::mm)}
* @brief Gets the value of the distance sensor.
* @return Returns an integer that represents the unit value specified by the parameter of the sonar sensor.
* @param units The measurement unit for the sonar device.
*/
double distance( distanceUnits units );