Replies: 1 comment
-
The The Would you like to experiment with this in Python and see which additional messages are worth adding? In pseudo code, this is what we send currently. You could try this in Python to confirm that the basics are working and then send other messages. bool forward = (duty > 0) == (self->direction == PBIO_DIRECTION_CLOCKWISE);
// Make duty cycle positive and bounded
if (duty < 0) {
duty = -duty;
}
if (duty > 99) {
duty = 105;
}
// Scale 100% duty to 7 PWM steps
uint8_t pwm = duty / 15;
// For forward, PWM steps 1--7 are binary 1 to 7, backward is 15--9
int16_t message = (forward || pwm == 0) ? pwm : 16 - pwm;
// Choose blue or red output
message |= (self->use_blue_port) << 4;
// Choose single output Mode
message |= 1 << 6;
// Choose channel (1--4)
message |= (self->channel - 1) << 8;
// Send the data to the device. This automatically delays by about 250 ms
// to ensure the data is properly sent and received. This also ensures that
// the message will still work if two identical values are sent in a row.
return pb_type_device_set_data(self->device_base, LEGO_DEVICE_MODE_PUP_COLOR_DISTANCE_SENSOR__IR_TX, &message, sizeof(message));
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This request is related to the Power Functions support of the Boost Color & Distance Sensor, implemented in https://code.pybricks.com/static/docs/v2.20.0/pupdevices/pfmotor.html and the PF IR protocol: https://www.philohome.com/pf/LEGO_Power_Functions_RC_v120.pdf
Normally, PF has 4 channels which are supported by pybricks. But each mode in the PF protocol contains an additional address bit which is usually considered to be 0.
However, in "extended mode", there is a command to toggle the address bit (Function Toggle Address bit: 0110). With this command, the "internal" address of the receivers can be toggled/switched to 1 so that there are 4 more channels available: channels 1-4 (address bit not toggled) and channels 5-8 (address bit toggled).
I tested this with the sensor and PF IR receivers and it does work. Keep in mind that commands sent to "channels 5-8" need the address bit to be 1 in the command.
The address bit gets set to 0 after a restart of the receiver, also some receivers seem to ignore it (Mindstorms EV3 IR sensor) and older IR receivers are buggy and don't implement the address bit correctly.
I didn't find any hint that this functionality was implemented in pybricks but it would be cool to be able to double the amount of "PF channels" if one had a supported IR receiver.
Also, it would be good to add information on timeouts to the pybricks documentation.
Beta Was this translation helpful? Give feedback.
All reactions