Skip to content

Commit 905768e

Browse files
authored
Merge pull request #22 from arduino-libraries/gbr1-exp
added tilt and shake
2 parents 03d4e3e + fa2a4dd commit 905768e

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

examples/firmware/firmware.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ void loop(){
227227
alvik.updateTouch();
228228
msg_size = packeter.packetC1B('t', alvik.getTouchKeys());
229229
alvik.serial->write(packeter.msg,msg_size);
230+
msg_size = packeter.packetC1B('m', alvik.getMotion());
231+
alvik.serial->write(packeter.msg,msg_size);
230232
break;
231233
case 2:
232234
alvik.updateAPDS();

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Arduino_AlvikCarrier
2-
version=1.0.1
2+
version=1.0.2
33
author=Arduino, Giovanni di Dio Bruno, Lucio Rossi
44
maintainer=Arduino <[email protected]>
55
sentence=Library and firmware for Arduino Alvik Carrier board

src/Arduino_AlvikCarrier.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ Arduino_AlvikCarrier::Arduino_AlvikCarrier(){
6767
ipKnobs = &iKnobs;
6868
imu_delta_time = MOTION_FX_ENGINE_DELTATIME;
6969
sample_to_discard = 0;
70+
is_shaking = 0;
71+
first_wakeup = true;
72+
shake_time = 0;
73+
shake_counter = 0;
74+
tilt_status = 0x80;
75+
xl = 0;
76+
xh = 0;
77+
yl = 0;
78+
yh = 0;
79+
zl = 0;
80+
zh = 0;
81+
tilt_time = 0;
82+
tmp_tilt_status = 0;
83+
tilt_filter = 0;
7084

7185
// version
7286
version_high = VERSION_BYTE_HIGH;
@@ -619,6 +633,11 @@ int Arduino_AlvikCarrier::beginImu(){
619633
imu->Set_G_FS(2000);
620634
imu->Enable_X();
621635
imu->Enable_G();
636+
imu->Enable_Wake_Up_Detection(LSM6DSO_INT1_PIN);
637+
imu->Set_Wake_Up_Threshold(1);
638+
imu->Set_Wake_Up_Duration(3);
639+
imu->Enable_6D_Orientation(LSM6DSO_INT1_PIN);
640+
622641

623642
delay(10);
624643

@@ -664,6 +683,60 @@ void Arduino_AlvikCarrier::updateImu(){
664683
sample_to_discard++;
665684
}
666685

686+
imu->Get_X_Event_Status(&imu_status);
687+
688+
if (imu_status.WakeUpStatus &&
689+
(motor_control_left->getRPM()<1 && motor_control_left->getRPM()>-1) &&
690+
(motor_control_right->getRPM()<1 && motor_control_right->getRPM()>-1)){
691+
if (first_wakeup){
692+
shake_time = millis();
693+
first_wakeup = false;
694+
shake_counter = 0;
695+
}
696+
shake_counter++;
697+
}
698+
699+
if (millis()-shake_time>500){
700+
if (shake_counter>10){
701+
is_shaking = true;
702+
shake_counter = 0;
703+
shake_time_sig = millis();
704+
}
705+
}
706+
if (is_shaking && (millis()-shake_time_sig>1000)){
707+
is_shaking = false;
708+
tilt_time = millis();
709+
}
710+
711+
if ((!is_shaking) && (millis()-tilt_time>1000)){
712+
imu->Get_6D_Orientation_XL(&xl);
713+
imu->Get_6D_Orientation_XH(&xh);
714+
imu->Get_6D_Orientation_YL(&yl);
715+
imu->Get_6D_Orientation_YH(&yh);
716+
imu->Get_6D_Orientation_ZL(&zl);
717+
imu->Get_6D_Orientation_ZH(&zh);
718+
719+
tmp_tilt_status = 0;
720+
tmp_tilt_status |= xl<<4;
721+
tmp_tilt_status |= xh<<5;
722+
tmp_tilt_status |= zl<<7;
723+
tmp_tilt_status |= zh<<6;
724+
tmp_tilt_status |= yh<<3;
725+
tmp_tilt_status |= yl<<2;
726+
727+
if (tilt_status != tmp_tilt_status){
728+
tilt_filter++;
729+
}else{
730+
tilt_filter = 0;
731+
}
732+
733+
if (tilt_filter>20){
734+
tilt_status = tmp_tilt_status;
735+
tilt_filter = 0;
736+
}
737+
738+
}
739+
667740
}
668741

669742
float Arduino_AlvikCarrier::getAccelerationX(){
@@ -702,6 +775,14 @@ float Arduino_AlvikCarrier::getYaw(){
702775
return 360.0-filter_data.rotation[0];
703776
}
704777

778+
bool Arduino_AlvikCarrier::isShaking(){
779+
return is_shaking;
780+
}
781+
782+
uint8_t Arduino_AlvikCarrier::getMotion(){
783+
return tilt_status | isShaking();
784+
}
785+
705786

706787

707788
/******************************************************************************************************/

src/Arduino_AlvikCarrier.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class Arduino_AlvikCarrier{
5656
LSM6DSOSensor * imu;
5757
int32_t accelerometer[3];
5858
int32_t gyroscope[3];
59+
LSM6DSO_Event_Status_t imu_status;
60+
5961

6062
float imu_delta_time;
6163
MFX_knobs_t iKnobs;
@@ -64,6 +66,15 @@ class Arduino_AlvikCarrier{
6466
MFX_input_t imu_data;
6567
MFX_output_t filter_data;
6668
uint16_t sample_to_discard;
69+
bool is_shaking;
70+
bool first_wakeup;
71+
unsigned long shake_time, shake_time_sig;
72+
uint16_t shake_counter;
73+
uint8_t tilt_status;
74+
uint8_t xl, xh, yl, yh, zl, zh;
75+
unsigned long tilt_time;
76+
uint8_t tilt_filter;
77+
uint8_t tmp_tilt_status;
6778

6879
uint8_t version_high;
6980
uint8_t version_mid;
@@ -220,6 +231,8 @@ class Arduino_AlvikCarrier{
220231
float getRoll(); // get robot roll
221232
float getPitch(); // get robot pitch
222233
float getYaw(); // get robot yaw
234+
bool isShaking(); // get true if robot is shaking
235+
uint8_t getMotion(); // get tilt + shaking
223236

224237
void errorLed(const int error_code); // error routine, locks on code blinking led
225238

src/definitions/robot_definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const float MOTION_FX_PERIOD = (1000U / MOTION_FX_FREQ);
8888
// Library version
8989
#define VERSION_BYTE_HIGH 1
9090
#define VERSION_BYTE_MID 0
91-
#define VERSION_BYTE_LOW 1
91+
#define VERSION_BYTE_LOW 2
9292

9393

9494

0 commit comments

Comments
 (0)