Skip to content

Commit b3bde5c

Browse files
committed
added experimental behaviour, illuminator&lift
1 parent d06a2ad commit b3bde5c

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

examples/firmware_01/firmware_01.ino

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ uint8_t msg_size;
3131
uint8_t ack_required=0;
3232
bool ack_check=false;
3333
uint8_t ack_code=0;
34+
uint8_t behaviours;
3435

3536
unsigned long tmotor=0;
3637
unsigned long tsend=0;
3738
unsigned long tsensor=0;
3839
unsigned long timu=0;
3940
unsigned long tack=0;
41+
unsigned long tbehaviours=0;
4042

4143

4244
float left, right, value;
@@ -77,6 +79,7 @@ void setup(){
7779
tsensor=millis();
7880
timu=millis();
7981
tack=millis();
82+
tbehaviours=millis();
8083
}
8184

8285
void loop(){
@@ -181,6 +184,17 @@ void loop(){
181184
ack_check = false;
182185
}
183186
break;
187+
188+
case 'B':
189+
packeter.unpacketC1B(code, behaviours);
190+
switch (behaviours){
191+
case 1:
192+
alvik.setBehaviour(LIFT_ILLUMINATOR, true);
193+
break;
194+
default:
195+
alvik.setBehaviour(ALL_BEHAVIOURS, false);
196+
}
197+
break;
184198
}
185199
}
186200

@@ -256,6 +270,11 @@ void loop(){
256270
alvik.serial->write(packeter.msg, msg_size);
257271
}
258272

273+
if (millis()-tbehaviours > 100){
274+
tbehaviours = millis();
275+
alvik.updateBehaviours();
276+
}
277+
259278
// imu update
260279
if (millis()-timu>10){
261280
timu=millis();

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Arduino Alvik Carrier
2-
version=0.2.0
2+
version=0.2.1
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ int Arduino_AlvikCarrier::begin(){
133133
if (beginImu()!=0){
134134
errorLed(ERROR_IMU);
135135
}
136+
137+
beginBehaviours();
136138

137139

138140
return 0;
@@ -171,6 +173,7 @@ void Arduino_AlvikCarrier::updateAPDS(){
171173
}
172174

173175
void Arduino_AlvikCarrier::setIlluminator(uint8_t value){
176+
illuminator_state=value;
174177
digitalWrite(APDS_LED, value);
175178
}
176179

@@ -811,3 +814,49 @@ bool Arduino_AlvikCarrier::isTargetReached(){
811814
uint8_t Arduino_AlvikCarrier::getKinematicsMovement(){
812815
return kinematics_movement;
813816
}
817+
818+
819+
820+
/******************************************************************************************************/
821+
/* Behaviours */
822+
/******************************************************************************************************/
823+
void Arduino_AlvikCarrier::beginBehaviours(){
824+
prev_illuminator_state = illuminator_state;
825+
behaviours = 0;
826+
first_lift = true;
827+
}
828+
829+
830+
void Arduino_AlvikCarrier::updateBehaviours(){
831+
if (behaviours|=1 == 1){
832+
if (isLifted()&&first_lift){
833+
first_lift = false;
834+
prev_illuminator_state = illuminator_state;
835+
disableIlluminator();
836+
}
837+
if (!isLifted()&&!first_lift){
838+
if (prev_illuminator_state!=0){
839+
first_lift = true;
840+
enableIlluminator();
841+
}
842+
}
843+
}
844+
}
845+
846+
void Arduino_AlvikCarrier::setBehaviour(const uint8_t behaviour, const bool enable){
847+
if (enable){
848+
behaviours |= behaviour;
849+
}
850+
else{
851+
behaviours &= ~behaviour;
852+
}
853+
}
854+
855+
bool Arduino_AlvikCarrier::isLifted(){
856+
if (getProximity()>LIFT_THRESHOLD){
857+
return true;
858+
}
859+
else{
860+
return false;
861+
}
862+
}

src/Arduino_AlvikCarrier.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Arduino_AlvikCarrier{
3737

3838
APDS9960 * apds9960;
3939
int bottom_red, bottom_green, bottom_blue, bottom_clear, bottom_proximity;
40+
bool illuminator_state;
4041

4142

4243
Servo * servo_A;
@@ -79,6 +80,12 @@ class Arduino_AlvikCarrier{
7980
PidController * move_pid;
8081

8182

83+
bool prev_illuminator_state;
84+
uint8_t behaviours;
85+
bool first_lift;
86+
87+
88+
8289

8390
public:
8491
Kinematics * kinematics;
@@ -238,7 +245,10 @@ class Arduino_AlvikCarrier{
238245
bool isTargetReached(); // get true if a movement is accomplished
239246
uint8_t getKinematicsMovement(); // get which kind of motion is running in kinematic control
240247

241-
248+
void beginBehaviours();
249+
void updateBehaviours();
250+
void setBehaviour(const uint8_t behaviour, const bool enable);
251+
bool isLifted();
242252
};
243253

244254
#endif

src/definitions/robot_definitions.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ const float MOTOR_RATIO = MOTOR_CPR*MOTOR_GEAR_RATIO;
6060
#define MOVEMENT_MOVE 2
6161

6262

63+
#define LIFT_THRESHOLD 80
64+
65+
#define ALL_BEHAVIOURS 255
66+
#define LIFT_ILLUMINATOR 1
67+
68+
69+
70+
6371

6472

6573
// Sensor fusioning parameters
@@ -80,7 +88,7 @@ const float MOTION_FX_PERIOD = (1000U / MOTION_FX_FREQ);
8088
// Library version
8189
#define VERSION_BYTE_HIGH 0
8290
#define VERSION_BYTE_MID 2
83-
#define VERSION_BYTE_LOW 0
91+
#define VERSION_BYTE_LOW 1
8492

8593

8694

0 commit comments

Comments
 (0)