I need to evolve my Event trigger mechanism.
Lets assume we want to control a robot with 2 electric motors – one left and one right. We are currently running forward with 1000 RPM and want to reverse with 10RPM.
Assign leftMotor.direction = reverse Assign rightMotor.direction = reverse Assign leftMotor.speed = 10 Assign rightMotor.speed=10
The issue is that as we make the first assign we also raise the event. This will cause the left motor to reverse at 1000RPM. The result is behaviour we did not intend during the update, so we need a mechanism that allow us to Control the event.
Object Motor uint32 direction uint32 speed End Event C OnCommand(Motor lm, Motor rm) const Forward = 0 const Reverse = 1 Motor leftMotor,rightMotor leftMotor.direction = forward rightMotor.direction = forward leftMotor.speed = 1000 rightMotor.speed=1000 Raise OnCommand(leftMotor, rightMotor) ... leftMotor.direction = reverse rightMotor.direction = reverse leftMotor.speed = 10 rightMotor.speed=10 Raise OnCommand(leftMotor, rightMotor
“Event C” does in this example declare a C code event named “OnCommand” with 2 x Motor Objects as parameters. Rather than having event’s triggered automatically we raise them controlled. I have tried different syntax to do the same automatically, but I believe controlling this manually actually is a must.
The syntax is a draft – the usage of raise is in this example inconsistent With earlier examples, so I will need to work on that. I also notice that I forgot Assign on the assign statements – this was accidental, but I decided to leave it because I am considering dropping the need for Assign, Call and Raise in the Assembly syntax.